rolldown-plugin-dts 0.13.13 → 0.13.14

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.d.ts CHANGED
@@ -158,4 +158,4 @@ declare function createGeneratePlugin({
158
158
  //#region src/index.d.ts
159
159
  declare function dts(options?: Options): Plugin[];
160
160
  //#endregion
161
- export { Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
161
+ export { type Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import Debug from "debug";
4
4
  import _generate from "@babel/generator";
5
5
  import { parse } from "@babel/parser";
6
6
  import * as t from "@babel/types";
7
- import { isDeclarationType, isTypeOf } from "ast-kit";
7
+ import { isDeclarationType, isTypeOf, resolveString } from "ast-kit";
8
8
  import { fork, spawn } from "node:child_process";
9
9
  import { existsSync } from "node:fs";
10
10
  import { mkdtemp, readFile, rm } from "node:fs/promises";
@@ -232,9 +232,10 @@ function walk(ast, { enter, leave }) {
232
232
  const generate = _generate.default || _generate;
233
233
  function createFakeJsPlugin({ dtsInput, sourcemap }) {
234
234
  let symbolIdx = 0;
235
- let identifierIdx = 0;
235
+ const identifierMap = Object.create(null);
236
236
  const symbolMap = /* @__PURE__ */ new Map();
237
237
  const commentsMap = /* @__PURE__ */ new Map();
238
+ const typeOnlyMap = /* @__PURE__ */ new Map();
238
239
  return {
239
240
  name: "rolldown-plugin-dts:fake-js",
240
241
  outputOptions(options) {
@@ -268,6 +269,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
268
269
  sourceType: "module"
269
270
  });
270
271
  const { program, comments } = file;
272
+ const typeOnlyIds = [];
271
273
  if (comments) {
272
274
  const directives = collectReferenceDirectives(comments);
273
275
  commentsMap.set(id, directives);
@@ -276,7 +278,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
276
278
  const namespaceStmts = /* @__PURE__ */ new Map();
277
279
  for (const [i, stmt] of program.body.entries()) {
278
280
  const setStmt = (node) => program.body[i] = node;
279
- if (rewriteImportExport(stmt, setStmt)) continue;
281
+ if (rewriteImportExport(stmt, setStmt, typeOnlyIds)) continue;
280
282
  const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
281
283
  if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
282
284
  const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
@@ -296,7 +298,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
296
298
  if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl$1) => decl$1.id));
297
299
  else if ("id" in decl && decl.id) {
298
300
  let binding = decl.id;
299
- binding = sideEffect ? t.identifier(`_${identifierIdx++}`) : binding;
301
+ binding = sideEffect ? t.identifier(`_${getIdentifierIndex("")}`) : binding;
300
302
  bindings.push(binding);
301
303
  } else {
302
304
  const binding = t.identifier("export_default");
@@ -349,6 +351,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
349
351
  ...program.body,
350
352
  ...appendStmts
351
353
  ];
354
+ typeOnlyMap.set(id, typeOnlyIds);
352
355
  const result = generate(file, {
353
356
  comments: false,
354
357
  sourceMaps: sourcemap,
@@ -358,12 +361,17 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
358
361
  }
359
362
  function renderChunk(code, chunk) {
360
363
  if (!RE_DTS.test(chunk.fileName)) return;
364
+ const typeOnlyIds = [];
365
+ for (const module of chunk.moduleIds) {
366
+ const ids = typeOnlyMap.get(module);
367
+ if (ids) typeOnlyIds.push(...ids);
368
+ }
361
369
  const file = parse(code, { sourceType: "module" });
362
370
  const { program } = file;
363
371
  program.body = patchTsNamespace(program.body);
364
372
  program.body = program.body.map((node) => {
365
373
  if (isHelperImport(node)) return null;
366
- if (patchImportSource(node)) return node;
374
+ if (patchImportExport(node, typeOnlyIds)) return node;
367
375
  if (node.type !== "VariableDeclaration") return node;
368
376
  const [decl] = node.declarations;
369
377
  if (decl.init?.type !== "ArrayExpression" || !decl.init.elements[0]) return null;
@@ -412,8 +420,9 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
412
420
  });
413
421
  return result;
414
422
  }
415
- function getIdentifierIndex() {
416
- return identifierIdx++;
423
+ function getIdentifierIndex(name) {
424
+ if (name in identifierMap) return identifierMap[name]++;
425
+ return identifierMap[name] = 0;
417
426
  }
418
427
  function registerSymbol(info) {
419
428
  const symbolId = symbolIdx++;
@@ -462,7 +471,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
462
471
  }
463
472
  function importNamespace(node, imported, source, namespaceStmts) {
464
473
  const sourceText = source.value.replaceAll(/\W/g, "_");
465
- let local = t.identifier(`${sourceText}${getIdentifierIndex()}`);
474
+ let local = t.identifier(`${sourceText}${getIdentifierIndex(sourceText)}`);
466
475
  if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
467
476
  else namespaceStmts.set(source.value, {
468
477
  stmt: t.importDeclaration([t.importNamespaceSpecifier(local)], source),
@@ -506,14 +515,21 @@ function isReferenceId(node) {
506
515
  function isHelperImport(node) {
507
516
  return node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__export", "__reExport"].includes(spec.imported.name));
508
517
  }
509
- function patchImportSource(node) {
518
+ function patchImportExport(node, typeOnlyIds) {
510
519
  if (isTypeOf(node, [
511
520
  "ImportDeclaration",
512
521
  "ExportAllDeclaration",
513
522
  "ExportNamedDeclaration"
514
- ]) && node.source?.value && RE_DTS.test(node.source.value)) {
515
- node.source.value = filename_dts_to(node.source.value, "js");
516
- return true;
523
+ ])) {
524
+ if (typeOnlyIds.length && node.type === "ExportNamedDeclaration") for (const spec of node.specifiers) {
525
+ const name = resolveString(spec.exported);
526
+ if (typeOnlyIds.includes(name)) if (spec.type === "ExportSpecifier") spec.exportKind = "type";
527
+ else node.exportKind = "type";
528
+ }
529
+ if (node.source?.value && RE_DTS.test(node.source.value)) {
530
+ node.source.value = filename_dts_to(node.source.value, "js");
531
+ return true;
532
+ }
517
533
  }
518
534
  }
519
535
  function patchTsNamespace(nodes) {
@@ -552,10 +568,13 @@ function patchTsNamespace(nodes) {
552
568
  }
553
569
  return nodes.filter((node) => !removed.has(node));
554
570
  }
555
- function rewriteImportExport(node, set) {
571
+ function rewriteImportExport(node, set, typeOnlyIds) {
556
572
  if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" && !node.declaration) {
557
- for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier") specifier.importKind = "value";
558
- else if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
573
+ for (const specifier of node.specifiers) {
574
+ if ("exportKind" in specifier && specifier.exportKind === "type" || "exportKind" in node && node.exportKind === "type") typeOnlyIds.push(resolveString(specifier.exported));
575
+ if (specifier.type === "ImportSpecifier") specifier.importKind = "value";
576
+ else if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
577
+ }
559
578
  if (node.type === "ImportDeclaration") node.importKind = "value";
560
579
  else if (node.type === "ExportNamedDeclaration") node.exportKind = "value";
561
580
  return true;
@@ -649,7 +668,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
649
668
  async buildStart(options) {
650
669
  if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
651
670
  else if (!parallel && (!isolatedDeclarations || vue)) {
652
- tscModule = await import("./tsc-CJ55BCXi.js");
671
+ tscModule = await import("./tsc-qM2loyiG.js");
653
672
  tscContext = eager ? void 0 : tscModule.createContext();
654
673
  }
655
674
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
@@ -1,4 +1,4 @@
1
- import { tscEmit } from "../tsc-AS4dxecO.js";
1
+ import { tscEmit } from "../tsc-DkRb5DrU.js";
2
2
  import { createBirpc } from "birpc";
3
3
  import process from "node:process";
4
4
 
@@ -77,8 +77,11 @@ function createVueProgramFactory(ts$1) {
77
77
  debug$1("loading vue language tools");
78
78
  const { proxyCreateProgram, vue } = loadVueLanguageTools();
79
79
  return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
80
- const { configFilePath } = options.options;
81
- const vueOptions = typeof configFilePath === "string" ? vue.createParsedCommandLine(ts$2, ts$2.sys, configFilePath.replaceAll("\\", "/")).vueOptions : vue.getDefaultCompilerOptions();
80
+ const $rootDir = options.options.$rootDir;
81
+ const $configRaw = options.options.$configRaw;
82
+ const resolver = new vue.CompilerOptionsResolver();
83
+ resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
84
+ const vueOptions = resolver.build();
82
85
  const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
83
86
  return { languagePlugins: [vueLanguagePlugin] };
84
87
  });
@@ -151,18 +154,73 @@ function buildSolution(tsconfig, incremental, context) {
151
154
  force: !incremental,
152
155
  verbose: true
153
156
  });
154
- const exitStatus = builder.build();
157
+ const projects = [];
158
+ const getCustomTransformers = (project) => {
159
+ projects.push(project);
160
+ return {};
161
+ };
162
+ const exitStatus = builder.build(void 0, void 0, void 0, getCustomTransformers);
155
163
  debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
164
+ return Array.from(new Set(projects));
165
+ }
166
+ function findProjectContainingFile(projects, targetFile, fsSystem) {
167
+ const resolvedTargetFile = fsSystem.resolvePath(targetFile);
168
+ for (const tsconfigPath of projects) {
169
+ const parsedConfig = parseTsconfig(tsconfigPath, fsSystem);
170
+ if (parsedConfig && parsedConfig.fileNames.some((fileName) => fsSystem.resolvePath(fileName) === resolvedTargetFile)) return {
171
+ parsedConfig,
172
+ tsconfigPath
173
+ };
174
+ }
175
+ }
176
+ function parseTsconfig(tsconfigPath, fsSystem) {
177
+ const diagnostics = [];
178
+ const parsedConfig = ts.getParsedCommandLineOfConfigFile(tsconfigPath, void 0, {
179
+ ...fsSystem,
180
+ onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
181
+ diagnostics.push(diagnostic);
182
+ }
183
+ });
184
+ if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
185
+ return parsedConfig;
156
186
  }
157
187
  function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd, context = globalContext }) {
158
188
  const fsSystem = createFsSystem(context.files);
159
- const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, tsconfig ? path.dirname(tsconfig) : cwd);
160
- if (tsconfig && parsedCmd.projectReferences?.length) buildSolution(tsconfig, incremental, context);
189
+ const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
190
+ const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
191
+ if (tsconfig && parsedConfig.projectReferences?.length) {
192
+ const projectPaths = buildSolution(tsconfig, incremental, context);
193
+ debug(`collected projects: ${JSON.stringify(projectPaths)}`);
194
+ const project = findProjectContainingFile(projectPaths, id, fsSystem);
195
+ if (project) {
196
+ debug(`Creating program for project: ${project.tsconfigPath}`);
197
+ return createTsProgramFromParsedConfig({
198
+ parsedConfig: project.parsedConfig,
199
+ fsSystem,
200
+ baseDir: path.dirname(project.tsconfigPath),
201
+ id,
202
+ entries,
203
+ vue
204
+ });
205
+ }
206
+ }
207
+ return createTsProgramFromParsedConfig({
208
+ parsedConfig,
209
+ fsSystem,
210
+ baseDir,
211
+ id,
212
+ entries,
213
+ vue
214
+ });
215
+ }
216
+ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue }) {
161
217
  const compilerOptions = {
162
218
  ...defaultCompilerOptions,
163
- ...parsedCmd.options
219
+ ...parsedConfig.options,
220
+ $configRaw: parsedConfig.raw,
221
+ $rootDir: baseDir
164
222
  };
165
- const rootNames = [...new Set([id, ...entries || parsedCmd.fileNames].map((f) => fsSystem.resolvePath(f)))];
223
+ const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
166
224
  const host = ts.createCompilerHost(compilerOptions, true);
167
225
  host.readFile = fsSystem.readFile;
168
226
  host.fileExists = fsSystem.fileExists;
@@ -172,7 +230,7 @@ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue,
172
230
  rootNames,
173
231
  options: compilerOptions,
174
232
  host,
175
- projectReferences: parsedCmd.projectReferences
233
+ projectReferences: parsedConfig.projectReferences
176
234
  });
177
235
  const sourceFile = program.getSourceFile(id);
178
236
  if (!sourceFile) {
@@ -0,0 +1,3 @@
1
+ import { createContext, tscEmit } from "./tsc-DkRb5DrU.js";
2
+
3
+ export { createContext, tscEmit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.13.13",
3
+ "version": "0.13.14",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "@typescript/native-preview": ">=7.0.0-dev.20250601.1",
33
33
  "rolldown": "^1.0.0-beta.9",
34
34
  "typescript": "^5.0.0",
35
- "vue-tsc": "~2.2.0"
35
+ "vue-tsc": "^2.2.0 || ^3.0.0"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@typescript/native-preview": {
@@ -46,31 +46,31 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@babel/generator": "^7.27.5",
50
- "@babel/parser": "^7.27.7",
51
- "@babel/types": "^7.27.7",
52
- "ast-kit": "^2.1.0",
53
- "birpc": "^2.4.0",
49
+ "@babel/generator": "^7.28.0",
50
+ "@babel/parser": "^7.28.0",
51
+ "@babel/types": "^7.28.1",
52
+ "ast-kit": "^2.1.1",
53
+ "birpc": "^2.5.0",
54
54
  "debug": "^4.4.1",
55
55
  "dts-resolver": "^2.1.1",
56
56
  "get-tsconfig": "^4.10.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@sxzz/eslint-config": "^7.0.4",
59
+ "@sxzz/eslint-config": "^7.0.6",
60
60
  "@sxzz/prettier-config": "^2.2.3",
61
61
  "@sxzz/test-utils": "^0.5.6",
62
62
  "@types/babel__generator": "^7.27.0",
63
63
  "@types/debug": "^4.1.12",
64
- "@types/node": "^24.0.6",
65
- "@typescript/native-preview": "7.0.0-dev.20250627.1",
66
- "@volar/typescript": "^2.4.15",
67
- "@vue/language-core": "^2.2.10",
64
+ "@types/node": "^24.0.14",
65
+ "@typescript/native-preview": "7.0.0-dev.20250715.1",
66
+ "@volar/typescript": "^2.4.19",
67
+ "@vue/language-core": "^3.0.1",
68
68
  "bumpp": "^10.2.0",
69
69
  "diff": "^8.0.2",
70
- "eslint": "^9.30.0",
70
+ "eslint": "^9.31.0",
71
71
  "estree-walker": "^3.0.3",
72
72
  "prettier": "^3.6.2",
73
- "rolldown": "^1.0.0-beta.21",
73
+ "rolldown": "^1.0.0-beta.27",
74
74
  "rollup-plugin-dts": "^6.2.1",
75
75
  "tinyglobby": "^0.2.14",
76
76
  "tsdown": "^0.12.9",
@@ -78,7 +78,7 @@
78
78
  "typescript": "^5.8.3",
79
79
  "vitest": "^3.2.4",
80
80
  "vue": "^3.5.17",
81
- "vue-tsc": "^2.2.10"
81
+ "vue-tsc": "^3.0.1"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=20.18.0"
@@ -1,3 +0,0 @@
1
- import { createContext, tscEmit } from "./tsc-AS4dxecO.js";
2
-
3
- export { createContext, tscEmit };