rolldown-plugin-dts 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright © 2025 三咲智子 Kevin Deng (https://github.com/sxzz)
3
+ Copyright © 2025-PRESENT Kevin Deng (https://github.com/sxzz)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -216,7 +216,7 @@ Furthermore, the test suite is authorized by them and distributed under the MIT
216
216
 
217
217
  ## License
218
218
 
219
- [MIT](./LICENSE) License © 2025 [三咲智子 Kevin Deng](https://github.com/sxzz)
219
+ [MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)
220
220
 
221
221
  <!-- Badges -->
222
222
 
@@ -3,13 +3,10 @@ import Debug from "debug";
3
3
  //#region src/tsc/context.ts
4
4
  const debug = Debug("rolldown-plugin-dts:tsc-context");
5
5
  function createContext() {
6
- const programs = [];
7
- const files = /* @__PURE__ */ new Map();
8
- const projects = /* @__PURE__ */ new Map();
9
6
  return {
10
- programs,
11
- files,
12
- projects
7
+ programs: [],
8
+ files: /* @__PURE__ */ new Map(),
9
+ projects: /* @__PURE__ */ new Map()
13
10
  };
14
11
  }
15
12
  function invalidateContextFile(context, file) {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_to_dts, replaceTemplateName, resolveTemplateFn } from "./filename-Dd76wOJT.js";
2
- import { createContext, globalContext, invalidateContextFile } from "./context-b9aW37YD.js";
2
+ import { createContext, globalContext, invalidateContextFile } from "./context-Digr9tkU.js";
3
3
  import Debug from "debug";
4
4
  import _generate from "@babel/generator";
5
5
  import { parse } from "@babel/parser";
@@ -232,8 +232,7 @@ function isNode(value) {
232
232
  * @returns {Node | null}
233
233
  */
234
234
  function walk(ast, { enter, leave }) {
235
- const instance = new SyncWalker(enter, leave);
236
- return instance.visit(ast, null);
235
+ return new SyncWalker(enter, leave).visit(ast, null);
237
236
  }
238
237
 
239
238
  //#endregion
@@ -366,12 +365,11 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
366
365
  ...appendStmts
367
366
  ];
368
367
  typeOnlyMap.set(id, typeOnlyIds);
369
- const result = generate(file, {
368
+ return generate(file, {
370
369
  comments: false,
371
370
  sourceMaps: sourcemap,
372
371
  sourceFileName: id
373
372
  });
374
- return result;
375
373
  }
376
374
  function renderChunk(code, chunk) {
377
375
  if (!RE_DTS.test(chunk.fileName)) return;
@@ -429,12 +427,11 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
429
427
  program.body[0].leadingComments ||= [];
430
428
  program.body[0].leadingComments.unshift(...comments);
431
429
  }
432
- const result = generate(file, {
430
+ return generate(file, {
433
431
  comments: true,
434
432
  sourceMaps: sourcemap,
435
433
  sourceFileName: chunk.fileName
436
434
  });
437
- return result;
438
435
  }
439
436
  function getIdentifierIndex(name) {
440
437
  if (name in identifierMap) return identifierMap[name]++;
@@ -503,13 +500,12 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
503
500
  overwriteNode(node, t.tsTypeReference(local, node.typeParameters));
504
501
  replacement = local;
505
502
  } else overwriteNode(node, local);
506
- const dep = {
503
+ return {
507
504
  ...TSEntityNameToRuntime(local),
508
505
  replace(newNode) {
509
506
  overwriteNode(replacement, newNode);
510
507
  }
511
508
  };
512
- return dep;
513
509
  }
514
510
  }
515
511
  const REFERENCE_RE = /\/\s*<reference\s+(?:path|types)=/;
@@ -546,29 +542,19 @@ function patchImportExport(node, typeOnlyIds, cjsDefault) {
546
542
  node.source.value = filename_dts_to(node.source.value, "js");
547
543
  return node;
548
544
  }
549
- if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && resolveString(node.specifiers[0].exported) === "default") {
550
- const defaultExport = node.specifiers[0];
551
- return {
552
- type: "TSExportAssignment",
553
- expression: defaultExport.local
554
- };
555
- }
545
+ if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && resolveString(node.specifiers[0].exported) === "default") return {
546
+ type: "TSExportAssignment",
547
+ expression: node.specifiers[0].local
548
+ };
556
549
  }
557
550
  }
