rolldown-plugin-dts 0.18.2 → 0.18.4

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/dist/index.mjs CHANGED
@@ -336,43 +336,61 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
336
336
  function collectDependencies(node, namespaceStmts) {
337
337
  const deps = /* @__PURE__ */ new Set();
338
338
  const seen = /* @__PURE__ */ new Set();
339
- walkAST(node, { leave(node$1) {
340
- if (node$1.type === "ExportNamedDeclaration") {
341
- for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
342
- } else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(TSEntityNameToRuntime(heritage.expression));
343
- else if (node$1.type === "ClassDeclaration") {
344
- if (node$1.superClass) addDependency(node$1.superClass);
345
- if (node$1.implements) for (const implement of node$1.implements) addDependency(TSEntityNameToRuntime(implement.expression));
346
- } else if (isTypeOf(node$1, [
347
- "ObjectMethod",
348
- "ObjectProperty",
349
- "ClassProperty",
350
- "TSPropertySignature",
351
- "TSDeclareMethod"
352
- ])) {
353
- if (node$1.computed && isReferenceId(node$1.key)) addDependency(node$1.key);
354
- if ("value" in node$1 && isReferenceId(node$1.value)) addDependency(node$1.value);
355
- } else switch (node$1.type) {
356
- case "TSTypeReference":
357
- addDependency(TSEntityNameToRuntime(node$1.typeName));
358
- break;
359
- case "TSTypeQuery":
360
- if (seen.has(node$1.exprName)) return;
361
- if (node$1.exprName.type === "TSImportType") break;
362
- addDependency(TSEntityNameToRuntime(node$1.exprName));
363
- break;
364
- case "TSImportType": {
365
- seen.add(node$1);
366
- const source = node$1.argument;
367
- const imported = node$1.qualifier;
368
- addDependency(importNamespace(node$1, imported, source, namespaceStmts));
369
- break;
339
+ const inferredStack = [];
340
+ let currentInferred = /* @__PURE__ */ new Set();
341
+ function isInferred(node$1) {
342
+ return node$1.type === "Identifier" && currentInferred.has(node$1.name);
343
+ }
344
+ walkAST(node, {
345
+ enter(node$1) {
346
+ if (node$1.type === "TSConditionalType") {
347
+ const inferred = collectInferredNames(node$1.extendsType);
348
+ inferredStack.push(inferred);
349
+ }
350
+ },
351
+ leave(node$1, parent) {
352
+ if (node$1.type === "TSConditionalType") inferredStack.pop();
353
+ else if (parent?.type === "TSConditionalType") {
354
+ const trueBranch = parent.trueType === node$1;
355
+ currentInferred = new Set((trueBranch ? inferredStack : inferredStack.slice(0, -1)).flat());
356
+ } else currentInferred = /* @__PURE__ */ new Set();
357
+ if (node$1.type === "ExportNamedDeclaration") {
358
+ for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
359
+ } else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(TSEntityNameToRuntime(heritage.expression));
360
+ else if (node$1.type === "ClassDeclaration") {
361
+ if (node$1.superClass) addDependency(node$1.superClass);
362
+ if (node$1.implements) for (const implement of node$1.implements) addDependency(TSEntityNameToRuntime(implement.expression));
363
+ } else if (isTypeOf(node$1, [
364
+ "ObjectMethod",
365
+ "ObjectProperty",
366
+ "ClassProperty",
367
+ "TSPropertySignature",
368
+ "TSDeclareMethod"
369
+ ])) {
370
+ if (node$1.computed && isReferenceId(node$1.key)) addDependency(node$1.key);
371
+ if ("value" in node$1 && isReferenceId(node$1.value)) addDependency(node$1.value);
372
+ } else switch (node$1.type) {
373
+ case "TSTypeReference":
374
+ addDependency(TSEntityNameToRuntime(node$1.typeName));
375
+ break;
376
+ case "TSTypeQuery":
377
+ if (seen.has(node$1.exprName)) return;
378
+ if (node$1.exprName.type === "TSImportType") break;
379
+ addDependency(TSEntityNameToRuntime(node$1.exprName));
380
+ break;
381
+ case "TSImportType": {
382
+ seen.add(node$1);
383
+ const source = node$1.argument;
384
+ const imported = node$1.qualifier;
385
+ addDependency(importNamespace(node$1, imported, source, namespaceStmts));
386
+ break;
387
+ }
370
388
  }
371
389
  }
372
- } });
390
+ });
373
391
  return Array.from(deps);
374
392
  function addDependency(node$1) {
375
- if (isThisExpression(node$1)) return;
393
+ if (isThisExpression(node$1) || isInferred(node$1)) return;
376
394
  deps.add(node$1);
377
395
  }
378
396
  }
@@ -402,6 +420,13 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
402
420
  };
403
421
  }
