rolldown-plugin-dts 0.17.0 → 0.17.2
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.js +74 -6
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -364,7 +364,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
|
|
|
364
364
|
bindings.push(binding);
|
|
365
365
|
decl.id = binding;
|
|
366
366
|
}
|
|
367
|
-
const params =
|
|
367
|
+
const params = collectParams(decl);
|
|
368
368
|
const deps = collectDependencies(decl, namespaceStmts);
|
|
369
369
|
if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
|
|
370
370
|
const symbolId = registerSymbol({
|
|
@@ -374,7 +374,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
|
|
|
374
374
|
params
|
|
375
375
|
});
|
|
376
376
|
const symbolIdNode = t.numericLiteral(symbolId);
|
|
377
|
-
const depsNode = t.arrowFunctionExpression(params.map((
|
|
377
|
+
const depsNode = t.arrowFunctionExpression(params.map(({ name }) => t.identifier(name)), t.arrayExpression(deps));
|
|
378
378
|
const sideEffectNode = sideEffect && t.callExpression(t.identifier("sideEffect"), [bindings[0]]);
|
|
379
379
|
const runtimeArrayNode = runtimeBindingArrayExpression(sideEffectNode ? [
|
|
380
380
|
symbolIdNode,
|
|
@@ -445,9 +445,9 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
|
|
|
445
445
|
overwriteNode(original.bindings[i], transformedBinding);
|
|
446
446
|
}
|
|
447
447
|
const transformedParams = depsFn.params;
|
|
448
|
-
for (
|
|
449
|
-
const
|
|
450
|
-
|
|
448
|
+
for (const [i, transformedParam] of transformedParams.entries()) {
|
|
449
|
+
const transformedName = transformedParam.name;
|
|
450
|
+
for (const originalTypeParam of original.params[i].typeParams) originalTypeParam.name = transformedName;
|
|
451
451
|
}
|
|
452
452
|
const transformedDeps = depsFn.body.elements;
|
|
453
453
|
for (let i = 0; i < original.deps.length; i++) {
|
|
@@ -494,6 +494,29 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
|
|
|
494
494
|
function getSymbol(symbolId) {
|
|
495
495
|
return symbolMap.get(symbolId);
|
|
496
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Collects all TSTypeParameter nodes from the given node and groups them by
|
|
499
|
+
* their name. One name can associate with one or more type parameters. These
|
|
500
|
+
* names will be used as the parameter name in the generated JavaScript
|
|
501
|
+
* dependency function.
|
|
502
|
+
*/
|
|
503
|
+
function collectParams(node) {
|
|
504
|
+
const typeParams = [];
|
|
505
|
+
walk(node, { leave(node$1) {
|
|
506
|
+
if ("typeParameters" in node$1 && node$1.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node$1.typeParameters.params);
|
|
507
|
+
} });
|
|
508
|
+
const paramMap = /* @__PURE__ */ new Map();
|
|
509
|
+
for (const typeParam of typeParams) {
|
|
510
|
+
const name = typeParam.name;
|
|
511
|
+
const group = paramMap.get(name);
|
|
512
|
+
if (group) group.push(typeParam);
|
|
513
|
+
else paramMap.set(name, [typeParam]);
|
|
514
|
+
}
|
|
515
|
+
return Array.from(paramMap.entries()).map(([name, typeParams$1]) => ({
|
|
516
|
+
name,
|
|
517
|
+
typeParams: typeParams$1
|
|
518
|
+
}));
|
|
519
|
+
}
|
|
497
520
|
function collectDependencies(node, namespaceStmts) {
|
|
498
521
|
const deps = /* @__PURE__ */ new Set();
|
|
499
522
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -605,7 +628,7 @@ function isReferenceId(node) {
|
|
|
605
628
|
return !!node && (node.type === "Identifier" || node.type === "MemberExpression");
|
|
606
629
|
}
|
|
607
630
|
function isHelperImport(node) {
|
|
608
|
-
return node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__export", "__reExport"].includes(spec.
|
|
631
|
+
return node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__export", "__reExport"].includes(spec.local.name));
|
|
609
632
|
}
|
|
610
633
|
/**
|
|
611
634
|
* patch `.d.ts` suffix in import source to `.js`
|
|
@@ -920,6 +943,24 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
920
943
|
if (result.error) return this.error(result.error);
|
|
921
944
|
dtsCode = result.code;
|
|
922
945
|
map = result.map;
|
|
946
|
+
if (dtsCode && RE_JSON.test(id)) if (dtsCode.includes("declare const _exports")) {
|
|
947
|
+
if (dtsCode.includes("declare const _exports: {")) {
|
|
948
|
+
const exports = collectJsonExports(dtsCode);
|
|
949
|
+
let i = 0;
|
|
950
|
+
dtsCode += exports.map((e) => {
|
|
951
|
+
const valid = `_${e.replaceAll(/[^\w$]/g, "_")}${i++}`;
|
|
952
|
+
const jsonKey = JSON.stringify(e);
|
|
953
|
+
return `declare let ${valid}: typeof _exports[${jsonKey}]\nexport { ${valid} as ${jsonKey} }`;
|
|
954
|
+
}).join("\n");
|
|
955
|
+
}
|
|
956
|
+
} else {
|
|
957
|
+
const exportMap = collectJsonExportMap(dtsCode);
|
|
958
|
+
dtsCode += `
|
|
959
|
+
declare namespace __json_default_export {
|
|
960
|
+
export { ${Array.from(exportMap.entries()).map(([exported, local]) => exported === local ? exported : `${local} as ${exported}`).join(", ")} }
|
|
961
|
+
}
|
|
962
|
+
export { __json_default_export as default }`;
|
|
963
|
+
}
|
|
923
964
|
}
|
|
924
965
|
return {
|
|
925
966
|
code: dtsCode || "",
|
|
@@ -965,6 +1006,33 @@ async function runTsgo(root, tsconfig) {
|
|
|
965
1006
|
], { stdio: "inherit" });
|
|
966
1007
|
return tsgoDist;
|
|
967
1008
|
}
|
|
1009
|
+
function collectJsonExportMap(code) {
|
|
1010
|
+
const exportMap = /* @__PURE__ */ new Map();
|
|
1011
|
+
const { program } = parse(code, {
|
|
1012
|
+
sourceType: "module",
|
|
1013
|
+
plugins: [["typescript", { dts: true }]]
|
|
1014
|
+
});
|
|
1015
|
+
for (const decl of program.body) if (decl.type === "ExportNamedDeclaration") {
|
|
1016
|
+
if (decl.declaration && decl.declaration.type === "VariableDeclaration") {
|
|
1017
|
+
for (const vdecl of decl.declaration.declarations) if (vdecl.id.type === "Identifier") exportMap.set(vdecl.id.name, vdecl.id.name);
|
|
1018
|
+
} else if (decl.specifiers.length) {
|
|
1019
|
+
for (const spec of decl.specifiers) if (spec.type === "ExportSpecifier" && spec.exported.type === "Identifier") exportMap.set(spec.exported.name, spec.local.type === "Identifier" ? spec.local.name : spec.exported.name);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return exportMap;
|
|
1023
|
+
}
|
|
1024
|
+
/** `declare const _exports` mode */
|
|
1025
|
+
function collectJsonExports(code) {
|
|
1026
|
+
const exports = [];
|
|
1027
|
+
const { program } = parse(code, {
|
|
1028
|
+
sourceType: "module",
|
|
1029
|
+
plugins: [["typescript", { dts: true }]]
|
|
1030
|
+
});
|
|
1031
|
+
const members = program.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;
|
|
1032
|
+
for (const member of members) if (member.key.type === "Identifier") exports.push(member.key.name);
|
|
1033
|
+
else if (member.key.type === "StringLiteral") exports.push(member.key.value);
|
|
1034
|
+
return exports;
|
|
1035
|
+
}
|
|
968
1036
|
|
|
969
1037
|
//#endregion
|
|
970
1038
|
//#region src/options.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -61,41 +61,41 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@babel/generator": "^7.28.
|
|
65
|
-
"@babel/parser": "^7.28.
|
|
66
|
-
"@babel/types": "^7.28.
|
|
64
|
+
"@babel/generator": "^7.28.5",
|
|
65
|
+
"@babel/parser": "^7.28.5",
|
|
66
|
+
"@babel/types": "^7.28.5",
|
|
67
67
|
"ast-kit": "^2.1.3",
|
|
68
68
|
"birpc": "^2.6.1",
|
|
69
69
|
"debug": "^4.4.3",
|
|
70
70
|
"dts-resolver": "^2.1.2",
|
|
71
71
|
"get-tsconfig": "^4.13.0",
|
|
72
|
-
"magic-string": "^0.30.
|
|
72
|
+
"magic-string": "^0.30.21"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@sxzz/eslint-config": "^7.2.7",
|
|
76
76
|
"@sxzz/prettier-config": "^2.2.4",
|
|
77
|
-
"@sxzz/test-utils": "^0.5.
|
|
77
|
+
"@sxzz/test-utils": "^0.5.12",
|
|
78
78
|
"@types/babel__generator": "^7.27.0",
|
|
79
79
|
"@types/debug": "^4.1.12",
|
|
80
80
|
"@types/node": "^24.9.1",
|
|
81
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
81
|
+
"@typescript/native-preview": "7.0.0-dev.20251027.1",
|
|
82
82
|
"@volar/typescript": "^2.4.23",
|
|
83
|
-
"@vue/language-core": "^3.1.
|
|
83
|
+
"@vue/language-core": "^3.1.2",
|
|
84
84
|
"arktype": "^2.1.23",
|
|
85
85
|
"bumpp": "^10.3.1",
|
|
86
86
|
"diff": "^8.0.2",
|
|
87
87
|
"eslint": "^9.38.0",
|
|
88
88
|
"estree-walker": "^3.0.3",
|
|
89
89
|
"prettier": "^3.6.2",
|
|
90
|
-
"rolldown": "^1.0.0-beta.
|
|
90
|
+
"rolldown": "^1.0.0-beta.45",
|
|
91
91
|
"rolldown-plugin-require-cjs": "^0.3.1",
|
|
92
92
|
"rollup-plugin-dts": "^6.2.3",
|
|
93
93
|
"tinyglobby": "^0.2.15",
|
|
94
|
-
"tsdown": "^0.15.
|
|
94
|
+
"tsdown": "^0.15.11",
|
|
95
95
|
"typescript": "^5.9.3",
|
|
96
|
-
"vitest": "^4.0.
|
|
96
|
+
"vitest": "^4.0.4",
|
|
97
97
|
"vue": "^3.5.22",
|
|
98
|
-
"vue-tsc": "^3.1.
|
|
98
|
+
"vue-tsc": "^3.1.2"
|
|
99
99
|
},
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=20.18.0"
|