rolldown-plugin-dts 0.21.1 → 0.21.3

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
@@ -8,7 +8,7 @@ A Rolldown plugin to generate and bundle dts files.
8
8
 
9
9
  ## Install
10
10
 
11
- Requires **`rolldown@1.0.0-beta.51`** or later.
11
+ Requires **`rolldown@1.0.0-beta.57`** or later.
12
12
 
13
13
  ```bash
14
14
  npm i -D rolldown-plugin-dts
package/dist/index.d.mts CHANGED
@@ -162,18 +162,36 @@ interface Options extends GeneralOptions, TscOptions {
162
162
  /**
163
163
  * **[Experimental]** Enables DTS generation using `tsgo`.
164
164
  *
165
- * To use this option, make sure `@typescript/native-preview` is installed as a dependency.
165
+ * To use this option, make sure `@typescript/native-preview` is installed as a dependency,
166
+ * or provide a custom path to the `tsgo` binary using the `path` option.
166
167
  *
167
168
  * **Note:** This option is not yet recommended for production environments.
168
169
  * `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
170
+ *
171
+ *
172
+ * ```ts
173
+ * // Use tsgo from `@typescript/native-preview` dependency
174
+ * tsgo: true
175
+ *
176
+ * // Use custom tsgo path (e.g., managed by Nix)
177
+ * tsgo: { path: '/path/to/tsgo' }
178
+ * ```
179
+ */
180
+ tsgo?: boolean | TsgoOptions;
181
+ }
182
+ interface TsgoOptions {
183
+ enabled?: boolean;
184
+ /**
185
+ * Custom path to the `tsgo` binary.
169
186
  */
170
- tsgo?: boolean;
187
+ path?: string;
171
188
  }
172
189
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
173
190
  type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
174
191
  tsconfig?: string;
175
192
  oxc: IsolatedDeclarationsOptions | false;
176
193
  tsconfigRaw: TsConfigJson;
194
+ tsgo: Omit<TsgoOptions, "enabled"> | false;
177
195
  }>;