404
422
  }
423
+ function collectInferredNames(node) {
424
+ const inferred = [];
425
+ walkAST(node, { enter(node$1) {
426
+ if (node$1.type === "TSInferType" && node$1.typeParameter) inferred.push(node$1.typeParameter.name);
427
+ } });
428
+ return inferred;
429
+ }
405
430
  const REFERENCE_RE = /\/\s*<reference\s+(?:path|types)=/;
406
431
  function collectReferenceDirectives(comment, negative = false) {
407
432
  return comment.filter((c) => REFERENCE_RE.test(c.value) !== negative);
@@ -603,7 +628,7 @@ function inheritNodeComments(oldNode, newNode) {
603
628
 
604
629
  //#endregion
605
630
  //#region src/generate.ts
606
- const debug$1 = createDebug("rolldown-plugin-dts:generate");
631
+ const debug$2 = createDebug("rolldown-plugin-dts:generate");
607
632
  const WORKER_URL = "./tsc-worker.mjs";
608
633
  const spawnAsync = (...args) => new Promise((resolve, reject) => {
609
634
  const child = spawn(...args);
@@ -627,10 +652,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
627
652
  let tscModule;
628
653
  let tscContext;
629
654
  let tsgoDist;
655
+ const rootDir = tsconfig ? path.dirname(tsconfig) : cwd;
630
656
  return {
631
657
  name: "rolldown-plugin-dts:generate",
632
658
  async buildStart(options) {
633
- if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
659
+ if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig);
634
660
  else if (!oxc) if (parallel) {
635
661
  childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
636
662
  rpc = (await import("birpc")).createBirpc({}, {
@@ -642,11 +668,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
642
668
  if (newContext) tscContext = createContext();
643
669
  }
644
670
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
645
- debug$1("resolving input alias %s -> %s", name, id);
671
+ debug$2("resolving input alias %s -> %s", name, id);
646
672
  let resolved = await this.resolve(id);
647
673
  if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
648
674
  const resolvedId = resolved?.id || id;
649
- debug$1("resolved input alias %s -> %s", id, resolvedId);
675
+ debug$2("resolved input alias %s -> %s", id, resolvedId);
650
676
  inputAliasMap.set(resolvedId, name);
651
677
  }
652
678
  },
@@ -666,7 +692,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
666
692
  },
667
693
  resolveId(id) {
668
694
  if (dtsMap.has(id)) {
669
- debug$1("resolve dts id %s", id);
695
+ debug$2("resolve dts id %s", id);
670
696
  return { id };
671
697
  }
672
698
  },
@@ -690,7 +716,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
690
716
  id,
691
717
  isEntry
692
718
  });
693
- debug$1("register dts source: %s", id);
719
+ debug$2("register dts source: %s", id);
694
720
  if (isEntry) {
695
721
  const name = inputAliasMap.get(id);
696
722
  this.emitFile({
@@ -716,13 +742,13 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
716
742
  const { code, id } = dtsMap.get(dtsId);
717
743
  let dtsCode;
718
744
  let map;
719
- debug$1("generate dts %s from %s", dtsId, id);
745
+ debug$2("generate dts %s from %s", dtsId, id);
720
746
  if (tsgo) {
721
747
  if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
722
- const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_to_dts(id)));
748
+ const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(rootDir), filename_to_dts(id)));
723
749
  if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
724
750
  else {
725
- debug$1("[tsgo]", dtsPath, "is missing");
751
+ debug$2("[tsgo]", dtsPath, "is missing");
726
752
  throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
727
753
  }
728
754
  } else if (oxc && !RE_VUE.test(id)) {
@@ -731,7 +757,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
731
757
  const [error] = result.errors;
732
758
  return this.error({
733
759
  message: error.message,
734
- frame: error.codeframe
760
+ frame: error.codeframe || void 0
735
761
  });
736
762
  }
737
763
  dtsCode = result.code;
@@ -789,7 +815,7 @@ export { __json_default_export as default }`;
789
815
  } : void 0,
790
816
  async buildEnd() {
791
817
  childProcess?.kill();
792
- if (!debug$1.enabled && tsgoDist) await rm(tsgoDist, {
818
+ if (!debug$2.enabled && tsgoDist) await rm(tsgoDist, {
793
819
  recursive: true,
794
820
  force: true
795
821
  }).catch(() => {});
@@ -801,12 +827,13 @@ export { __json_default_export as default }`;
801
827
  }