558
551
  function patchTsNamespace(nodes) {
559
552
  const emptyObjectAssignments = /* @__PURE__ */ new Map();
560
553
  const removed = /* @__PURE__ */ new Set();
561
554
  for (const [i, node] of nodes.entries()) {
562
- if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].id.type === "Identifier" && node.declarations[0].init?.type === "ObjectExpression" && node.declarations[0].init.properties.length === 0) emptyObjectAssignments.set(node.declarations[0].id.name, node);
563
- if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || !node.expression.callee.name.startsWith("__export")) continue;
564
- const [binding, exports] = node.expression.arguments;
565
- if (binding.type !== "Identifier") continue;
566
- const bindingText = binding.name;
567
- if (emptyObjectAssignments.has(bindingText)) {
568
- const emptyNode = emptyObjectAssignments.get(bindingText);
569
- emptyObjectAssignments.delete(bindingText);
570
- removed.add(emptyNode);
571
- }
555
+ const result = handleExport(node) || handleLegacyExport(node);
556
+ if (!result) continue;
557
+ const [binding, exports] = result;
572
558
  nodes[i] = {
573
559
  type: "TSModuleDeclaration",
574
560
  id: binding,
@@ -590,6 +576,31 @@ function patchTsNamespace(nodes) {
590
576
  };
591
577
  }
592
578
  return nodes.filter((node) => !removed.has(node));
579
+ function handleExport(node) {
580
+ if (node.type !== "VariableDeclaration" || node.declarations.length !== 1 || node.declarations[0].id.type !== "Identifier" || node.declarations[0].init?.type !== "CallExpression" || node.declarations[0].init.callee.type !== "Identifier" || node.declarations[0].init.callee.name !== "__export" || node.declarations[0].init.arguments.length !== 1 || node.declarations[0].init.arguments[0].type !== "ObjectExpression") return false;
581
+ const source = node.declarations[0].id;
582
+ const exports = node.declarations[0].init.arguments[0];
583
+ return [source, exports];
584
+ }
585
+ /**
586
+ * @deprecated remove me in future
587
+ */
588
+ function handleLegacyExport(node) {
589
+ if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].id.type === "Identifier" && node.declarations[0].init?.type === "ObjectExpression" && node.declarations[0].init.properties.length === 0) {
590
+ emptyObjectAssignments.set(node.declarations[0].id.name, node);
591
+ return false;
592
+ }
593
+ if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || !node.expression.callee.name.startsWith("__export")) return false;
594
+ const [binding, exports] = node.expression.arguments;
595
+ if (binding.type !== "Identifier" || exports.type !== "ObjectExpression") return false;
596
+ const bindingText = binding.name;
597
+ if (emptyObjectAssignments.has(bindingText)) {
598
+ const emptyNode = emptyObjectAssignments.get(bindingText);
599
+ emptyObjectAssignments.delete(bindingText);
600
+ removed.add(emptyNode);
601
+ }
602
+ return [binding, exports];
603
+ }
593
604
  }
594
605
  function rewriteImportExport(node, set, typeOnlyIds) {
595
606
  if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" && !node.declaration) {
@@ -734,10 +745,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
734
745
  exclude: [RE_DTS, RE_NODE_MODULES]
735
746
  } },
