rolldown-plugin-dts 0.12.1 → 0.12.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -22
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -269,14 +269,10 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
269
269
  handler: transform
270
270
  },
271
271
  renderChunk,
272
- generateBundle(options, bundle) {
272
+ generateBundle: sourcemap ? void 0 : (options, bundle) => {
273
273
  for (const chunk of Object.values(bundle)) {
274
- if (chunk.type !== "asset" || !RE_DTS_MAP.test(chunk.fileName) || typeof chunk.source !== "string") continue;
275
- if (sourcemap) {
276
- const maps = JSON.parse(chunk.source);
277
- maps.sourcesContent = null;
278
- chunk.source = JSON.stringify(maps);
279
- } else delete bundle[chunk.fileName];
274
+ if (!RE_DTS_MAP.test(chunk.fileName)) continue;
275
+ delete bundle[chunk.fileName];
280
276
  }
281
277
  }
282
278
  };
@@ -301,7 +297,6 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
301
297
  const isDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && stmt.declaration;
302
298
  const decl = isDecl ? stmt.declaration : stmt;
303
299
  const setDecl = isDecl ? (node) => stmt.declaration = node : setStmt;
304
- if (decl.type === "VariableDeclaration" && decl.declarations.length !== 1) throw new Error("Only one declaration is supported");
305
300
  if (decl.type !== "TSDeclareFunction" && !isDeclarationType(decl)) continue;
306
301
  if (isTypeOf(decl, [
307
302
  "TSEnumDeclaration",
@@ -311,12 +306,17 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
311
306
  "TSModuleDeclaration",
312
307
  "VariableDeclaration"
313
308
  ])) decl.declare = true;
314
- let binding = decl.type === "VariableDeclaration" ? decl.declarations[0].id : "id" in decl ? decl.id : null;
315
- if (!binding) {
316
- binding = t.identifier("export_default");
309
+ const bindings = [];
310
+ if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl$1) => decl$1.id));
311
+ else if ("id" in decl && decl.id) {
312
+ let binding = decl.id;
313
+ binding = sideEffect ? t.identifier(`_${identifierIdx++}`) : binding;
314
+ bindings.push(binding);
315
+ } else {
316
+ const binding = t.identifier("export_default");
317
+ bindings.push(binding);
317
318
  decl.id = binding;
318
319
  }
319
- binding = sideEffect ? t.identifier(`_${identifierIdx++}`) : binding;
320
320
  const deps = collectDependencies(decl, namespaceStmts);
321
321
  const elements = [
322
322
  t.numericLiteral(0),
@@ -332,7 +332,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
332
332
  const symbolId = registerSymbol({
333
333
  decl,
334
334
  deps,
335
- binding
335
+ bindings
336
336
  });
337
337
  elements[0] = t.numericLiteral(symbolId);
338
338
  const runtimeAssignment = {
@@ -341,14 +341,20 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
341
341
  declarations: [{
342
342
  type: "VariableDeclarator",
343
343
  id: {
344
- ...binding,
344
+ ...bindings[0],
345
345
  typeAnnotation: null
346
346
  },
347
347
  init: runtime
348
- }]
348
+ }, ...bindings.slice(1).map((binding) => ({
349
+ type: "VariableDeclarator",
350
+ id: {
351
+ ...binding,
352
+ typeAnnotation: null
353
+ }
354
+ }))]
349
355
  };
350
356
  if (isDefaultExport) {
351
- appendStmts.push(t.exportNamedDeclaration(null, [t.exportSpecifier(binding, t.identifier("default"))]));
357
+ appendStmts.push(t.exportNamedDeclaration(null, [t.exportSpecifier(bindings[0], t.identifier("default"))]));
352
358
  setStmt(runtimeAssignment);
353
359
  } else setDecl(runtimeAssignment);
354
360
  }
@@ -371,18 +377,20 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
371
377
  program.body = patchTsNamespace(program.body);
372
378
  program.body = program.body.map((node) => {
373
379
  if (patchImportSource(node)) return node;
374
- if (node.type !== "VariableDeclaration" || node.declarations.length !== 1) return node;
380
+ if (node.type !== "VariableDeclaration") return node;
375
381
  const [decl] = node.declarations;
376
382
  if (decl.init?.type !== "ArrayExpression" || !decl.init.elements[0]) return null;
377
383
  const [symbolIdNode, ...depsFns] = decl.init.elements;
378
384
  if (symbolIdNode?.type !== "NumericLiteral") return null;
379
385
  const symbolId = symbolIdNode.value;
380
386
  const original = getSymbol(symbolId);
381
- const transformedBinding = {
382
- ...decl.id,
383
- typeAnnotation: original.binding.typeAnnotation
384
- };
385
- overwriteNode(original.binding, transformedBinding);
387
+ for (const [i, decl$1] of node.declarations.entries()) {
388
+ const transformedBinding = {
389
+ ...decl$1.id,
390
+ typeAnnotation: original.bindings[i].typeAnnotation
391
+ };
392
+ overwriteNode(original.bindings[i], transformedBinding);
393
+ }
386
394
  const transformedDeps = depsFns.filter((node$1) => node$1?.type === "ArrowFunctionExpression").map((node$1) => node$1.body);
387
395
  if (original.deps.length) for (let i = 0; i < original.deps.length; i++) {
388
396
  const originalDep = original.deps[i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "@babel/parser": "^7.27.2",
46
46
  "@babel/types": "^7.27.1",
47
47
  "ast-kit": "^2.0.0",
48
- "debug": "^4.4.0",
48
+ "debug": "^4.4.1",
49
49
  "dts-resolver": "^2.0.1",
50
50
  "get-tsconfig": "^4.10.0"
51
51
  },
@@ -59,14 +59,14 @@
59
59
  "@volar/typescript": "^2.4.13",
60
60
  "@vue/language-core": "^2.2.10",
61
61
  "bumpp": "^10.1.0",
62
- "diff": "^8.0.0",
62
+ "diff": "^8.0.1",
63
63
  "eslint": "^9.26.0",
64
64
  "estree-walker": "^3.0.3",
65
65
  "prettier": "^3.5.3",
66
66
  "rolldown": "canary",
67
67
  "rollup-plugin-dts": "^6.2.1",
68
68
  "tinyglobby": "^0.2.13",
69
- "tsdown": "^0.11.5",
69
+ "tsdown": "^0.11.9",
70
70
  "tsx": "^4.19.4",
71
71
  "typescript": "^5.8.3",
72
72
  "vitest": "^3.1.3",