rolldown-plugin-dts 0.11.2 → 0.11.4
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 +9 -3
- package/dist/index.js +59 -18
- package/package.json +14 -6
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ declare function createFakeJsPlugin({
|
|
|
13
13
|
declare function createGeneratePlugin({
|
|
14
14
|
compilerOptions,
|
|
15
15
|
isolatedDeclarations,
|
|
16
|
-
emitDtsOnly
|
|
17
|
-
|
|
16
|
+
emitDtsOnly,
|
|
17
|
+
vue
|
|
18
|
+
}: Pick<OptionsResolved, "compilerOptions" | "isolatedDeclarations" | "emitDtsOnly" | "vue">): Plugin;
|
|
18
19
|
|
|
19
20
|
//#endregion
|
|
20
21
|
//#region src/index.d.ts
|
|
@@ -63,6 +64,10 @@ interface Options {
|
|
|
63
64
|
sourcemap?: boolean;
|
|
64
65
|
/** Resolve external types used in dts files from `node_modules` */
|
|
65
66
|
resolve?: boolean | (string | RegExp)[];
|
|
67
|
+
/**
|
|
68
|
+
* When `true`, the plugin will generate `.d.ts` via `vue-tsc`.
|
|
69
|
+
*/
|
|
70
|
+
vue?: boolean;
|
|
66
71
|
}
|
|
67
72
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
68
73
|
type OptionsResolved = Overwrite<Required<Options>, {
|
|
@@ -78,7 +83,8 @@ declare function resolveOptions({
|
|
|
78
83
|
sourcemap,
|
|
79
84
|
dtsInput,
|
|
80
85
|
emitDtsOnly,
|
|
81
|
-
resolve
|
|
86
|
+
resolve,
|
|
87
|
+
vue
|
|
82
88
|
}: Options): OptionsResolved;
|
|
83
89
|
|
|
84
90
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -230,11 +230,12 @@ const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
|
230
230
|
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
231
231
|
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
232
232
|
const RE_CSS = /\.css$/;
|
|
233
|
+
const RE_VUE = /\.vue$/;
|
|
233
234
|
function filename_js_to_dts(id) {
|
|
234
235
|
return id.replace(RE_JS, ".d.$1ts");
|
|
235
236
|
}
|
|
236
237
|
function filename_ts_to_dts(id) {
|
|
237
|
-
return id.replace(RE_TS, ".d.$1ts");
|
|
238
|
+
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts");
|
|
238
239
|
}
|
|
239
240
|
function filename_dts_to(id, ext) {
|
|
240
241
|
return id.replace(RE_DTS, `.$1${ext}`);
|
|
@@ -295,6 +296,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
295
296
|
const setStmt = (node) => program.body[i] = node;
|
|
296
297
|
if (rewriteImportExport(stmt, setStmt)) continue;
|
|
297
298
|
const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
|
|
299
|
+
if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
|
|
298
300
|
const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
|
|
299
301
|
const isDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && stmt.declaration;
|
|
300
302
|
const decl = isDecl ? stmt.declaration : stmt;
|
|
@@ -618,6 +620,37 @@ function inheritNodeComments(oldNode, newNode) {
|
|
|
618
620
|
}
|
|
619
621
|
}
|
|
620
622
|
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region src/utils/vue.ts
|
|
625
|
+
const debug$3 = Debug("rolldown-plugin-dts:vue");
|
|
626
|
+
let createVueProgram;
|
|
627
|
+
const require = createRequire(import.meta.url);
|
|
628
|
+
function loadVueLanguageTools() {
|
|
629
|
+
try {
|
|
630
|
+
const vueTscPath = require.resolve("vue-tsc");
|
|
631
|
+
const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
632
|
+
const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
633
|
+
return {
|
|
634
|
+
proxyCreateProgram,
|
|
635
|
+
vue
|
|
636
|
+
};
|
|
637
|
+
} catch (error) {
|
|
638
|
+
debug$3("vue language tools not found", error);
|
|
639
|
+
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function createVueProgramFactory() {
|
|
643
|
+
if (createVueProgram) return createVueProgram;
|
|
644
|
+
debug$3("loading vue language tools");
|
|
645
|
+
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
646
|
+
return createVueProgram = proxyCreateProgram(ts, ts.createProgram, (ts$1, options) => {
|
|
647
|
+
const { configFilePath } = options.options;
|
|
648
|
+
const vueOptions = typeof configFilePath === "string" ? vue.createParsedCommandLine(ts$1, ts$1.sys, configFilePath.replaceAll("\\", "/")).vueOptions : vue.getDefaultCompilerOptions();
|
|
649
|
+
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$1, options.options, vueOptions, (id) => id);
|
|
650
|
+
return { languagePlugins: [vueLanguagePlugin] };
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
|
|
621
654
|
//#endregion
|
|
622
655
|
//#region src/utils/tsc.ts
|
|
623
656
|
const debug$2 = Debug("rolldown-plugin-dts:tsc");
|
|
@@ -625,8 +658,8 @@ let ts;
|
|
|
625
658
|
let formatHost;
|
|
626
659
|
function initTs() {
|
|
627
660
|
debug$2("loading typescript");
|
|
628
|
-
const require = createRequire(import.meta.url);
|
|
629
|
-
ts = require("typescript");
|
|
661
|
+
const require$1 = createRequire(import.meta.url);
|
|
662
|
+
ts = require$1("typescript");
|
|
630
663
|
formatHost = {
|
|
631
664
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
632
665
|
getNewLine: () => ts.sys.newLine,
|
|
@@ -642,11 +675,10 @@ const defaultCompilerOptions = {
|
|
|
642
675
|
checkJs: false,
|
|
643
676
|
declarationMap: false,
|
|
644
677
|
skipLibCheck: true,
|
|
645
|
-
preserveSymlinks: true,
|
|
646
678
|
target: 99,
|
|
647
679
|
resolveJsonModule: true
|
|
648
680
|
};
|
|
649
|
-
function createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap) {
|
|
681
|
+
function createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap, vue) {
|
|
650
682
|
const program = programs.find((program$1) => {
|
|
651
683
|
if (isEntry) return program$1.getRootFileNames().includes(id);
|
|
652
684
|
return program$1.getSourceFile(id);
|
|
@@ -659,12 +691,12 @@ function createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap) {
|
|
|
659
691
|
};
|
|
660
692
|
}
|
|
661
693
|
debug$2(`create program for module: ${id}`);
|
|
662
|
-
const module = createTsProgram(compilerOptions, dtsMap, id);
|
|
694
|
+
const module = createTsProgram(compilerOptions, dtsMap, id, vue);
|
|
663
695
|
debug$2(`created program for module: ${id}`);
|
|
664
696
|
programs.push(module.program);
|
|
665
697
|
return module;
|
|
666
698
|
}
|
|
667
|
-
function createTsProgram(compilerOptions, dtsMap, id) {
|
|
699
|
+
function createTsProgram(compilerOptions, dtsMap, id, vue) {
|
|
668
700
|
const overrideCompilerOptions = ts.convertCompilerOptionsFromJson(compilerOptions, ".").options;
|
|
669
701
|
const options = {
|
|
670
702
|
...defaultCompilerOptions,
|
|
@@ -684,8 +716,13 @@ function createTsProgram(compilerOptions, dtsMap, id) {
|
|
|
684
716
|
if (debug$2.enabled && !RE_NODE_MODULES.test(fileName)) debug$2(`read file from fs: ${fileName}`);
|
|
685
717
|
return _readFile(fileName);
|
|
686
718
|
};
|
|
687
|
-
const entries = Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id);
|
|
688
|
-
const
|
|
719
|
+
const entries = [...new Set([...Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id), id])];
|
|
720
|
+
const createProgram = vue ? createVueProgramFactory() : ts.createProgram;
|
|
721
|
+
const program = createProgram({
|
|
722
|
+
rootNames: entries,
|
|
723
|
+
options,
|
|
724
|
+
host
|
|
725
|
+
});
|
|
689
726
|
const sourceFile = program.getSourceFile(id);
|
|
690
727
|
if (!sourceFile) throw new Error(`Source file not found: ${id}`);
|
|
691
728
|
return {
|
|
@@ -729,7 +766,7 @@ function getTsModule(dtsMap, tsId) {
|
|
|
729
766
|
//#endregion
|
|
730
767
|
//#region src/generate.ts
|
|
731
768
|
const debug$1 = Debug("rolldown-plugin-dts:generate");
|
|
732
|
-
function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emitDtsOnly = false }) {
|
|
769
|
+
function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emitDtsOnly = false, vue }) {
|
|
733
770
|
const dtsMap = new Map();
|
|
734
771
|
/**
|
|
735
772
|
* A map of input id to output file name
|
|
@@ -742,7 +779,10 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
742
779
|
*/
|
|
743
780
|
const inputAliasMap = new Map();
|
|
744
781
|
let programs = [];
|
|
745
|
-
if (!isolatedDeclarations)
|
|
782
|
+
if (vue || !isolatedDeclarations) {
|
|
783
|
+
initTs();
|
|
784
|
+
if (vue) createVueProgramFactory();
|
|
785
|
+
}
|
|
746
786
|
return {
|
|
747
787
|
name: "rolldown-plugin-dts:generate",
|
|
748
788
|
async buildStart(options) {
|
|
@@ -774,7 +814,7 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
774
814
|
transform: {
|
|
775
815
|
order: "pre",
|
|
776
816
|
filter: { id: {
|
|
777
|
-
include: [RE_TS],
|
|
817
|
+
include: [RE_TS, RE_VUE],
|
|
778
818
|
exclude: [RE_DTS, RE_NODE_MODULES]
|
|
779
819
|
} },
|
|
780
820
|
handler(code, id) {
|
|
@@ -809,7 +849,7 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
809
849
|
let dtsCode;
|
|
810
850
|
let map;
|
|
811
851
|
debug$1("generate dts %s from %s", dtsId, id);
|
|
812
|
-
if (isolatedDeclarations) {
|
|
852
|
+
if (isolatedDeclarations && !RE_VUE.test(id)) {
|
|
813
853
|
const result = isolatedDeclaration(id, code, isolatedDeclarations);
|
|
814
854
|
if (result.errors.length) {
|
|
815
855
|
const [error] = result.errors;
|
|
@@ -824,7 +864,7 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
824
864
|
map.sourcesContent = void 0;
|
|
825
865
|
}
|
|
826
866
|
} else {
|
|
827
|
-
const module = createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap);
|
|
867
|
+
const module = createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap, vue);
|
|
828
868
|
const result = tscEmit(module);
|
|
829
869
|
if (result.error) return this.error(result.error);
|
|
830
870
|
dtsCode = result.code;
|
|
@@ -871,7 +911,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
871
911
|
};
|
|
872
912
|
let resolution = resolver(id, importer);
|
|
873
913
|
resolution &&= path.normalize(resolution);
|
|
874
|
-
if (!resolution || !RE_TS.test(resolution)) {
|
|
914
|
+
if (!resolution || !RE_TS.test(resolution) && !RE_VUE.test(resolution)) {
|
|
875
915
|
const result = await this.resolve(id, importer, options);
|
|
876
916
|
if (!result || !RE_TS.test(result.id)) return external;
|
|
877
917
|
resolution = result.id;
|
|
@@ -882,7 +922,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
882
922
|
else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
|
|
883
923
|
if (!shouldResolve) return external;
|
|
884
924
|
}
|
|
885
|
-
if (RE_TS.test(resolution) && !RE_DTS.test(resolution)) {
|
|
925
|
+
if (RE_TS.test(resolution) && !RE_DTS.test(resolution) || RE_VUE.test(resolution)) {
|
|
886
926
|
await this.load({ id: resolution });
|
|
887
927
|
resolution = filename_ts_to_dts(resolution);
|
|
888
928
|
}
|
|
@@ -905,7 +945,7 @@ function dts(options = {}) {
|
|
|
905
945
|
plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
|
|
906
946
|
return plugins;
|
|
907
947
|
}
|
|
908
|
-
function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
|
|
948
|
+
function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false }) {
|
|
909
949
|
if (tsconfig === true || tsconfig == null) {
|
|
910
950
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
911
951
|
tsconfig = path$1;
|
|
@@ -937,7 +977,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
|
|
|
937
977
|
sourcemap,
|
|
938
978
|
dtsInput,
|
|
939
979
|
emitDtsOnly,
|
|
940
|
-
resolve
|
|
980
|
+
resolve,
|
|
981
|
+
vue
|
|
941
982
|
};
|
|
942
983
|
}
|
|
943
984
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "A Rolldown plugin to bundle dts files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,30 +29,36 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"rolldown": "^1.0.0-beta.8-commit.534fde3",
|
|
32
|
-
"typescript": "^5.0.0"
|
|
32
|
+
"typescript": "^5.0.0",
|
|
33
|
+
"vue-tsc": "~2.2.0"
|
|
33
34
|
},
|
|
34
35
|
"peerDependenciesMeta": {
|
|
35
36
|
"typescript": {
|
|
36
37
|
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"vue-tsc": {
|
|
40
|
+
"optional": true
|
|
37
41
|
}
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
44
|
"@babel/generator": "^7.27.1",
|
|
41
45
|
"@babel/parser": "^7.27.2",
|
|
42
46
|
"@babel/types": "^7.27.1",
|
|
43
|
-
"ast-kit": "^
|
|
47
|
+
"ast-kit": "^2.0.0",
|
|
44
48
|
"debug": "^4.4.0",
|
|
45
|
-
"dts-resolver": "^1.
|
|
49
|
+
"dts-resolver": "^1.2.0",
|
|
46
50
|
"get-tsconfig": "^4.10.0"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@sxzz/eslint-config": "^7.0.
|
|
53
|
+
"@sxzz/eslint-config": "^7.0.1",
|
|
50
54
|
"@sxzz/prettier-config": "^2.2.1",
|
|
51
55
|
"@sxzz/test-utils": "^0.5.6",
|
|
52
56
|
"@types/babel__generator": "^7.27.0",
|
|
53
57
|
"@types/debug": "^4.1.12",
|
|
54
58
|
"@types/diff": "^7.0.2",
|
|
55
59
|
"@types/node": "^22.15.17",
|
|
60
|
+
"@volar/typescript": "^2.4.13",
|
|
61
|
+
"@vue/language-core": "^2.2.10",
|
|
56
62
|
"bumpp": "^10.1.0",
|
|
57
63
|
"diff": "^7.0.0",
|
|
58
64
|
"eslint": "^9.26.0",
|
|
@@ -64,7 +70,9 @@
|
|
|
64
70
|
"tsdown": "^0.11.1",
|
|
65
71
|
"tsx": "^4.19.4",
|
|
66
72
|
"typescript": "^5.8.3",
|
|
67
|
-
"vitest": "^3.1.3"
|
|
73
|
+
"vitest": "^3.1.3",
|
|
74
|
+
"vue": "^3.5.13",
|
|
75
|
+
"vue-tsc": "^2.2.10"
|
|
68
76
|
},
|
|
69
77
|
"engines": {
|
|
70
78
|
"node": ">=20.18.0"
|