178
196
  declare function resolveOptions({
179
197
  cwd,
package/dist/index.mjs CHANGED
@@ -1,14 +1,9 @@
1
- const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
2
1
  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
2
  import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-EuY-ImLj.mjs";
4
3
  import { createDebug } from "obug";
5
- const {
6
- generate
7
- } = __cjs_require("@babel/generator");
8
- const {
9
- parse
10
- } = __cjs_require("@babel/parser");
11
- const t = __cjs_require("@babel/types");
4
+ import { generate } from "@babel/generator";
5
+ import { parse } from "@babel/parser";
6
+ import * as t from "@babel/types";
12
7
  import { isDeclarationType, isIdentifierOf, isTypeOf, resolveString, walkAST } from "ast-kit";
13
8
  const {
14
9
  fork,
@@ -69,9 +64,9 @@ function createDtsInputPlugin({ sideEffects }) {
69
64
  //#endregion
70
65
  //#region src/fake-js.ts
71
66
  function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
72
- let symbolIdx = 0;
67
+ let declarationIdx = 0;
73
68
  const identifierMap = Object.create(null);
74
- const symbolMap = /* @__PURE__ */ new Map();
69
+ const declarationMap = /* @__PURE__ */ new Map();
75
70
  const commentsMap = /* @__PURE__ */ new Map();
76
71
  const typeOnlyMap = /* @__PURE__ */ new Map();
77
72
  return {
@@ -131,9 +126,9 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
131
126
  const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
132
127
  if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
133
128
  const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
134
- const isDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && stmt.declaration;
135
- const decl = isDecl ? stmt.declaration : stmt;
136
- const setDecl = isDecl ? (decl$1) => stmt.declaration = decl$1 : setStmt;
129
+ const isExportDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && !!stmt.declaration;
130
+ const decl = isExportDecl ? stmt.declaration : stmt;
131
+ const setDecl = isExportDecl ? (decl$1) => stmt.declaration = decl$1 : setStmt;
137
132
  if (decl.type !== "TSDeclareFunction" && !isDeclarationType(decl)) continue;
138
133
  if (isTypeOf(decl, [
139
134
  "TSEnumDeclaration",
@@ -155,22 +150,33 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
155
150
  decl.id = binding;
156
151
  }
157
152
  const params = collectParams(decl);
158
- const deps = collectDependencies(decl, namespaceStmts);
153
+ const childrenSet = /* @__PURE__ */ new Set();
154
+ const deps = collectDependencies(decl, namespaceStmts, childrenSet);
155
+ const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
159
156
  if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
160
- const symbolId = registerSymbol({
157
+ const declarationId = registerDeclaration({
161
158
  decl,
162
159
  deps,
163
160
  bindings,
164
- params
161
+ params,
162
+ children
165
163
  });
166
- const symbolIdNode = t.numericLiteral(symbolId);
164
+ const declarationIdNode = t.numericLiteral(declarationId);
167
165
  const depsNode = t.arrowFunctionExpression(params.map(({ name }) => t.identifier(name)), t.arrayExpression(deps));
166
+ const childrenNode = t.arrayExpression(children.map((node) => ({
167
+ type: "StringLiteral",
168
+ value: "",
169
+ start: node.start,
170
+ end: node.end,
171
+ loc: node.loc
172
+ })));
168
173
  const sideEffectNode = sideEffect && t.callExpression(t.identifier("sideEffect"), [bindings[0]]);
169
- const runtimeArrayNode = runtimeBindingArrayExpression(sideEffectNode ? [
170
- symbolIdNode,
174
+ const runtimeArrayNode = runtimeBindingArrayExpression([
175
+ declarationIdNode,
171
176
  depsNode,
172
- sideEffectNode
173
- ] : [symbolIdNode, depsNode]);
177
+ childrenNode,
178
+ ...sideEffectNode ? [sideEffectNode] : []
179
+ ]);
174
180
  const runtimeAssignment = {
175
181
  type: "VariableDeclaration",
176
182
  kind: "var",
@@ -201,11 +207,15 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
201
207
  ...appendStmts
202
208
  ];
203
209
  typeOnlyMap.set(id, typeOnlyIds);
204
- return generate(file, {
210
+ const result = generate(file, {
205
211
  comments: false,
206
212
  sourceMaps: sourcemap,
207
213
  sourceFileName: id
208
214
  });
215
+ return {
216
+ code: result.code,
217
+ map: result.map
218
+ };
209
219
  }
210
220
  function renderChunk(code, chunk) {
211
221
  if (!RE_DTS.test(chunk.fileName)) return;
@@ -225,31 +235,29 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
225
235
  if (newNode || newNode === false) return newNode;
226
236
  if (node.type !== "VariableDeclaration") return node;
227
237
  if (!isRuntimeBindingVariableDeclaration(node)) return null;
228
- const [symbolIdNode, depsFn] = node.declarations[0].init.elements;
229
- const symbolId = symbolIdNode.value;
230
- const original = getSymbol(symbolId);
231
- walkAST(original.decl, { enter(node$1) {
238
+ const [declarationIdNode, depsFn, children] = node.declarations[0].init.elements;
239
+ const declarationId = declarationIdNode.value;
240
+ const declaration = getDeclaration(declarationId);
241
+ walkAST(declaration.decl, { enter(node$1) {
232
242
  delete node$1.loc;
233
243
  } });
234
244
  for (const [i, decl] of node.declarations.entries()) {
235
245
  const transformedBinding = {
236
246
  ...decl.id,
237
- typeAnnotation: original.bindings[i].typeAnnotation
247
+ typeAnnotation: declaration.bindings[i].typeAnnotation
238
248
  };
239
- overwriteNode(original.bindings[i], transformedBinding);
249
+ overwriteNode(declaration.bindings[i], transformedBinding);
240
250
  }
251
+ for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], { loc: child.loc });
241
252
  const transformedParams = depsFn.params;
242
253
  for (const [i, transformedParam] of transformedParams.entries()) {
243
254
  const transformedName = transformedParam.name;
244
- for (const originalTypeParam of original.params[i].typeParams) originalTypeParam.name = transformedName;
255
+ for (const originalTypeParam of declaration.params[i].typeParams) originalTypeParam.name = transformedName;
245
256
  }
246
257
  const transformedDeps = depsFn.body.elements;
247
- for (let i = 0; i < original.deps.length; i++) {
248
- const originalDep = original.deps[i];
249
- if (originalDep.replace) originalDep.replace(transformedDeps[i]);
250
- else Object.assign(originalDep, transformedDeps[i]);
251
- }
252
- return inheritNodeComments(node, original.decl);
258
+ for (const [i, originalDep] of declaration.deps.entries()) if (originalDep.replace) originalDep.replace(transformedDeps[i]);
259
+ else Object.assign(originalDep, transformedDeps[i]);
260
+ return inheritNodeComments(node, declaration.decl);
253
261
  }).filter((node) => !!node);
254
262
  if (program.body.length === 0) return "export { };";
255
263
  const comments = /* @__PURE__ */ new Set();
@@ -270,23 +278,27 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
270
278
  program.body[0].leadingComments ||= [];
271
279
  program.body[0].leadingComments.unshift(...comments);
272
280
  }
273
- return generate(file, {
281
+ const result = generate(file, {
274
282
  comments: true,
275
283
  sourceMaps: sourcemap,
276
284
  sourceFileName: chunk.fileName
277
285
  });
286
+ return {
287
+ code: result.code,
288
+ map: result.map
289
+ };
278
290
  }
279
291
  function getIdentifierIndex(name) {
280
292
  if (name in identifierMap) return identifierMap[name]++;
281
293
  return identifierMap[name] = 0;
282
294
  }
283
- function registerSymbol(info) {
284
- const symbolId = symbolIdx++;
285
- symbolMap.set(symbolId, info);
286
- return symbolId;
295
+ function registerDeclaration(info) {
296
+ const declarationId = declarationIdx++;
297
+ declarationMap.set(declarationId, info);
298
+ return declarationId;
287
299
  }
288
- function getSymbol(symbolId) {
289
- return symbolMap.get(symbolId);
300
+ function getDeclaration(declarationId) {
301
+ return declarationMap.get(declarationId);
290
302
  }
291
303
  /**
292
304
  * Collects all TSTypeParameter nodes from the given node and groups them by
@@ -297,7 +309,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
297
309
  function collectParams(node) {
298
310
  const typeParams = [];
299
311
  walkAST(node, { leave(node$1) {
300
- if ("typeParameters" in node$1 && node$1.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node$1.typeParameters.params);
312
+ if ("typeParameters" in node$1 && node$1.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node$1.typeParameters.params.map((param) => param.name));
301
313
  } });
302
314
  const paramMap = /* @__PURE__ */ new Map();
303
315
  for (const typeParam of typeParams) {
@@ -311,7 +323,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
311
323
  typeParams: typeParams$1
312
324
  }));
313
325
  }
314
- function collectDependencies(node, namespaceStmts) {
326
+ function collectDependencies(node, namespaceStmts, children) {
315
327
  const deps = /* @__PURE__ */ new Set();
316
328
  const seen = /* @__PURE__ */ new Set();
317
329
  const inferredStack = [];
@@ -334,10 +346,13 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
334
346
  } else currentInferred = /* @__PURE__ */ new Set();
335
347
  if (node$1.type === "ExportNamedDeclaration") {
336
348
  for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
337
- } else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(TSEntityNameToRuntime(heritage.expression));
349
+ } else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(heritage.expression);
338
350
  else if (node$1.type === "ClassDeclaration") {
339
351
  if (node$1.superClass) addDependency(node$1.superClass);
340
- if (node$1.implements) for (const implement of node$1.implements) addDependency(TSEntityNameToRuntime(implement.expression));
352
+ if (node$1.implements) for (const implement of node$1.implements) {
353
+ if (implement.type === "ClassImplements") throw new Error("Unexpected Flow syntax");
354
+ addDependency(implement.expression);
355
+ }
341
356
  } else if (isTypeOf(node$1, [
342
357
  "ObjectMethod",
343
358
  "ObjectProperty",
@@ -358,12 +373,12 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
358
373
  break;
359
374
  case "TSImportType": {
360
375
  seen.add(node$1);
361
- const source = node$1.argument;
362
- const imported = node$1.qualifier;
363
- addDependency(importNamespace(node$1, imported, source, namespaceStmts));
376
+ const { source, qualifier } = node$1;
377
+ addDependency(importNamespace(node$1, qualifier, source, namespaceStmts));
364
378
  break;
365
379
  }
366
380
  }
381
+ if (parent && !deps.has(node$1) && isChildSymbol(node$1, parent)) children.add(node$1);
367
382
  }
368
383
  });
369
384
  return Array.from(deps);
@@ -382,12 +397,13 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
382
397
  });
383
398
  if (imported) {
384
399
  const importedLeft = getIdFromTSEntityName(imported);
400
+ if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
385
401
  overwriteNode(importedLeft, t.tsQualifiedName(local, { ...importedLeft }));
386
402
  local = imported;
387
403
  }
388
404
  let replacement = node;
389
- if (node.typeParameters) {
390
- overwriteNode(node, t.tsTypeReference(local, node.typeParameters));
405
+ if (node.typeArguments) {
406
+ overwriteNode(node, t.tsTypeReference(local, node.typeArguments));
391
407
  replacement = local;
392
408
  } else overwriteNode(node, local);
393
409
  return {
@@ -398,10 +414,15 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
398
414
  };
399
415
  }
400
416
  }
417
+ function isChildSymbol(node, parent) {
418
+ if (node.type === "Identifier") return true;
419
+ if (isTypeOf(parent, ["TSPropertySignature", "TSMethodSignature"]) && parent.key === node) return true;
420
+ return false;
421
+ }
401
422
  function collectInferredNames(node) {
402
423
  const inferred = [];
403
424
  walkAST(node, { enter(node$1) {
404
- if (node$1.type === "TSInferType" && node$1.typeParameter) inferred.push(node$1.typeParameter.name);
425
+ if (node$1.type === "TSInferType" && node$1.typeParameter) inferred.push(node$1.typeParameter.name.name);
405
426
  } });
406
427
  return inferred;
407
428
  }
@@ -413,34 +434,34 @@ function collectReferenceDirectives(comment, negative = false) {
413
434
  * Check if the given node is a {@link RuntimeBindingVariableDeclration}
414
435
  */
415
436
  function isRuntimeBindingVariableDeclaration(node) {
416
- return t.isVariableDeclaration(node) && node.declarations.length > 0 && t.isVariableDeclarator(node.declarations[0]) && isRuntimeBindingArrayExpression(node.declarations[0].init);
437
+ return node?.type === "VariableDeclaration" && node.declarations.length > 0 && node.declarations[0].type === "VariableDeclarator" && isRuntimeBindingArrayExpression(node.declarations[0].init);
417
438
  }
418
439
  /**
419
440
  * Check if the given node is a {@link RuntimeBindingArrayExpression}
420
441
  */
421
442
  function isRuntimeBindingArrayExpression(node) {
422
- return t.isArrayExpression(node) && isRuntimeBindingArrayElements(node.elements);
423
- }
424
- function runtimeBindingArrayExpression(elements) {
425
- return t.arrayExpression(elements);
443
+ return node?.type === "ArrayExpression" && isRuntimeBindingArrayElements(node.elements);
426
444
  }
427
445
  /**
428
446
  * Check if the given array is a {@link RuntimeBindingArrayElements}
429
447
  */
430
448
  function isRuntimeBindingArrayElements(elements) {
431
- const [symbolId, deps, effect] = elements;
432
- return t.isNumericLiteral(symbolId) && t.isArrowFunctionExpression(deps) && (!effect || t.isCallExpression(effect));
449
+ const [declarationId, deps, children, effect] = elements;
450
+ return declarationId?.type === "NumericLiteral" && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
451
+ }
452
+ function runtimeBindingArrayExpression(elements) {
453
+ return t.arrayExpression(elements);
433
454
  }
434
455
  function isThisExpression(node) {
435
- return isIdentifierOf(node, "this") || node.type === "MemberExpression" && isThisExpression(node.object);
456
+ return isIdentifierOf(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
436
457
  }
437
458
  function TSEntityNameToRuntime(node) {
438
- if (node.type === "Identifier") return node;
459
+ if (node.type === "Identifier" || node.type === "ThisExpression") return node;
439
460
  const left = TSEntityNameToRuntime(node.left);
440
461
  return Object.assign(node, t.memberExpression(left, node.right));
441
462
  }
442
463
  function getIdFromTSEntityName(node) {
443
- if (node.type === "Identifier") return node;
464
+ if (node.type === "Identifier" || node.type === "ThisExpression") return node;
444
465
  return getIdFromTSEntityName(node.left);
445
466
  }
446
467
  function isReferenceId(node) {
@@ -612,11 +633,21 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
612
633
  child.on("close", () => resolve());
613
634
  child.on("error", (error) => reject(error));
614
635
  });
615
- async function runTsgo(rootDir, tsconfig, sourcemap) {
616
- debug$3("[tsgo] rootDir", rootDir);
636
+ async function getTsgoPathFromNodeModules() {
617
637
  const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
618
638
  const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
619
- const tsgo = getExePath();
639
+ return getExePath();
640
+ }
641
+ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
642
+ debug$3("[tsgo] rootDir", rootDir);
643
+ let tsgo;
644
+ if (tsgoPath) {
645
+ tsgo = tsgoPath;
646
+ debug$3("[tsgo] using custom path", tsgo);
647
+ } else {
648
+ tsgo = await getTsgoPathFromNodeModules();
649
+ debug$3("[tsgo] using tsgo from node_modules", tsgo);
650
+ }
620
651
  const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
621
652
  debug$3("[tsgo] tsgoDist", tsgoDist);
622
653
  const args = [
@@ -662,7 +693,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
662
693
  return {
663
694
  name: "rolldown-plugin-dts:generate",
664
695
  async buildStart(options) {
665
- if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig, sourcemap);
696
+ if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig, sourcemap, tsgo.path);
666
697
  else if (!oxc) if (parallel) {
667
698
  childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
668
699
  rpc = (await import("birpc")).createBirpc({}, {
@@ -800,7 +831,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
800
831
  dtsCode = result.code;
801
832
  map = result.map;
802
833
  if (dtsCode && RE_JSON.test(id)) if (dtsCode.includes("declare const _exports")) {
803
- if (dtsCode.includes("declare const _exports: {")) {
834
+ if (dtsCode.includes("declare const _exports: {") && !dtsCode.includes("\n}[];")) {
804
835
  const exports = collectJsonExports(dtsCode);
805
836
  let i = 0;
806
837
  dtsCode += exports.map((e) => {
@@ -876,6 +907,8 @@ function collectJsonExports(code) {
876
907
  //#region src/options.ts
877
908
  let warnedTsgo = false;
878
909
  function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
910
+ if (tsgo === true) tsgo = {};
911
+ else if (typeof tsgo === "object" && tsgo.enabled === false) tsgo = false;
879
912
  let resolvedTsconfig;
880
913
  if (tsconfig === true || tsconfig == null) {
881
914
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -16,7 +16,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
16
16
 
17
17
  //#endregion
18
18
  //#region src/tsc/system.ts
19
- const debug$3 = createDebug("rolldown-plugin-dts:tsc-system");
19
+ const debug$4 = createDebug("rolldown-plugin-dts:tsc-system");
20
20
  /**
21
21
  * A system that writes files to both memory and disk. It will try read files
22
22
  * from memory firstly and fallback to disk if not found.
@@ -25,7 +25,7 @@ function createFsSystem(files) {
25
25
  return {
26
26
  ...ts.sys,
27
27
  write(message) {
28
- debug$3(message);
28
+ debug$4(message);
29
29
  },
30
30
  resolvePath(path$1) {
31
31
  if (files.has(path$1)) return path$1;
@@ -90,20 +90,20 @@ function setSourceMapRoot(map, originalFilePath, finalFilePath) {
90
90
 
91
91
  //#endregion
92
92
  //#region src/tsc/emit-build.ts
93
- const debug$2 = createDebug("rolldown-plugin-dts:tsc-build");
93
+ const debug$3 = createDebug("rolldown-plugin-dts:tsc-build");
94
94
  function tscEmitBuild(tscOptions) {
95
95
  const { id, tsconfig, incremental, context = globalContext, sourcemap } = tscOptions;
96
- debug$2(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
96
+ debug$3(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
97
97
  if (!tsconfig) return { error: "[rolldown-plugin-dts] build mode requires a tsconfig path" };
98
98
  const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
99
99
  const resolvedId = fsSystem.resolvePath(id);
100
- if (resolvedId !== id) debug$2(`resolved id from ${id} to ${resolvedId}`);
100
+ if (resolvedId !== id) debug$3(`resolved id from ${id} to ${resolvedId}`);
101
101
  const project = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap).get(resolvedId);
102
102
  if (!project) {
103
- debug$2(`unable to locate a project containing ${resolvedId}`);
103
+ debug$3(`unable to locate a project containing ${resolvedId}`);
104
104
  return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
105
105
  }
106
- debug$2(`loaded project ${project.tsconfigPath} for ${id}`);
106
+ debug$3(`loaded project ${project.tsconfigPath} for ${id}`);
107
107
  const ignoreCase = !fsSystem.useCaseSensitiveFileNames;
108
108
  const outputFiles = ts.getOutputFileNames(project.parsedConfig, resolvedId, ignoreCase);
109
109
  let code;
@@ -133,20 +133,20 @@ function tscEmitBuild(tscOptions) {
133
133
  map
134
134
  };
135
135
  if (incremental) {
136
- debug$2(`incremental build failed`);
136
+ debug$3(`incremental build failed`);
137
137
  return tscEmitBuild({
138
138
  ...tscOptions,
139
139
  incremental: false
140
140
  });
141
141
  }
142
- debug$2(`unable to build .d.ts file for ${id}`);
142
+ debug$3(`unable to build .d.ts file for ${id}`);
143
143
  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}` };
144
144
  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` };
145
145
  }
146
146
  function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
147
147
  let projectMap = context.projects.get(tsconfig);
148
148
  if (projectMap) {
149
- debug$2(`skip building projects for ${tsconfig}`);
149
+ debug$3(`skip building projects for ${tsconfig}`);
150
150
  return projectMap;
151
151
  }
152
152
  projectMap = buildProjects(fsSystem, tsconfig, force, sourcemap);
@@ -157,15 +157,15 @@ function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
157
157
  * Use TypeScript compiler to build all projects referenced
158
158
  */
159
159
  function buildProjects(fsSystem, tsconfig, force, sourcemap) {
160
- debug$2(`start building projects for ${tsconfig}`);
160
+ debug$3(`start building projects for ${tsconfig}`);
161
161
  const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
162
- debug$2("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
162
+ debug$3("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
163
163
  const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
164
- debug$2(`built solution for ${tsconfig} with exit status ${ts.createSolutionBuilder(host, [tsconfig], {
164
+ debug$3(`built solution for ${tsconfig} with exit status ${ts.createSolutionBuilder(host, [tsconfig], {
165
165
  force,
166
166
  verbose: true
167
167
  }).build(void 0, void 0, void 0, (project) => {
168
- debug$2(`transforming project ${project}`);
168
+ debug$3(`transforming project ${project}`);
169
169
  return customTransformers;
170
170
  })}`);
171
171
  const sourceFileToProjectMap = /* @__PURE__ */ new Map();
@@ -244,33 +244,38 @@ const createProgramWithPatchedCompilerOptions = (rootNames, options, ...args) =>
244
244
 
245
245
  //#endregion
246
246
  //#region src/tsc/volar.ts
247
+ const debug$2 = createDebug("rolldown-plugin-dts:volar");
247
248
  function loadVueLanguageTools() {
248
- const debug$4 = createDebug("rolldown-plugin-dts:vue");
249
- debug$4("loading vue language tools");
249
+ debug$2("loading vue language tools");
250
250
  try {
251
251
  const vueTscPath = __require.resolve("vue-tsc");
252
- const { proxyCreateProgram } = __require(__require.resolve("@volar/typescript", { paths: [vueTscPath] }));
253
- const vue = __require(__require.resolve("@vue/language-core", { paths: [vueTscPath] }));
254
- const getLanguagePlugin = (ts$1, options) => {
255
- const $rootDir = options.options.$rootDir;
256
- const $configRaw = options.options.$configRaw;
257
- const resolver = new vue.CompilerOptionsResolver(ts$1, ts$1.sys.readFile);
258
- resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
259
- const vueOptions = resolver.build();
260
- return vue.createVueLanguagePlugin(ts$1, options.options, vueOptions, (id) => id);
261
- };
262
252
  return {
263
- proxyCreateProgram,
264
- getLanguagePlugin
253
+ volarTs: __require(__require.resolve("@volar/typescript", { paths: [vueTscPath] })),
254
+ vue: __require(__require.resolve("@vue/language-core", { paths: [vueTscPath] }))
265
255
  };
266
256
  } catch (error) {
267
- debug$4("vue language tools not found", error);
257
+ debug$2("vue language tools not found", error);
268
258
  throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
269
259
  }
270
260
  }
271
- function loadTsMacro() {
272
- const debug$4 = createDebug("rolldown-plugin-dts:ts-macro");
273
- debug$4("loading ts-macro language tools");
261
+ function initVueLanguageTools() {
262
+ const { vue, volarTs: { proxyCreateProgram } } = loadVueLanguageTools();
263
+ const getLanguagePlugin = (ts$1, options) => {
264
+ const $rootDir = options.options.$rootDir;
265
+ const $configRaw = options.options.$configRaw;
266
+ const resolver = new vue.CompilerOptionsResolver(ts$1, ts$1.sys.readFile);
267
+ resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
268
+ const vueOptions = resolver.build();
269
+ return vue.createVueLanguagePlugin(ts$1, options.options, vueOptions, (id) => id);
270
+ };
271
+ return {
272
+ proxyCreateProgram,
273
+ getLanguagePlugin
274
+ };
275
+ }
276
+ function initTsMacro() {
277
+ const debug$5 = createDebug("rolldown-plugin-dts:ts-macro");
278
+ debug$5("loading ts-macro language tools");
274
279
  try {
275
280
  const tsMacroPath = __require.resolve("@ts-macro/tsc");
276
281
  const { proxyCreateProgram } = __require(__require.resolve("@volar/typescript", { paths: [tsMacroPath] }));
@@ -285,13 +290,13 @@ function loadTsMacro() {
285
290
  getLanguagePlugin
286
291
  };
287
292
  } catch (error) {
288
- debug$4("ts-macro language tools not found", error);
293
+ debug$5("ts-macro language tools not found", error);
289
294
  throw new Error("Failed to load ts-macro language tools. Please manually install @ts-macro/tsc.");
290
295
  }
291
296
  }
292
297
  function createProgramFactory(ts$1, options) {
293
- const vueLanguageTools = options.vue ? loadVueLanguageTools() : void 0;
294
- const tsMacroLanguageTools = options.tsMacro ? loadTsMacro() : void 0;
298
+ const vueLanguageTools = options.vue ? initVueLanguageTools() : void 0;
299
+ const tsMacroLanguageTools = options.tsMacro ? initTsMacro() : void 0;
295
300
  const proxyCreateProgram = vueLanguageTools?.proxyCreateProgram || tsMacroLanguageTools?.proxyCreateProgram;
296
301
  if (!proxyCreateProgram) return ts$1.createProgram;
297
302
  return proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options$1) => {
@@ -340,7 +345,11 @@ function createOrGetTsModule(options) {
340
345
  function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, tsMacro, cwd, context = globalContext }) {
341
346
  const fsSystem = createFsSystem(context.files);
342
347
  const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
343
- const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
348
+ const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir, void 0, void 0, void 0, vue ? [{
349
+ extension: "vue",
350
+ isMixedContent: true,
351
+ scriptKind: ts.ScriptKind.Deferred
352
+ }] : void 0);
344
353
  debug$1(`creating program for root project: ${baseDir}`);
345
354
  return createTsProgramFromParsedConfig({
346
355
  parsedConfig,
@@ -1,4 +1,4 @@
1
- import { t as tscEmit } from "./tsc-C0UrtIA5.mjs";
1
+ import { t as tscEmit } from "./tsc-DmkHlcNe.mjs";
2
2
  const process = globalThis.process;
3
3
  import { createBirpc } from "birpc";
4
4
 
package/dist/tsc.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as tscEmit } from "./tsc-C0UrtIA5.mjs";
1
+ import { t as tscEmit } from "./tsc-DmkHlcNe.mjs";
2
2
 
3
3
  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.21.1",
4
+ "version": "0.21.3",
5
5
  "description": "A Rolldown plugin to generate and bundle dts files.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -62,35 +62,35 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@babel/generator": "^7.28.6",
66
- "@babel/parser": "^7.28.6",
67
- "@babel/types": "^7.28.6",
68
- "ast-kit": "^2.2.0",
65
+ "@babel/generator": "8.0.0-beta.4",
66
+ "@babel/parser": "8.0.0-beta.4",
67
+ "@babel/types": "8.0.0-beta.4",
68
+ "ast-kit": "^3.0.0-beta.1",
69
69
  "birpc": "^4.0.0",
70
70
  "dts-resolver": "^2.1.3",
71
71
  "get-tsconfig": "^4.13.0",
72
72
  "obug": "^2.1.1"
73
73
  },
74
74
  "devDependencies": {
75
+ "@jridgewell/source-map": "^0.3.11",
75
76
  "@sxzz/eslint-config": "^7.4.5",
76
77
  "@sxzz/prettier-config": "^2.2.6",
77
78
  "@sxzz/test-utils": "^0.5.15",
78
- "@types/babel__generator": "^7.27.0",
79
- "@types/node": "^25.0.8",
80
- "@typescript/native-preview": "7.0.0-dev.20260114.1",
79
+ "@types/node": "^25.0.9",
80
+ "@typescript/native-preview": "7.0.0-dev.20260118.1",
81
81
  "@volar/typescript": "^2.4.27",
82
82
  "@vue/language-core": "^3.2.2",
83
83
  "arktype": "^2.1.29",
84
84
  "bumpp": "^10.4.0",
85
85
  "diff": "^8.0.3",
86
86
  "eslint": "^9.39.2",
87
- "prettier": "^3.7.4",
87
+ "prettier": "^3.8.0",
88
88
  "rolldown": "^1.0.0-beta.60",
89
89
  "rolldown-plugin-dts-snapshot": "^0.3.2",
90
90
  "rolldown-plugin-require-cjs": "^0.3.3",
91
91
  "rollup-plugin-dts": "^6.3.0",
92
92
  "tinyglobby": "^0.2.15",
93
- "tsdown": "^0.20.0-beta.2",
93
+ "tsdown": "^0.20.0-beta.3",
94
94
  "typescript": "^5.9.3",
95
95
  "vitest": "^4.0.17",
96
96
  "vue": "^3.5.26",