rolldown-plugin-dts 0.24.0-beta.1 → 0.24.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.
Files changed (2) hide show
  1. package/dist/index.mjs +126 -39
  2. package/package.json +12 -18
package/dist/index.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
- const __cjs_require = __cjs_createRequire(import.meta.url);
3
1
  import { a as RE_JSON, c as RE_TS, d as filename_js_to_dts, f as filename_to_dts, i as RE_JS, l as RE_VUE, m as resolveTemplateFn, n as RE_DTS, o as RE_NODE_MODULES, p as replaceTemplateName, r as RE_DTS_MAP, s as RE_ROLLDOWN_RUNTIME, t as RE_CSS, u as filename_dts_to } from "./filename-DQnUJlio.mjs";
4
2
  import { createContext, globalContext, invalidateContextFile } from "./tsc-context.mjs";
5
3
  import { createDebug } from "obug";
@@ -7,13 +5,11 @@ import { importerId, include } from "rolldown/filter";
7
5
  import { generate } from "@babel/generator";
8
6
  import { isIdentifierName } from "@babel/helper-validator-identifier";
9
7
  import { parse } from "@babel/parser";
10
- import * as t from "@babel/types";
11
8
  import { isDeclarationType, isIdentifierOf, isTypeOf, resolveString, walkAST } from "ast-kit";
12
9
  import { fork, spawn } from "node:child_process";
13
10
  import { existsSync } from "node:fs";
14
11
  import { mkdtemp, readFile, rm } from "node:fs/promises";
15
12
  import path from "node:path";
16
- const picomatch = __cjs_require("picomatch");
17
13
  import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
18
14
  import { tmpdir } from "node:os";
19
15
  import process from "node:process";
@@ -141,11 +137,17 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
141
137
  else if ("id" in decl && decl.id) {
142
138
  let binding = decl.id;
143
139
  if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
144
- binding = sideEffect ? t.identifier(`_${getIdentifierIndex(identifierMap, "")}`) : binding;
140
+ binding = sideEffect ? {
141
+ type: "Identifier",
142
+ name: `_${getIdentifierIndex(identifierMap, "")}`
143
+ } : binding;
145
144
  if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
146
145
  bindings.push(binding);
147
146
  } else {
148
- const binding = t.identifier("export_default");
147
+ const binding = {
148
+ type: "Identifier",
149
+ name: "export_default"
150
+ };
149
151
  bindings.push(binding);
150
152
  decl.id = binding;
151
153
  }
@@ -154,23 +156,48 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
154
156
  const deps = collectDependencies(decl, namespaceStmts, childrenSet, identifierMap);
155
157
  const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
156
158
  if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
157
- const declarationId = registerDeclaration({
158
- decl,
159
- deps,
160
- bindings,
161
- params,
162
- children
163
- });
164
- const declarationIdNode = t.numericLiteral(declarationId);
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
- })));
173
- const sideEffectNode = sideEffect && t.callExpression(t.identifier("sideEffect"), [bindings[0]]);
159
+ const declarationIdNode = {
160
+ type: "NumericLiteral",
161
+ value: registerDeclaration({
162
+ decl,
163
+ deps,
164
+ bindings,
165
+ params,
166
+ children
167
+ })
168
+ };
169
+ const depsBody = {
170
+ type: "ArrayExpression",
171
+ elements: deps
172
+ };
173
+ const depsNode = {
174
+ type: "ArrowFunctionExpression",
175
+ params: params.map(({ name }) => ({
176
+ type: "Identifier",
177
+ name
178
+ })),
179
+ body: depsBody,
180
+ async: false,
181
+ expression: true
182
+ };
183
+ const childrenNode = {
184
+ type: "ArrayExpression",
185
+ elements: children.map((node) => ({
186
+ type: "StringLiteral",
187
+ value: "",
188
+ start: node.start,
189
+ end: node.end,
190
+ loc: node.loc
191
+ }))
192
+ };
193
+ const sideEffectNode = sideEffect && {
194
+ type: "CallExpression",
195
+ callee: {
196
+ type: "Identifier",
197
+ name: "sideEffect"
198
+ },
199
+ arguments: [bindings[0]]
200
+ };
174
201
  const runtimeArrayNode = runtimeBindingArrayExpression([
175
202
  declarationIdNode,
176
203
  depsNode,
@@ -196,11 +223,34 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
196
223
  }))]
197
224
  };
198
225
  if (isDefaultExport) {
199
- appendStmts.push(t.exportNamedDeclaration(null, [t.exportSpecifier(bindings[0], t.identifier("default"))]));
226
+ appendStmts.push({
227
+ type: "ExportNamedDeclaration",
228
+ declaration: null,
229
+ specifiers: [{
230
+ type: "ExportSpecifier",
231
+ local: bindings[0],
232
+ exported: {
233
+ type: "Identifier",
234
+ name: "default"
235
+ }
236
+ }],
237
+ source: null,
238
+ attributes: null
239
+ });
200
240
  setStmt(runtimeAssignment);
201
241
  } else setDecl(runtimeAssignment);
