rolldown-plugin-dts 0.18.3 → 0.19.0

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/README.md CHANGED
@@ -108,14 +108,6 @@ If set to `true`, and you are only exporting a single item using `export default
108
108
  the output will use `export = ...` instead of the standard ES module syntax.
109
109
  This is useful for compatibility with CommonJS.
110
110
 
111
- #### `banner`
112
-
113
- Content to be added at the top of each generated `.d.ts` file.
114
-
115
- #### `footer`
116
-
117
- Content to be added at the bottom of each generated `.d.ts` file.
118
-
119
111
  #### `sideEffects`
120
112
 
121
113
  Indicates whether the generated `.d.ts` files have side effects.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as RE_JSON, c as RE_VUE, i as RE_JS, n as RE_DTS, o as RE_NODE_MODULES, r as RE_DTS_MAP, s as RE_TS, t as RE_CSS } from "./filename-Dn8CLu7g.mjs";
2
2
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
3
3
  import { TsConfigJson } from "get-tsconfig";
4
- import { AddonFunction, Plugin } from "rolldown";
4
+ import { Plugin } from "rolldown";
5
5
 
6
6
  //#region src/options.d.ts
7
7
  interface GeneralOptions {
@@ -161,14 +161,6 @@ interface TscOptions {
161
161
  * `false`.
162
162
  */
163
163
  emitJs?: boolean;
164
- /**
165
- * Content to be added at the top of each generated `.d.ts` file.
166
- */
167
- banner?: string | Promise<string> | AddonFunction;
168
- /**
169
- * Content to be added at the bottom of each generated `.d.ts` file.
170
- */
171
- footer?: string | Promise<string> | AddonFunction;
172
164
  }
173
165
  interface Options extends GeneralOptions, TscOptions {
174
166
  /**
@@ -189,8 +181,7 @@ interface Options extends GeneralOptions, TscOptions {
189
181
  tsgo?: boolean;
190
182
  }
191
183
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
192
- type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
193
- type OptionsResolved = Overwrite<MarkPartial<Omit<Options, "compilerOptions">, "banner" | "footer">, {
184
+ type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
194
185
  tsconfig?: string;
195
186
  oxc: IsolatedDeclarationsOptions | false;
196
187
  tsconfigRaw: TsConfigJson;
@@ -206,8 +197,6 @@ declare function resolveOptions({
206
197
  resolve,
207
198
  resolver,
208
199
  cjsDefault,
209
- banner,
210
- footer,
211
200
  sideEffects,
212
201
  build,
213
202
  incremental,
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ const __cjs_require = globalThis.process.getBuiltinModule("module").createRequir
2
2
  import { a as RE_JSON, c as RE_VUE, d as filename_to_dts, f as replaceTemplateName, i as RE_JS, l as filename_dts_to, n as RE_DTS, o as RE_NODE_MODULES, p as resolveTemplateFn, r as RE_DTS_MAP, s as RE_TS, t as RE_CSS, u as filename_js_to_dts } from "./filename-Cqnsj8Gp.mjs";
3
3
  import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-EuY-ImLj.mjs";
4
4
  import { createDebug } from "obug";
5
- import MagicString from "magic-string";
6
5
  const {
7
6
  generate
8
7
  } = __cjs_require("@babel/generator");
@@ -32,36 +31,6 @@ const process = globalThis.process;
32
31
  import { getTsconfig, parseTsconfig } from "get-tsconfig";
33
32
  import { createResolver } from "dts-resolver";
34
33
 
35
- //#region src/banner.ts
36
- function createBannerPlugin({ banner, footer }) {
37
- return {
38
- name: "rolldown-plugin-dts:banner",
39
- async renderChunk(code, chunk) {
40
- if (!RE_DTS.test(chunk.fileName)) return;
41
- const s = new MagicString(code);
42
- if (banner) {
43
- const code$1 = await (typeof banner === "function" ? banner(chunk) : banner);
44
- if (code$1) s.prepend(`${code$1}\n`);
45
- }
46
- if (footer) {
47
- const code$1 = await (typeof footer === "function" ? footer(chunk) : footer);
48
- if (code$1) s.append(`\n${code$1}`);
49
- }
50
- return {
51
- code: s.toString(),
52
- get map() {
53
- return s.generateMap({
54
- source: chunk.fileName,
55
- includeContent: true,
56
- hires: "boundary"
57
- });
58
- }
59
- };
60
- }
61
- };
62
- }
63
-
64
- //#endregion
65
34
  //#region src/dts-input.ts
66
35
  function createDtsInputPlugin({ sideEffects }) {
67
36
  return {
@@ -628,7 +597,7 @@ function inheritNodeComments(oldNode, newNode) {
628
597
 
629
598
  //#endregion
630
599
  //#region src/generate.ts
631
- const debug$1 = createDebug("rolldown-plugin-dts:generate");
600
+ const debug$2 = createDebug("rolldown-plugin-dts:generate");
632
601
  const WORKER_URL = "./tsc-worker.mjs";
633
602
  const spawnAsync = (...args) => new Promise((resolve, reject) => {
634
603
  const child = spawn(...args);
@@ -652,10 +621,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
652
621
  let tscModule;
653
622
  let tscContext;
654
623
  let tsgoDist;
624
+ const rootDir = tsconfig ? path.dirname(tsconfig) : cwd;
655
625
  return {
656
626
  name: "rolldown-plugin-dts:generate",
657
627
  async buildStart(options) {
658
- if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
628
+ if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig);
659
629
  else if (!oxc) if (parallel) {
660
630
  childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
661
631
  rpc = (await import("birpc")).createBirpc({}, {
@@ -667,11 +637,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
667
637
  if (newContext) tscContext = createContext();
668
638
  }
669
639
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
670
- debug$1("resolving input alias %s -> %s", name, id);
640
+ debug$2("resolving input alias %s -> %s", name, id);
671
641
  let resolved = await this.resolve(id);
672
642
  if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
673
643
  const resolvedId = resolved?.id || id;
674
- debug$1("resolved input alias %s -> %s", id, resolvedId);
644
+ debug$2("resolved input alias %s -> %s", id, resolvedId);
675
645
  inputAliasMap.set(resolvedId, name);
676
646
  }
677
647
  },
@@ -691,7 +661,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
691
661
  },
692
662
  resolveId(id) {
693
663
  if (dtsMap.has(id)) {
694
- debug$1("resolve dts id %s", id);
664
+ debug$2("resolve dts id %s", id);
695
665
  return { id };
696
666
  }
697
667
  },
@@ -715,7 +685,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
715
685
  id,
716
686
  isEntry
717
687
  });
718
- debug$1("register dts source: %s", id);
688
+ debug$2("register dts source: %s", id);
719
689
  if (isEntry) {
720
690
  const name = inputAliasMap.get(id);
721
691
  this.emitFile({
@@ -741,13 +711,13 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
741
711
  const { code, id } = dtsMap.get(dtsId);
742
712
  let dtsCode;
743
713
  let map;
744
- debug$1("generate dts %s from %s", dtsId, id);
714
+ debug$2("generate dts %s from %s", dtsId, id);
745
715
  if (tsgo) {
746
716
  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)));
717
+ const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(rootDir), filename_to_dts(id)));
748
718
  if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
749
719
  else {
750
- debug$1("[tsgo]", dtsPath, "is missing");
720
+ debug$2("[tsgo]", dtsPath, "is missing");
751
721
  throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
752
722
  }
753
723
  } else if (oxc && !RE_VUE.test(id)) {
@@ -756,7 +726,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
756
726
  const [error] = result.errors;
757
727
  return this.error({
758
728
  message: error.message,
759
- frame: error.codeframe
729
+ frame: error.codeframe || void 0
760
730
  });
761
731
  }
762
732
  dtsCode = result.code;
@@ -814,7 +784,7 @@ export { __json_default_export as default }`;
814
784
  } : void 0,