736
747
  handler(code, id) {
737
- const shouldEmit = !RE_JS.test(id) || emitJs;
738
- if (shouldEmit) {
739
- const mod = this.getModuleInfo(id);
740
- const isEntry = !!mod?.isEntry;
748
+ if (!RE_JS.test(id) || emitJs) {
749
+ const isEntry = !!this.getModuleInfo(id)?.isEntry;
741
750
  const dtsId = filename_to_dts(id);
742
751
  dtsMap.set(dtsId, {
743
752
  code,
@@ -954,10 +963,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
954
963
  if (RE_CSS.test(id)) return external;
955
964
  const rolldownResolution = await this.resolve(id, importer, options);
956
965
  const dtsResolution = resolveDtsPath(id, importer, rolldownResolution);
957
- if (!dtsResolution) {
958
- const isFileImport = id.startsWith(".") || path.isAbsolute(id);
959
- return isFileImport ? null : external;
960
- }
966
+ if (!dtsResolution) return id.startsWith(".") || path.isAbsolute(id) ? null : external;
961
967
  if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) return external;
962
968
  if (RE_DTS.test(dtsResolution)) return dtsResolution;
963
969
  if (isSourceFile(dtsResolution)) {
@@ -1,3 +1,3 @@
1
- import { createContext, globalContext, invalidateContextFile } from "./context-b9aW37YD.js";
1
+ import { createContext, globalContext, invalidateContextFile } from "./context-Digr9tkU.js";
2
2
 
3
3
  export { createContext, globalContext, invalidateContextFile };
@@ -1,4 +1,4 @@
1
- import { globalContext } from "./context-b9aW37YD.js";
1
+ import { globalContext } from "./context-Digr9tkU.js";
2
2
  import { createRequire } from "node:module";
3
3
  import Debug from "debug";
4
4
  import path from "node:path";
@@ -88,8 +88,7 @@ function tscEmitBuild(tscOptions) {
88
88
  const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
89
89
  const resolvedId = fsSystem.resolvePath(id);
90
90
  if (resolvedId !== id) debug$3(`resolved id from ${id} to ${resolvedId}`);
91
- const sourceFileToProjectMap = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap);
92
- const project = sourceFileToProjectMap.get(resolvedId);
91
+ const project = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap).get(resolvedId);
93
92
  if (!project) {
94
93
  debug$3(`unable to locate a project containing ${resolvedId}`);
95
94
  return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
@@ -152,11 +151,10 @@ function buildProjects(fsSystem, tsconfig, force, sourcemap) {
152
151
  const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
153
152
  debug$3("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
154
153
  const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
155
- const builder = ts.createSolutionBuilder(host, [tsconfig], {
154
+ const exitStatus = ts.createSolutionBuilder(host, [tsconfig], {
156
155
  force,
157
156
  verbose: true
158
- });
159
- const exitStatus = builder.build(void 0, void 0, void 0, (project) => {
157
+ }).build(void 0, void 0, void 0, (project) => {
160
158
  debug$3(`transforming project ${project}`);
161
159
  return customTransformers;
162
160
  });
@@ -265,8 +263,7 @@ function createVueProgramFactory(ts$1) {
265
263
  resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
266
264
  const vueOptions = resolver.build();
267
265
  vue.writeGlobalTypes(vueOptions, ts$2.sys.writeFile);
268
- const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
269
- return { languagePlugins: [vueLanguagePlugin] };
266
+ return { languagePlugins: [vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id)] };
270
267
  });
271
268
  }
272
269
 
@@ -328,8 +325,7 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
328
325
  };
329
326
  const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
330
327
  const host = ts.createCompilerHost(compilerOptions, true);
331
- const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
332
- const program = createProgram({
328
+ const program = (vue ? createVueProgramFactory(ts) : ts.createProgram)({
333
329
  rootNames,
334
330
  options: compilerOptions,
335
331
  host,
@@ -338,8 +334,7 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
338
334
  const sourceFile = program.getSourceFile(id);
339
335
  if (!sourceFile) {
340
336
  debug$1(`source file not found in program: ${id}`);
341
- const hasReferences = !!parsedConfig.projectReferences?.length;
342
- if (hasReferences) throw new Error(`[rolldown-plugin-dts] Unable to load ${id}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`);
337
+ if (!!parsedConfig.projectReferences?.length) throw new Error(`[rolldown-plugin-dts] Unable to load ${id}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`);
343
338
  if (!fsSystem.fileExists(id)) {
344
339
  debug$1(`File ${id} does not exist on disk.`);
345
340
  throw new Error(`Source file not found: ${id}`);
@@ -355,8 +350,7 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
355
350
  }
356
351
  function tscEmitCompiler(tscOptions) {
357
352
  debug$1(`running tscEmitCompiler ${tscOptions.id}`);
358
- const module = createOrGetTsModule(tscOptions);
359
- const { program, file } = module;
353
+ const { program, file } = createOrGetTsModule(tscOptions);
360
354
  debug$1(`got source file: ${file.fileName}`);
361
355
  let dtsCode;
362
356
  let map;
@@ -1,11 +1,10 @@
1
- import "./context-b9aW37YD.js";
2
- import { tscEmit } from "./tsc-BQbq3o79.js";
1
+ import "./context-Digr9tkU.js";
2
+ import { tscEmit } from "./tsc-q7n7-QbP.js";
3
3
  import process from "node:process";
4
4
  import { createBirpc } from "birpc";
5
5
 
6
6
  //#region src/tsc/worker.ts
7
- const functions = { tscEmit };
8
- createBirpc(functions, {
7
+ createBirpc({ tscEmit }, {
9
8
  post: (data) => process.send(data),
10
9
  on: (fn) => process.on("message", fn)
11
10
  });
package/dist/tsc.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./context-b9aW37YD.js";
2
- import { tscEmit } from "./tsc-BQbq3o79.js";
1
+ import "./context-Digr9tkU.js";
2
+ import { tscEmit } from "./tsc-q7n7-QbP.js";
3
3
 
4
4
  export { tscEmit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "A Rolldown plugin to generate and bundle dts files.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -20,7 +20,7 @@
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/sxzz/rolldown-plugin-dts.git"
22
22
  },
23
- "author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
23
+ "author": "Kevin Deng <sxzz@sxzz.moe>",
24
24
  "funding": "https://github.com/sponsors/sxzz",
25
25
  "files": [
26
26
  "dist"
@@ -73,7 +73,7 @@
73
73
  "@types/babel__generator": "^7.27.0",
74
74
  "@types/debug": "^4.1.12",
75
75
  "@types/node": "^24.3.1",
76
- "@typescript/native-preview": "7.0.0-dev.20250906.1",
76
+ "@typescript/native-preview": "7.0.0-dev.20250910.1",
77
77
  "@volar/typescript": "^2.4.23",
78
78
  "@vue/language-core": "^3.0.6",
79
79
  "bumpp": "^10.2.3",
@@ -81,10 +81,10 @@
81
81
  "eslint": "^9.35.0",
82
82
  "estree-walker": "^3.0.3",
83
83
  "prettier": "^3.6.2",
84
- "rolldown": "^1.0.0-beta.35",
84
+ "rolldown": "^1.0.0-beta.36",
85
85
  "rollup-plugin-dts": "^6.2.3",
86
- "tinyglobby": "^0.2.14",
87
- "tsdown": "^0.14.2",
86
+ "tinyglobby": "^0.2.15",
87
+ "tsdown": "^0.15.0",
88
88
  "typescript": "^5.9.2",
89
89
  "vitest": "^3.2.4",
90
90
  "vue": "^3.5.21",
@@ -102,6 +102,6 @@
102
102
  "test": "vitest",
103
103
  "typecheck": "tsc --noEmit",
104
104
  "format": "prettier --cache --write .",
105
- "release": "bumpp && unotp pnpm publish"
105
+ "release": "bumpp"
106
106
  }
107
107
  }