202
242
  }
203
- if (sideEffects) appendStmts.push(t.expressionStatement(t.callExpression(t.identifier("sideEffect"), [])));
243
+ if (sideEffects) appendStmts.push({
244
+ type: "ExpressionStatement",
245
+ expression: {
246
+ type: "CallExpression",
247
+ callee: {
248
+ type: "Identifier",
249
+ name: "sideEffect"
250
+ },
251
+ arguments: []
252
+ }
253
+ });
204
254
  program.body = [
205
255
  ...Array.from(namespaceStmts.values()).map(({ stmt }) => stmt),
206
256
  ...program.body,
@@ -264,7 +314,8 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
264
314
  for (const [i, originalDep] of declaration.deps.entries()) {
265
315
  let transformedDep = transformedDeps[i];
266
316
  if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void") transformedDep = {
267
- ...t.identifier("undefined"),
317
+ type: "Identifier",
318
+ name: "undefined",
268
319
  loc: transformedDep.loc,
269
320
  start: transformedDep.start,
270
321
  end: transformedDep.end
@@ -324,7 +375,10 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
324
375
  function collectParams(node) {
325
376
  const typeParams = [];
326
377
  walkAST(node, { leave(node) {
327
- if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => typeof name === "string" ? t.identifier(name) : name));
378
+ if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => typeof name === "string" ? {
379
+ type: "Identifier",
380
+ name
381
+ } : name));
328
382
  } });
329
383
  const paramMap = /* @__PURE__ */ new Map();
330
384
  for (const typeParam of typeParams) {
@@ -404,22 +458,40 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
404
458
  }
405
459
  function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
406
460
  const sourceText = source.value.replaceAll(/\W/g, "_");
407
- const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
408
- let local = t.identifier(localName);
461
+ let local = {
462
+ type: "Identifier",
463
+ name: `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`
464
+ };
409
465
  if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
410
466
  else namespaceStmts.set(source.value, {
411
- stmt: t.importDeclaration([t.importNamespaceSpecifier(local)], source),
467
+ stmt: {
468
+ type: "ImportDeclaration",
469
+ specifiers: [{
470
+ type: "ImportNamespaceSpecifier",
471
+ local
472
+ }],
473
+ source,
474
+ attributes: null
475
+ },
412
476
  local
413
477
  });
414
478
  if (imported) {
415
479
  const importedLeft = getIdFromTSEntityName(imported);
416
480
  if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
417
- overwriteNode(importedLeft, t.tsQualifiedName(local, { ...importedLeft }));
481
+ overwriteNode(importedLeft, {
482
+ type: "TSQualifiedName",
483
+ left: local,
484
+ right: { ...importedLeft }
485
+ });
418
486
  local = imported;
419
487
  }
420
488
  let replacement = node;
421
489
  if (node.typeArguments) {
422
- overwriteNode(node, t.tsTypeReference(local, node.typeArguments));
490
+ overwriteNode(node, {
491
+ type: "TSTypeReference",
492
+ typeName: local,
493
+ typeArguments: node.typeArguments
494
+ });
423
495
  replacement = local;
424
496
  } else overwriteNode(node, local);
