rolldown-plugin-dts 0.16.3 → 0.16.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.
@@ -18,6 +18,7 @@ interface TscOptions {
18
18
  id: string;
19
19
  sourcemap: boolean;
20
20
  vue?: boolean;
21
+ tsMacro?: boolean;
21
22
  context?: TscContext;
22
23
  }
23
24
  interface TscResult {
package/dist/index.d.ts CHANGED
@@ -110,6 +110,10 @@ interface TscOptions {
110
110
  */
111
111
  vue?: boolean;
112
112
  /**
113
+ * If `true`, the plugin will generate `.d.ts` files using `@ts-macro/tsc`.
114
+ */
115
+ tsMacro?: boolean;
116
+ /**
113
117
  * If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
114
118
  * This enables processing multiple projects in parallel.
115
119
  */
@@ -178,6 +182,7 @@ declare function resolveOptions({
178
182
  build,
179
183
  incremental,
180
184
  vue,
185
+ tsMacro,
181
186
  parallel,
182
187
  eager,
183
188
  newContext,
@@ -202,13 +207,14 @@ declare function createGeneratePlugin({
202
207
  oxc,
203
208
  emitDtsOnly,
204
209
  vue,
210
+ tsMacro,
205
211
  parallel,
206
212
  eager,
207
213
  tsgo,
208
214
  newContext,
209
215
  emitJs,
210
216
  sourcemap
211
- }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
217
+ }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
212
218
  //#endregion
213
219
  //#region src/index.d.ts
214
220
  declare function dts(options?: Options): Plugin[];
package/dist/index.js CHANGED
@@ -325,11 +325,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
325
325
  ...sideEffect ? [t.callExpression(t.identifier("sideEffect"), [bindings[0]])] : []
326
326
  ];
327
327
  const runtime = t.arrayExpression(elements);
328
- if (decl !== stmt) {
329
- decl.innerComments = stmt.innerComments;
330
- decl.leadingComments = stmt.leadingComments;
331
- decl.trailingComments = stmt.trailingComments;
332
- }
328
+ if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
333
329
  const symbolId = registerSymbol({
334
330
  decl,
335
331
  deps,
@@ -662,7 +658,6 @@ function inheritNodeComments(oldNode, newNode) {
662
658
  const leadingComments = oldNode.leadingComments?.filter((comment) => comment.value.startsWith("#"));
663
659
  if (leadingComments) newNode.leadingComments.unshift(...leadingComments);
664
660
  newNode.leadingComments = collectReferenceDirectives(newNode.leadingComments, true);
665
- newNode.trailingComments = newNode.trailingComments?.filter((comment) => !comment.value.startsWith("# sourceMappingURL"));
666
661
  return newNode;
667
662
  }
668
663
 
@@ -675,7 +670,7 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
675
670
  child.on("close", () => resolve());
676
671
  child.on("error", (error) => reject(error));
677
672
  });
678
- function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
673
+ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
679
674
  const dtsMap = /* @__PURE__ */ new Map();
680
675
  /**
681
676
  * A map of input id to output file name
@@ -812,6 +807,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
812
807
  id,
813
808
  sourcemap,
814
809
  vue,
810
+ tsMacro,
815
811
  context: tscContext
816
812
  };
817
813
  let result;
@@ -869,7 +865,7 @@ async function runTsgo(root, tsconfig) {
869
865
  //#endregion
870
866
  //#region src/options.ts
871
867
  let warnedTsgo = false;
872
- function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, cjsDefault = false, build = false, incremental = false, vue = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
868
+ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, cjsDefault = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
873
869
  let resolvedTsconfig;
874
870
  if (tsconfig === true || tsconfig == null) {
875
871
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -891,7 +887,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
891
887
  ...overriddenTsconfigRaw,
892
888
  compilerOptions
893
889
  };
894
- oxc ??= !!(compilerOptions?.isolatedDeclarations && !vue && !tsgo);
890
+ oxc ??= !!(compilerOptions?.isolatedDeclarations && !vue && !tsgo && !tsMacro);
895
891
  if (oxc === true) oxc = {};
896
892
  if (oxc) {
897
893
  oxc.stripInternal ??= !!compilerOptions?.stripInternal;
@@ -900,9 +896,11 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
900
896
  emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
901
897
  if (tsgo) {
902
898
  if (vue) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");
899
+ if (tsMacro) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `tsMacro` option. Please disable one of them.");
903
900
  if (oxc) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.");
904
901
  }
905
902
  if (oxc && vue) throw new Error("[rolldown-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");
903
+ if (oxc && tsMacro) throw new Error("[rolldown-plugin-dts] The `oxc` option is not compatible with the `tsMacro` option. Please disable one of them.");
906
904
  if (tsgo && !warnedTsgo) {
907
905
  console.warn("The `tsgo` option is experimental and may change in the future.");
908
906
  warnedTsgo = true;
@@ -919,6 +917,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
919
917
  build,
920
918
  incremental,
921
919
  vue,
920
+ tsMacro,
922
921
  parallel,
923
922
  eager,
924
923
  newContext,
@@ -6,7 +6,7 @@ import ts from "typescript";
6
6
  import { pathToFileURL } from "node:url";
7
7
 
8
8
  //#region src/tsc/system.ts
9
- const debug$4 = Debug("rolldown-plugin-dts:tsc-system");
9
+ const debug$3 = Debug("rolldown-plugin-dts:tsc-system");
10
10
  /**
11
11
  * A system that writes files to both memory and disk. It will try read files
12
12
  * from memory firstly and fallback to disk if not found.
@@ -15,7 +15,7 @@ function createFsSystem(files) {
15
15
  return {
16
16
  ...ts.sys,
17
17
  write(message) {
18
- debug$4(message);
18
+ debug$3(message);
19
19
  },
20
20
  resolvePath(path$1) {
21
21
  if (files.has(path$1)) return path$1;
@@ -80,20 +80,20 @@ function setSourceMapRoot(map, originalFilePath, finalFilePath) {
80
80
 
81
81
  //#endregion
82
82
  //#region src/tsc/emit-build.ts
83
- const debug$3 = Debug("rolldown-plugin-dts:tsc-build");
83
+ const debug$2 = Debug("rolldown-plugin-dts:tsc-build");
84
84
  function tscEmitBuild(tscOptions) {
85
85
  const { id, tsconfig, incremental, context = globalContext, sourcemap } = tscOptions;
86
- debug$3(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
86
+ debug$2(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
87
87
  if (!tsconfig) return { error: "[rolldown-plugin-dts] build mode requires a tsconfig path" };
88
88
  const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
89
89
  const resolvedId = fsSystem.resolvePath(id);
90
- if (resolvedId !== id) debug$3(`resolved id from ${id} to ${resolvedId}`);
90
+ if (resolvedId !== id) debug$2(`resolved id from ${id} to ${resolvedId}`);
91
91
  const project = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap).get(resolvedId);
92
92
  if (!project) {
93
- debug$3(`unable to locate a project containing ${resolvedId}`);
93
+ debug$2(`unable to locate a project containing ${resolvedId}`);
94
94
  return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
95
95
  }
96
- debug$3(`loaded project ${project.tsconfigPath} for ${id}`);
96
+ debug$2(`loaded project ${project.tsconfigPath} for ${id}`);
97
97
  const ignoreCase = !fsSystem.useCaseSensitiveFileNames;
98
98
  const outputFiles = ts.getOutputFileNames(project.parsedConfig, resolvedId, ignoreCase);
99
99
  let code;
@@ -123,20 +123,20 @@ function tscEmitBuild(tscOptions) {
123
123
  map
124
124
  };
125
125
  if (incremental) {
126
- debug$3(`incremental build failed`);
126
+ debug$2(`incremental build failed`);
127
127
  return tscEmitBuild({
128
128
  ...tscOptions,
129
129
  incremental: false
130
130
  });
131
131
  }
132
- debug$3(`unable to build .d.ts file for ${id}`);
132
+ debug$2(`unable to build .d.ts file for ${id}`);
133
133
  if (project.parsedConfig.options.declaration !== true) return { error: `Unable to build .d.ts file for ${id}; Make sure the "declaration" option is set to true in ${project.tsconfigPath}` };
134
134
  return { error: `Unable to build .d.ts file for ${id}; This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues` };
135
135
  }
136
136
  function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
137
137
  let projectMap = context.projects.get(tsconfig);
138
138
  if (projectMap) {
139
- debug$3(`skip building projects for ${tsconfig}`);
139
+ debug$2(`skip building projects for ${tsconfig}`);
140
140
  return projectMap;
141
141
  }
142
142
  projectMap = buildProjects(fsSystem, tsconfig, force, sourcemap);
@@ -147,18 +147,18 @@ function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
147
147
  * Use TypeScript compiler to build all projects referenced
148
148
  */
149
149
  function buildProjects(fsSystem, tsconfig, force, sourcemap) {
150
- debug$3(`start building projects for ${tsconfig}`);
150
+ debug$2(`start building projects for ${tsconfig}`);
151
151
  const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
152
- debug$3("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
152
+ debug$2("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
153
153
  const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
154
154
  const exitStatus = ts.createSolutionBuilder(host, [tsconfig], {
155
155
  force,
156
156
  verbose: true
157
157
  }).build(void 0, void 0, void 0, (project) => {
158
- debug$3(`transforming project ${project}`);
158
+ debug$2(`transforming project ${project}`);
159
159
  return customTransformers;
160
160
  });
161
- debug$3(`built solution for ${tsconfig} with exit status ${exitStatus}`);
161
+ debug$2(`built solution for ${tsconfig} with exit status ${exitStatus}`);
162
162
  const sourceFileToProjectMap = /* @__PURE__ */ new Map();
163
163
  for (const project of projects) for (const fileName of project.parsedConfig.fileNames) sourceFileToProjectMap.set(fsSystem.resolvePath(fileName), project);
164
164
  return sourceFileToProjectMap;
@@ -234,36 +234,64 @@ const createProgramWithPatchedCompilerOptions = (rootNames, options, ...args) =>
234
234
  };
235
235
 
236
236
  //#endregion
237
- //#region src/tsc/vue.ts
238
- const debug$2 = Debug("rolldown-plugin-dts:vue");
239
- let createVueProgram;
237
+ //#region src/tsc/volar.ts
240
238
  const require = createRequire(import.meta.url);
241
239
  function loadVueLanguageTools() {
240
+ const debug$4 = Debug("rolldown-plugin-dts:vue");
241
+ debug$4("loading vue language tools");
242
242
  try {
243
243
  const vueTscPath = require.resolve("vue-tsc");
244
244
  const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
245
245
  const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
246
+ const getLanguagePlugin = (ts$1, options) => {
247
+ const $rootDir = options.options.$rootDir;
248
+ const $configRaw = options.options.$configRaw;
249
+ const resolver = new vue.CompilerOptionsResolver(ts$1.sys.fileExists);
250
+ resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
251
+ const vueOptions = resolver.build();
252
+ vue.writeGlobalTypes(vueOptions, ts$1.sys.writeFile);
253
+ return vue.createVueLanguagePlugin(ts$1, options.options, vueOptions, (id) => id);
254
+ };
246
255
  return {
247
256
  proxyCreateProgram,
248
- vue
257
+ getLanguagePlugin
249
258
  };
250
259
  } catch (error) {
251
- debug$2("vue language tools not found", error);
260
+ debug$4("vue language tools not found", error);
252
261
  throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
253
262
  }
254
263
  }
255
- function createVueProgramFactory(ts$1) {
256
- if (createVueProgram) return createVueProgram;
257
- debug$2("loading vue language tools");
258
- const { proxyCreateProgram, vue } = loadVueLanguageTools();
259
- return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
260
- const $rootDir = options.options.$rootDir;
261
- const $configRaw = options.options.$configRaw;
262
- const resolver = new vue.CompilerOptionsResolver(ts$2.sys.fileExists);
263
- resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
264
- const vueOptions = resolver.build();
265
- vue.writeGlobalTypes(vueOptions, ts$2.sys.writeFile);
266
- return { languagePlugins: [vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id)] };
264
+ function loadTsMacro() {
265
+ const debug$4 = Debug("rolldown-plugin-dts:ts-macro");
266
+ debug$4("loading ts-macro language tools");
267
+ try {
268
+ const tsMacroPath = require.resolve("@ts-macro/tsc");
269
+ const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [tsMacroPath] }));
270
+ const tsMacro = require(require.resolve("@ts-macro/language-plugin", { paths: [tsMacroPath] }));
271
+ const { getOptions } = require(require.resolve("@ts-macro/language-plugin/options", { paths: [tsMacroPath] }));
272
+ const getLanguagePlugin = (ts$1, options) => {
273
+ const $rootDir = options.options.$rootDir;
274
+ return tsMacro.getLanguagePlugins(ts$1, options.options, getOptions(ts$1, $rootDir))[0];
275
+ };
276
+ return {
277
+ proxyCreateProgram,
278
+ getLanguagePlugin
279
+ };
280
+ } catch (error) {
281
+ debug$4("ts-macro language tools not found", error);
282
+ throw new Error("Failed to load ts-macro language tools. Please manually install @ts-macro/tsc.");
283
+ }
284
+ }
285
+ function createProgramFactory(ts$1, options) {
286
+ const vueLanguageTools = options.vue ? loadVueLanguageTools() : void 0;
287
+ const tsMacroLanguageTools = options.tsMacro ? loadTsMacro() : void 0;
288
+ const proxyCreateProgram = vueLanguageTools?.proxyCreateProgram || tsMacroLanguageTools?.proxyCreateProgram;
289
+ if (!proxyCreateProgram) return ts$1.createProgram;
290
+ return proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options$1) => {
291
+ const languagePlugins = [];
292
+ if (vueLanguageTools) languagePlugins.push(vueLanguageTools.getLanguagePlugin(ts$2, options$1));
293
+ if (tsMacroLanguageTools) languagePlugins.push(tsMacroLanguageTools.getLanguagePlugin(ts$2, options$1));
294
+ return { languagePlugins };
267
295
  });
268
296
  }