815
785
  async buildEnd() {
816
786
  childProcess?.kill();
817
- if (!debug$1.enabled && tsgoDist) await rm(tsgoDist, {
787
+ if (!debug$2.enabled && tsgoDist) await rm(tsgoDist, {
818
788
  recursive: true,
819
789
  force: true
820
790
  }).catch(() => {});
@@ -826,12 +796,13 @@ export { __json_default_export as default }`;
826
796
  }
827
797
  };
828
798
  }
829
- async function runTsgo(root, tsconfig) {
799
+ async function runTsgo(rootDir, tsconfig) {
830
800
  const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
831
801
  const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
832
802
  const tsgo = getExePath();
833
803
  const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
834
- debug$1("[tsgo] tsgoDist", tsgoDist);
804
+ debug$2("[tsgo] tsgoDist", tsgoDist);
805
+ debug$2("[tsgo] rootDir", rootDir);
835
806
  await spawnAsync(tsgo, [
836
807
  "--noEmit",
837
808
  "false",
@@ -841,7 +812,7 @@ async function runTsgo(root, tsconfig) {
841
812
  "--outDir",
842
813
  tsgoDist,
843
814
  "--rootDir",
844
- root,
815
+ rootDir,
845
816
  "--noCheck"
846
817
  ], { stdio: "inherit" });
847
818
  return tsgoDist;
@@ -880,7 +851,7 @@ function collectJsonExports(code) {
880
851
  //#endregion
881
852
  //#region src/options.ts
882
853
  let warnedTsgo = false;
883
- function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, resolver = "oxc", cjsDefault = false, banner, footer, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
854
+ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
884
855
  let resolvedTsconfig;
885
856
  if (tsconfig === true || tsconfig == null) {
886
857
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -930,8 +901,6 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
930
901
  resolve,
931
902
  resolver,
932
903
  cjsDefault,
933
- banner,
934
- footer,
935
904
  sideEffects,
936
905
  build,
937
906
  incremental,
@@ -948,6 +917,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
948
917
 
949
918
  //#endregion
950
919
  //#region src/resolver.ts
920
+ const debug$1 = createDebug("rolldown-plugin-dts:resolver");
951
921
  function isSourceFile(id) {
952
922
  return RE_TS.test(id) || RE_VUE.test(id) || RE_JSON.test(id);
953
923
  }
@@ -969,16 +939,31 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
969
939
  external: true,
970
940
  moduleSideEffects: sideEffects
971
941
  };
972
- if (RE_CSS.test(id)) return external;
942
+ if (RE_CSS.test(id)) {
943
+ debug$1("Externalizing css import:", id);
944
+ return external;
945
+ }
973
946
  const rolldownResolution = await this.resolve(id, importer, options);
947
+ debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
974
948
  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
- };
949
+ debug$1("Dts resolution for dts import %O from %O: %O", id, importer, dtsResolution);
950
+ if (!dtsResolution) {
951
+ debug$1("Unresolvable dts import:", id, "from", importer);
952
+ return isFilePath(id) ? null : external;
953
+ }
954
+ if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) {
955
+ debug$1("Externalizing node_modules dts import:", id);
956
+ return external;
957
+ }
958
+ if (RE_DTS.test(dtsResolution)) {
959
+ debug$1("Resolving dts import to declaration file:", id);
960
+ return {
961
+ id: dtsResolution,
962
+ moduleSideEffects
963
+ };
964
+ }
981
965
  if (isSourceFile(dtsResolution)) {
966
+ debug$1("Resolving dts import to source file:", id);
982
967
  await this.load({ id: dtsResolution });
983
968
  return {
984
969
  id: filename_to_dts(dtsResolution),
@@ -998,6 +983,7 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
998
983
  const { tscResolve } = await import("./resolver-DksQRwY1.mjs");
999
984
  dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
1000
985
  } else dtsPath = baseDtsResolver(id, importer);
986
+ debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
1001
987
  if (dtsPath) dtsPath = path.normalize(dtsPath);
1002
988
  if (!dtsPath || !isSourceFile(dtsPath)) {
1003
989
  if (rolldownResolution && isFilePath(rolldownResolution.id) && isSourceFile(rolldownResolution.id) && !rolldownResolution.external) return rolldownResolution.id;
@@ -1021,7 +1007,6 @@ function dts(options = {}) {
1021
1007
  if (options.dtsInput) plugins.push(createDtsInputPlugin(resolved));
1022
1008
  else plugins.push(createGeneratePlugin(resolved));
1023
1009
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
1024
- if (options.banner || options.footer) plugins.push(createBannerPlugin(resolved));
1025
1010
  return plugins;
1026
1011
  }
1027
1012
 
@@ -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.19.0",
5
5
  "description": "A Rolldown plugin to generate and bundle dts files.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "peerDependencies": {
46
46
  "@ts-macro/tsc": "^0.3.6",
47
47
  "@typescript/native-preview": ">=7.0.0-dev.20250601.1",
48
- "rolldown": "^1.0.0-beta.51",
48
+ "rolldown": "^1.0.0-beta.55",
49
49
  "typescript": "^5.0.0",
50
50
  "vue-tsc": "~3.1.0"
51
51
  },
@@ -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.15",
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.3",
83
+ "@typescript/native-preview": "7.0.0-dev.20251217.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.55",
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": {