rolldown-plugin-dts 0.18.3 → 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
@@ -628,7 +628,7 @@ function inheritNodeComments(oldNode, newNode) {
628
628
 
629
629
  //#endregion
630
630
  //#region src/generate.ts
631
- const debug$1 = createDebug("rolldown-plugin-dts:generate");
631
+ const debug$2 = createDebug("rolldown-plugin-dts:generate");
632
632
  const WORKER_URL = "./tsc-worker.mjs";
633
633
  const spawnAsync = (...args) => new Promise((resolve, reject) => {
634
634
  const child = spawn(...args);
@@ -652,10 +652,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
652
652
  let tscModule;
653
653
  let tscContext;
654
654
  let tsgoDist;
655
+ const rootDir = tsconfig ? path.dirname(tsconfig) : cwd;
655
656
  return {
656
657
  name: "rolldown-plugin-dts:generate",
657
658
  async buildStart(options) {
658
- if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
659
+ if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig);
659
660
  else if (!oxc) if (parallel) {
660
661
  childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
661
662
  rpc = (await import("birpc")).createBirpc({}, {
@@ -667,11 +668,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
667
668
  if (newContext) tscContext = createContext();
668
669
  }
669
670
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
670
- debug$1("resolving input alias %s -> %s", name, id);
671
+ debug$2("resolving input alias %s -> %s", name, id);
671
672
  let resolved = await this.resolve(id);
672
673
  if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
673
674
  const resolvedId = resolved?.id || id;
674
- debug$1("resolved input alias %s -> %s", id, resolvedId);
675
+ debug$2("resolved input alias %s -> %s", id, resolvedId);
675
676
  inputAliasMap.set(resolvedId, name);
676
677
  }
677
678
  },
@@ -691,7 +692,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
691
692
  },
692
693
  resolveId(id) {
693
694
  if (dtsMap.has(id)) {
694
- debug$1("resolve dts id %s", id);
695
+ debug$2("resolve dts id %s", id);
695
696
  return { id };
696
697
  }
697
698
  },
@@ -715,7 +716,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
715
716
  id,
716
717
  isEntry
717
718
  });
718
- debug$1("register dts source: %s", id);
719
+ debug$2("register dts source: %s", id);
719
720
  if (isEntry) {
720
721
  const name = inputAliasMap.get(id);
721
722
  this.emitFile({
@@ -741,13 +742,13 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
741
742
  const { code, id } = dtsMap.get(dtsId);
742
743
  let dtsCode;
743
744
  let map;
744
- debug$1("generate dts %s from %s", dtsId, id);
745
+ debug$2("generate dts %s from %s", dtsId, id);
745
746
  if (tsgo) {
746
747
  if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
747
- 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)));
748
749
  if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
749
750
  else {
750
- debug$1("[tsgo]", dtsPath, "is missing");
751
+ debug$2("[tsgo]", dtsPath, "is missing");
751
752
  throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
752
753
  }
753
754
  } else if (oxc && !RE_VUE.test(id)) {
@@ -756,7 +757,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
756
757
  const [error] = result.errors;
757
758
  return this.error({
758
759
  message: error.message,
759
- frame: error.codeframe
760
+ frame: error.codeframe || void 0
760
761
  });
761
762
  }
762
763
  dtsCode = result.code;
@@ -814,7 +815,7 @@ export { __json_default_export as default }`;
814
815
  } : void 0,
815
816
  async buildEnd() {
816
817
  childProcess?.kill();
817
- if (!debug$1.enabled && tsgoDist) await rm(tsgoDist, {
818
+ if (!debug$2.enabled && tsgoDist) await rm(tsgoDist, {
818
819
  recursive: true,
819
820
  force: true
820
821
  }).catch(() => {});
@@ -826,12 +827,13 @@ export { __json_default_export as default }`;
826
827
  }
827
828
  };
828
829
  }
829
- async function runTsgo(root, tsconfig) {
830
+ async function runTsgo(rootDir, tsconfig) {
830
831
  const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
831
832
  const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
832
833
  const tsgo = getExePath();
833
834
  const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
834
- debug$1("[tsgo] tsgoDist", tsgoDist);
835
+ debug$2("[tsgo] tsgoDist", tsgoDist);
836
+ debug$2("[tsgo] rootDir", rootDir);
835
837
  await spawnAsync(tsgo, [
836
838
  "--noEmit",
837
839
  "false",
@@ -841,7 +843,7 @@ async function runTsgo(root, tsconfig) {
841
843
  "--outDir",
842
844
  tsgoDist,
843
845
  "--rootDir",
844
- root,
846
+ rootDir,
845
847
  "--noCheck"
846
848
  ], { stdio: "inherit" });
847
849
  return tsgoDist;
@@ -948,6 +950,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
948
950
 
949
951
  //#endregion
950
952
  //#region src/resolver.ts
953
+ const debug$1 = createDebug("rolldown-plugin-dts:resolver");
951
954
  function isSourceFile(id) {
952
955
  return RE_TS.test(id) || RE_VUE.test(id) || RE_JSON.test(id);
953
956
  }
@@ -969,16 +972,31 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
969
972
  external: true,
970
973
  moduleSideEffects: sideEffects
971
974
  };
972
- if (RE_CSS.test(id)) return external;
975
+ if (RE_CSS.test(id)) {
976
+ debug$1("Externalizing css import:", id);
977
+ return external;
978
+ }
973
979
  const rolldownResolution = await this.resolve(id, importer, options);
980
+ debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
974
981
  const dtsResolution = await resolveDtsPath(id, importer, rolldownResolution);
975
- if (!dtsResolution) return isFilePath(id) ? null : external;
976
- if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) return external;
977
- if (RE_DTS.test(dtsResolution)) return {
978
- id: dtsResolution,
979
- moduleSideEffects
980
- };
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
+ }
981
998
  if (isSourceFile(dtsResolution)) {
999
+ debug$1("Resolving dts import to source file:", id);
982
1000
  await this.load({ id: dtsResolution });
983
1001
  return {
984
1002
  id: filename_to_dts(dtsResolution),
@@ -998,6 +1016,7 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
998
1016
  const { tscResolve } = await import("./resolver-DksQRwY1.mjs");
999
1017
  dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
1000
1018
  } else dtsPath = baseDtsResolver(id, importer);
1019
+ debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
1001
1020
  if (dtsPath) dtsPath = path.normalize(dtsPath);
1002
1021
  if (!dtsPath || !isSourceFile(dtsPath)) {
1003
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.3",
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.20251204.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",
91
+ "rolldown": "^1.0.0-beta.54",
92
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",
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": {