rolldown-plugin-dts 0.17.1 → 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 +46 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -628,7 +628,7 @@ function isReferenceId(node) {
|
|
|
628
628
|
return !!node && (node.type === "Identifier" || node.type === "MemberExpression");
|
|
629
629
|
}
|
|
630
630
|
function isHelperImport(node) {
|
|
631
|
-
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));
|
|
632
632
|
}
|
|
633
633
|
/**
|
|
634
634
|
* patch `.d.ts` suffix in import source to `.js`
|
|
@@ -943,6 +943,24 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
943
943
|
if (result.error) return this.error(result.error);
|
|
944
944
|
dtsCode = result.code;
|
|
945
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
|
+
}
|
|
946
964
|
}
|
|
947
965
|
return {
|
|
948
966
|
code: dtsCode || "",
|
|
@@ -988,6 +1006,33 @@ async function runTsgo(root, tsconfig) {
|
|
|
988
1006
|
], { stdio: "inherit" });
|
|
989
1007
|
return tsgoDist;
|
|
990
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
|
+
}
|
|
991
1036
|
|
|
992
1037
|
//#endregion
|
|
993
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": [
|
|
@@ -78,24 +78,24 @@
|
|
|
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"
|