425
497
  return {
@@ -466,7 +538,10 @@ function isRuntimeBindingArrayElements(elements) {
466
538
  return declarationId?.type === "NumericLiteral" && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
467
539
  }
468
540
  function runtimeBindingArrayExpression(elements) {
469
- return t.arrayExpression(elements);
541
+ return {
542
+ type: "ArrayExpression",
543
+ elements
544
+ };
470
545
  }
471
546
  function isThisExpression(node) {
472
547
  return isIdentifierOf(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
@@ -477,7 +552,12 @@ function isInfer(node) {
477
552
  function TSEntityNameToRuntime(node) {
478
553
  if (node.type === "Identifier" || node.type === "ThisExpression") return node;
479
554
  const left = TSEntityNameToRuntime(node.left);
480
- return Object.assign(node, t.memberExpression(left, node.right));
555
+ return Object.assign(node, {
556
+ type: "MemberExpression",
557
+ object: left,
558
+ property: node.right,
559
+ computed: false
560
+ });
481
561
  }
482
562
  function getIdFromTSEntityName(node) {
483
563
  if (node.type === "Identifier" || node.type === "ThisExpression") return node;
@@ -537,9 +617,11 @@ function patchTsNamespace(nodes) {
537
617
  body: [{
538
618
  type: "ExportNamedDeclaration",
539
619
  specifiers: exports.properties.filter((property) => property.type === "ObjectProperty").map((property) => {
540
- const local = property.value.body;
541
- const exported = property.key;
542
- return t.exportSpecifier(local, exported);
620
+ return {
621
+ type: "ExportSpecifier",
622
+ local: property.value.body,
623
+ exported: property.key
624
+ };
543
625
  }),
544
626
  source: null,
545
627
  declaration: null
@@ -628,7 +710,10 @@ function rewriteImportExport(node, set, typeOnlyIds) {
628
710
  specifiers: [{
629
711
  type: "ExportSpecifier",
630
712
  local: node.declaration,
631
- exported: t.identifier("default")
713
+ exported: {
714
+ type: "Identifier",
715
+ name: "default"
716
+ }
632
717
  }]
633
718
  });
634
719
  return true;
@@ -694,7 +779,9 @@ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
694
779
  const debug$2 = createDebug("rolldown-plugin-dts:generate");
695
780
  const WORKER_URL = "./tsc-worker.mjs";
696
781
  function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
697
- const entryMatcher = entry ? picomatch(entry, { ignore: entry.filter((p) => p.startsWith("!")).map((p) => p.slice(1)) }) : void 0;
782
+ const entryIncludes = entry?.filter((p) => p[0] !== "!");
783
+ const entryIgnores = entry?.filter((p) => p[0] === "!").map((p) => p.slice(1));
784
+ const entryMatcher = entry ? (file) => entryIncludes.some((p) => path.matchesGlob(file, p)) && !entryIgnores.some((p) => path.matchesGlob(file, p)) : void 0;
698
785
  const dtsMap = /* @__PURE__ */ new Map();
699
786
  /**
700
787
  * A map of input id to output file name
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
3
  "type": "module",
4
- "version": "0.24.0-beta.1",
4
+ "version": "0.24.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",
@@ -62,25 +62,23 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@babel/generator": "8.0.0-rc.3",
66
- "@babel/helper-validator-identifier": "8.0.0-rc.3",
67
- "@babel/parser": "8.0.0-rc.3",
68
- "@babel/types": "8.0.0-rc.3",
65
+ "@babel/generator": "8.0.0-rc.4",
66
+ "@babel/helper-validator-identifier": "8.0.0-rc.4",
67
+ "@babel/parser": "8.0.0-rc.4",
69
68
  "ast-kit": "^3.0.0-beta.1",
70
69
  "birpc": "^4.0.0",
71
70
  "dts-resolver": "^2.1.3",
72
- "get-tsconfig": "^5.0.0-beta.4",
73
- "obug": "^2.1.1",
74
- "picomatch": "^4.0.4"
71
+ "get-tsconfig": "5.0.0-beta.5",
72
+ "obug": "^2.1.1"
75
73
  },
76
74
  "devDependencies": {
75
+ "@babel/types": "^8.0.0-rc.4",
77
76
  "@jridgewell/source-map": "^0.3.11",
78
- "@sxzz/eslint-config": "^7.8.4",
77
+ "@sxzz/eslint-config": "^8.0.0",
79
78
  "@sxzz/prettier-config": "^2.3.1",
80
79
  "@sxzz/test-utils": "^0.5.18",
81
80
  "@types/node": "^25.6.0",
82
- "@types/picomatch": "^4.0.3",
83
- "@typescript/native-preview": "7.0.0-dev.20260427.1",
81
+ "@typescript/native-preview": "7.0.0-dev.20260430.1",
84
82
  "@volar/typescript": "^2.4.28",
85
83
  "@vue/language-core": "^3.2.7",
86
84
  "arktype": "^2.2.0",
@@ -88,20 +86,16 @@
88
86
  "diff": "^9.0.0",
89
87
  "eslint": "^10.2.1",
90
88
  "prettier": "^3.8.3",
91
- "rolldown": "^1.0.0-rc.17",
89
+ "rolldown": "^1.0.0-rc.18",
92
90
  "rolldown-plugin-require-cjs": "^0.4.0",
93
91
  "rollup-plugin-dts": "^6.4.1",
94
- "tinyglobby": "^0.2.16",
95
- "tsdown": "^0.22.0-beta.1",
92
+ "tsdown": "^0.22.0-beta.2",
96
93
  "tsnapi": "^0.3.2",
97
94
  "typescript": "^6.0.3",
98
95
  "vitest": "^4.1.5",
99
96
  "vue": "^3.5.33",
100
97
  "vue-tsc": "^3.2.7",
101
- "zod": "^4.3.6"
102
- },
103
- "resolutions": {
104
- "rolldown": "^1.0.0-rc.17"
98
+ "zod": "^4.4.1"
105
99
  },
106
100
  "prettier": "@sxzz/prettier-config",
107
101
  "scripts": {