802
828
  };
803
829
  }
804
- async function runTsgo(root, tsconfig) {
830
+ async function runTsgo(rootDir, tsconfig) {
805
831
  const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
806
832
  const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
807
833
  const tsgo = getExePath();
808
834
  const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
809
- debug$1("[tsgo] tsgoDist", tsgoDist);
835
+ debug$2("[tsgo] tsgoDist", tsgoDist);
836
+ debug$2("[tsgo] rootDir", rootDir);
810
837
  await spawnAsync(tsgo, [
811
838
  "--noEmit",
812
839
  "false",
@@ -816,7 +843,7 @@ async function runTsgo(root, tsconfig) {
816
843
  "--outDir",
817
844
  tsgoDist,
818
845
  "--rootDir",
819
- root,
846
+ rootDir,
820
847
  "--noCheck"
821
848
  ], { stdio: "inherit" });
822
849
  return tsgoDist;
@@ -923,6 +950,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
923
950
 
924
951
  //#endregion
925
952
  //#region src/resolver.ts
953
+ const debug$1 = createDebug("rolldown-plugin-dts:resolver");
926
954
  function isSourceFile(id) {
927
955
  return RE_TS.test(id) || RE_VUE.test(id) || RE_JSON.test(id);
928
956
  }
@@ -944,16 +972,31 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
944
972
  external: true,
945
973
  moduleSideEffects: sideEffects
946
974
  };
947
- if (RE_CSS.test(id)) return external;
975
+ if (RE_CSS.test(id)) {
976
+ debug$1("Externalizing css import:", id);
977
+ return external;
978
+ }
948
979
  const rolldownResolution = await this.resolve(id, importer, options);
980
+ debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
949
981
  const dtsResolution = await resolveDtsPath(id, importer, rolldownResolution);
950
- if (!dtsResolution) return isFilePath(id) ? null : external;
951
- if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) return external;
952
- if (RE_DTS.test(dtsResolution)) return {
953
- id: dtsResolution,
954
- moduleSideEffects
955
- };
982
+ debug$1("Dts resolution for dts import %O from %O: %O", id, importer, dtsResolution);
983
+ if (!dtsResolution) {
984
+ debug$1("Unresolvable dts import:", id, "from", importer);
985
+ return isFilePath(id) ? null : external;
986
+ }
987
+ if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) {
988
+ debug$1("Externalizing node_modules dts import:", id);
989
+ return external;
990
+ }
991
+ if (RE_DTS.test(dtsResolution)) {
992
+ debug$1("Resolving dts import to declaration file:", id);
993
+ return {
994
+ id: dtsResolution,
995
+ moduleSideEffects
996
+ };
997
+ }
956
998
  if (isSourceFile(dtsResolution)) {
999
+ debug$1("Resolving dts import to source file:", id);
957
1000
  await this.load({ id: dtsResolution });
958
1001
  return {
959
1002
  id: filename_to_dts(dtsResolution),
@@ -973,6 +1016,7 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
973
1016
  const { tscResolve } = await import("./resolver-DksQRwY1.mjs");
974
1017
  dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
975
1018
  } else dtsPath = baseDtsResolver(id, importer);
1019
+ debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
976
1020
  if (dtsPath) dtsPath = path.normalize(dtsPath);
977
1021
  if (!dtsPath || !isSourceFile(dtsPath)) {
978
1022
  if (rolldownResolution && isFilePath(rolldownResolution.id) && isSourceFile(rolldownResolution.id) && !rolldownResolution.external) return rolldownResolution.id;
@@ -341,7 +341,7 @@ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, tsMacro, cwd
341
341
  const fsSystem = createFsSystem(context.files);
342
342
  const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
343
343
  const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
344
- debug$1(`Creating program for root project: ${baseDir}`);
344
+ debug$1(`creating program for root project: ${baseDir}`);
345
345
  return createTsProgramFromParsedConfig({
346
346
  parsedConfig,
347
347
  fsSystem,
@@ -404,9 +404,12 @@ function tscEmitCompiler(tscOptions) {
404
404
  }
405
405
  }, void 0, true, customTransformers, true);
406
406
  if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
407
- if (!dtsCode && file.isDeclarationFile) {
408
- debug$1("nothing was emitted. fallback to sourceFile text.");
409
- dtsCode = file.getFullText();
407
+ if (!dtsCode) {
408
+ debug$1("nothing was emitted.");
409
+ if (file.isDeclarationFile) {
410
+ debug$1("source file is a declaration file.");
411
+ dtsCode = file.getFullText();
412
+ } else console.warn("[rolldown-plugin-dts] Warning: Failed to emit declaration file. Please try to enable `eager` option (`dts.eager` for tsdown).");
410
413
  }
411
414
  return {
412
415
  code: dtsCode,
@@ -1,4 +1,4 @@
1
- import { t as tscEmit } from "./tsc-BW5Mr7EL.mjs";
1
+ import { t as tscEmit } from "./tsc-Cn0kGE1h.mjs";
2
2
  import "./context-EuY-ImLj.mjs";
3
3
  const process = globalThis.process;
4
4
  import { createBirpc } from "birpc";
package/dist/tsc.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as tscEmit } from "./tsc-BW5Mr7EL.mjs";
1
+ import { t as tscEmit } from "./tsc-Cn0kGE1h.mjs";
2
2
  import "./context-EuY-ImLj.mjs";
3
3
 
4
4
  export { tscEmit };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
3
  "type": "module",
4
- "version": "0.18.2",
4
+ "version": "0.18.4",
5
5
  "description": "A Rolldown plugin to generate and bundle dts files.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -68,35 +68,35 @@
68
68
  "@babel/parser": "^7.28.5",
69
69
  "@babel/types": "^7.28.5",
70
70
  "ast-kit": "^2.2.0",
71
- "birpc": "^3.0.0",
71
+ "birpc": "^4.0.0",
72
72
  "dts-resolver": "^2.1.3",
73
73
  "get-tsconfig": "^4.13.0",
74
74
  "magic-string": "^0.30.21",
75
75
  "obug": "^2.1.1"
76
76
  },
77
77
  "devDependencies": {
78
- "@sxzz/eslint-config": "^7.4.1",
78
+ "@sxzz/eslint-config": "^7.4.3",
79
79
  "@sxzz/prettier-config": "^2.2.6",
80
- "@sxzz/test-utils": "^0.5.13",
80
+ "@sxzz/test-utils": "^0.5.14",
81
81
  "@types/babel__generator": "^7.27.0",
82
- "@types/node": "^24.10.1",
83
- "@typescript/native-preview": "7.0.0-dev.20251203.1",
84
- "@volar/typescript": "^2.4.26",
85
- "@vue/language-core": "^3.1.5",
86
- "arktype": "^2.1.28",
82
+ "@types/node": "^25.0.2",
83
+ "@typescript/native-preview": "7.0.0-dev.20251216.1",
84
+ "@volar/typescript": "^2.4.27",
85
+ "@vue/language-core": "^3.1.8",
86
+ "arktype": "^2.1.29",
87
87
  "bumpp": "^10.3.2",
88
88
  "diff": "^8.0.2",
89
- "eslint": "^9.39.1",
89
+ "eslint": "^9.39.2",
90
90
  "prettier": "^3.7.4",
91
- "rolldown": "^1.0.0-beta.53",
92
- "rolldown-plugin-require-cjs": "^0.3.2",
91
+ "rolldown": "^1.0.0-beta.54",
92
+ "rolldown-plugin-require-cjs": "^0.3.3",
93
93
  "rollup-plugin-dts": "^6.3.0",
94
94
  "tinyglobby": "^0.2.15",
95
- "tsdown": "^0.17.0-beta.6",
95
+ "tsdown": "^0.18.0",
96
96
  "typescript": "^5.9.3",
97
- "vitest": "^4.0.15",
97
+ "vitest": "^4.0.16",
98
98
  "vue": "^3.5.25",
99
- "vue-tsc": "^3.1.5"
99
+ "vue-tsc": "^3.1.8"
100
100
  },
101
101
  "prettier": "@sxzz/prettier-config",
102
102
  "scripts": {