269
297
 
@@ -302,7 +330,7 @@ function createOrGetTsModule(options) {
302
330
  context.programs.push(module.program);
303
331
  return module;
304
332
  }
305
- function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, cwd, context = globalContext }) {
333
+ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, tsMacro, cwd, context = globalContext }) {
306
334
  const fsSystem = createFsSystem(context.files);
307
335
  const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
308
336
  const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
@@ -313,10 +341,11 @@ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, cwd, context
313
341
  baseDir,
314
342
  id,
315
343
  entries,
316
- vue
344
+ vue,
345
+ tsMacro
317
346
  });
318
347
  }
319
- function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue }) {
348
+ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue, tsMacro }) {
320
349
  const compilerOptions = {
321
350
  ...defaultCompilerOptions,
322
351
  ...parsedConfig.options,
@@ -325,7 +354,10 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
325
354
  };
326
355
  const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
327
356
  const host = ts.createCompilerHost(compilerOptions, true);
328
- const program = (vue ? createVueProgramFactory(ts) : ts.createProgram)({
357
+ const program = createProgramFactory(ts, {
358
+ vue,
359
+ tsMacro
360
+ })({
329
361
  rootNames,
330
362
  options: compilerOptions,
331
363
  host,
@@ -1,5 +1,5 @@
1
1
  import "./context-DXNtAHtR.js";
2
- import { tscEmit } from "./index-Cbz-60ZO.js";
2
+ import { tscEmit } from "./index-CxJisQQS.js";
3
3
 
4
4
  //#region src/tsc/worker.d.ts
5
5
  declare const functions: {
@@ -1,5 +1,5 @@
1
1
  import "./context-Digr9tkU.js";
2
- import { tscEmit } from "./tsc-q7n7-QbP.js";
2
+ import { tscEmit } from "./tsc-DLbQk3B6.js";
3
3
  import process from "node:process";
4
4
  import { createBirpc } from "birpc";
5
5
 
package/dist/tsc.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./context-DXNtAHtR.js";
2
- import { TscModule, TscOptions, TscResult, tscEmit } from "./index-Cbz-60ZO.js";
2
+ import { TscModule, TscOptions, TscResult, tscEmit } from "./index-CxJisQQS.js";
3
3
  export { TscModule, TscOptions, TscResult, tscEmit };
package/dist/tsc.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./context-Digr9tkU.js";
2
- import { tscEmit } from "./tsc-q7n7-QbP.js";
2
+ import { tscEmit } from "./tsc-DLbQk3B6.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.3",
3
+ "version": "0.16.4",
4
4
  "description": "A Rolldown plugin to generate and bundle dts files.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -40,12 +40,16 @@
40
40
  "access": "public"
41
41
  },
42
42
  "peerDependencies": {
43
+ "@ts-macro/tsc": "^0.3.6",
43
44
  "@typescript/native-preview": ">=7.0.0-dev.20250601.1",
44
45
  "rolldown": "^1.0.0-beta.9",
45
46
  "typescript": "^5.0.0",
46
47
  "vue-tsc": "~3.0.3"
47
48
  },
48
49
  "peerDependenciesMeta": {
50
+ "@ts-macro/tsc": {
51
+ "optional": true
52
+ },
49
53
  "@typescript/native-preview": {
50
54
  "optional": true
51
55
  },