rolldown-plugin-dts 0.13.8 → 0.13.9
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 +17 -14
- package/dist/{utils/tsc-worker.d.ts → tsc/worker.d.ts} +7 -3
- package/dist/{utils/tsc-worker.js → tsc/worker.js} +2 -2
- package/dist/{tsc-BjgfmUbK.js → tsc-AS4dxecO.js} +68 -52
- package/dist/tsc-CJ55BCXi.js +3 -0
- package/package.json +6 -6
- package/dist/tsc-sXJZixaR.js +0 -3
package/dist/index.js
CHANGED
|
@@ -610,7 +610,7 @@ function inheritNodeComments(oldNode, newNode) {
|
|
|
610
610
|
//#endregion
|
|
611
611
|
//#region src/generate.ts
|
|
612
612
|
const debug$1 = Debug("rolldown-plugin-dts:generate");
|
|
613
|
-
const WORKER_URL = "./
|
|
613
|
+
const WORKER_URL = "./tsc/worker.js";
|
|
614
614
|
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
615
615
|
const child = spawn(...args);
|
|
616
616
|
child.on("close", () => resolve());
|
|
@@ -630,7 +630,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
630
630
|
const inputAliasMap = /* @__PURE__ */ new Map();
|
|
631
631
|
let childProcess;
|
|
632
632
|
let rpc;
|
|
633
|
-
let
|
|
633
|
+
let tscModule;
|
|
634
|
+
let tscContext;
|
|
634
635
|
let tsgoDist;
|
|
635
636
|
if (!tsgo && parallel) {
|
|
636
637
|
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
@@ -656,7 +657,10 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
656
657
|
"--outDir",
|
|
657
658
|
tsgoDist
|
|
658
659
|
], { stdio: "inherit" });
|
|
659
|
-
} else if (!parallel && (!isolatedDeclarations || vue))
|
|
660
|
+
} else if (!parallel && (!isolatedDeclarations || vue)) {
|
|
661
|
+
tscModule = await import("./tsc-CJ55BCXi.js");
|
|
662
|
+
tscContext = eager ? void 0 : tscModule.createContext();
|
|
663
|
+
}
|
|
660
664
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
661
665
|
debug$1("resolving input alias %s -> %s", name, id);
|
|
662
666
|
let resolved = await this.resolve(id);
|
|
@@ -749,11 +753,12 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
749
753
|
cwd,
|
|
750
754
|
entries,
|
|
751
755
|
id,
|
|
752
|
-
vue
|
|
756
|
+
vue,
|
|
757
|
+
context: tscContext
|
|
753
758
|
};
|
|
754
759
|
let result;
|
|
755
760
|
if (parallel) result = await rpc.tscEmit(options);
|
|
756
|
-
else result = tscEmit(options);
|
|
761
|
+
else result = tscModule.tscEmit(options);
|
|
757
762
|
if (result.error) return this.error(result.error);
|
|
758
763
|
dtsCode = result.code;
|
|
759
764
|
map = result.map;
|
|
@@ -770,13 +775,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
770
775
|
} : void 0,
|
|
771
776
|
async buildEnd() {
|
|
772
777
|
childProcess?.kill();
|
|
773
|
-
if (tsgoDist) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
tsgoDist = void 0;
|
|
779
|
-
}
|
|
778
|
+
if (tsgoDist) await rm(tsgoDist, {
|
|
779
|
+
recursive: true,
|
|
780
|
+
force: true
|
|
781
|
+
}).catch(() => {});
|
|
782
|
+
tscContext = tsgoDist = void 0;
|
|
780
783
|
}
|
|
781
784
|
};
|
|
782
785
|
}
|
|
@@ -834,7 +837,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
834
837
|
}
|
|
835
838
|
|
|
836
839
|
//#endregion
|
|
837
|
-
//#region src/
|
|
840
|
+
//#region src/resolver.ts
|
|
838
841
|
function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
839
842
|
const resolver = createResolver({
|
|
840
843
|
tsconfig,
|
|
@@ -842,7 +845,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
842
845
|
ResolverFactory
|
|
843
846
|
});
|
|
844
847
|
return {
|
|
845
|
-
name: "rolldown-plugin-dts:
|
|
848
|
+
name: "rolldown-plugin-dts:resolver",
|
|
846
849
|
resolveId: {
|
|
847
850
|
order: "pre",
|
|
848
851
|
async handler(id, importer, options) {
|
|
@@ -2,8 +2,11 @@ import { TsConfigJson } from "get-tsconfig";
|
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { SourceMapInput } from "rolldown";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
6
|
-
|
|
5
|
+
//#region src/tsc/index.d.ts
|
|
6
|
+
interface TscContext {
|
|
7
|
+
programs: ts.Program[];
|
|
8
|
+
files: Map<string, string>;
|
|
9
|
+
}
|
|
7
10
|
interface TscOptions {
|
|
8
11
|
tsconfig?: string;
|
|
9
12
|
tsconfigRaw: TsConfigJson;
|
|
@@ -12,6 +15,7 @@ interface TscOptions {
|
|
|
12
15
|
entries?: string[];
|
|
13
16
|
id: string;
|
|
14
17
|
vue?: boolean;
|
|
18
|
+
context?: TscContext;
|
|
15
19
|
}
|
|
16
20
|
interface TscResult {
|
|
17
21
|
code?: string;
|
|
@@ -20,7 +24,7 @@ interface TscResult {
|
|
|
20
24
|
}
|
|
21
25
|
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
22
26
|
//#endregion
|
|
23
|
-
//#region src/
|
|
27
|
+
//#region src/tsc/worker.d.ts
|
|
24
28
|
declare const functions: {
|
|
25
29
|
tscEmit: typeof tscEmit;
|
|
26
30
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tscEmit } from "../tsc-
|
|
1
|
+
import { tscEmit } from "../tsc-AS4dxecO.js";
|
|
2
2
|
import { createBirpc } from "birpc";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/tsc/worker.ts
|
|
6
6
|
const functions = { tscEmit };
|
|
7
7
|
createBirpc(functions, {
|
|
8
8
|
post: (data) => process.send(data),
|
|
@@ -3,51 +3,58 @@ import path from "node:path";
|
|
|
3
3
|
import Debug from "debug";
|
|
4
4
|
import ts from "typescript";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/tsc/system.ts
|
|
7
7
|
const debug$2 = Debug("rolldown-plugin-dts:tsc-system");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A system that writes files to both memory and disk. It will try read files
|
|
10
|
+
* from memory firstly and fallback to disk if not found.
|
|
11
|
+
*/
|
|
12
|
+
function createFsSystem(files) {
|
|
13
|
+
return {
|
|
14
|
+
...ts.sys,
|
|
15
|
+
write(message) {
|
|
16
|
+
debug$2(message);
|
|
17
|
+
},
|
|
18
|
+
resolvePath(path$1) {
|
|
19
|
+
if (files.has(path$1)) return path$1;
|
|
20
|
+
return ts.sys.resolvePath(path$1);
|
|
21
|
+
},
|
|
22
|
+
directoryExists(directory) {
|
|
23
|
+
if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
|
|
24
|
+
return ts.sys.directoryExists(directory);
|
|
25
|
+
},
|
|
26
|
+
fileExists(fileName) {
|
|
27
|
+
if (files.has(fileName)) return true;
|
|
28
|
+
return ts.sys.fileExists(fileName);
|
|
29
|
+
},
|
|
30
|
+
readFile(fileName, ...args) {
|
|
31
|
+
if (files.has(fileName)) return files.get(fileName);
|
|
32
|
+
return ts.sys.readFile(fileName, ...args);
|
|
33
|
+
},
|
|
34
|
+
writeFile(path$1, data, ...args) {
|
|
35
|
+
files.set(path$1, data);
|
|
36
|
+
ts.sys.writeFile(path$1, data, ...args);
|
|
37
|
+
},
|
|
38
|
+
deleteFile(fileName, ...args) {
|
|
39
|
+
files.delete(fileName);
|
|
40
|
+
ts.sys.deleteFile?.(fileName, ...args);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createMemorySystem(files) {
|
|
45
|
+
return {
|
|
46
|
+
...createFsSystem(files),
|
|
47
|
+
writeFile(path$1, data) {
|
|
48
|
+
files.set(path$1, data);
|
|
49
|
+
},
|
|
50
|
+
deleteFile(fileName) {
|
|
51
|
+
files.delete(fileName);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
48
55
|
|
|
49
56
|
//#endregion
|
|
50
|
-
//#region src/
|
|
57
|
+
//#region src/tsc/vue.ts
|
|
51
58
|
const debug$1 = Debug("rolldown-plugin-dts:vue");
|
|
52
59
|
let createVueProgram;
|
|
53
60
|
const require = createRequire(import.meta.url);
|
|
@@ -78,10 +85,18 @@ function createVueProgramFactory(ts$1) {
|
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
//#endregion
|
|
81
|
-
//#region src/
|
|
88
|
+
//#region src/tsc/index.ts
|
|
82
89
|
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
83
90
|
debug(`loaded typescript: ${ts.version}`);
|
|
84
|
-
|
|
91
|
+
function createContext() {
|
|
92
|
+
const programs = [];
|
|
93
|
+
const files = /* @__PURE__ */ new Map();
|
|
94
|
+
return {
|
|
95
|
+
programs,
|
|
96
|
+
files
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const globalContext = createContext();
|
|
85
100
|
const formatHost = {
|
|
86
101
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
87
102
|
getNewLine: () => ts.sys.newLine,
|
|
@@ -100,8 +115,8 @@ const defaultCompilerOptions = {
|
|
|
100
115
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
101
116
|
};
|
|
102
117
|
function createOrGetTsModule(options) {
|
|
103
|
-
const { id, entries } = options;
|
|
104
|
-
const program = programs.find((program$1) => {
|
|
118
|
+
const { id, entries, context = globalContext } = options;
|
|
119
|
+
const program = context.programs.find((program$1) => {
|
|
105
120
|
const roots = program$1.getRootFileNames();
|
|
106
121
|
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
107
122
|
return roots.includes(id);
|
|
@@ -116,7 +131,7 @@ function createOrGetTsModule(options) {
|
|
|
116
131
|
debug(`create program for module: ${id}`);
|
|
117
132
|
const module = createTsProgram(options);
|
|
118
133
|
debug(`created program for module: ${id}`);
|
|
119
|
-
programs.push(module.program);
|
|
134
|
+
context.programs.push(module.program);
|
|
120
135
|
return module;
|
|
121
136
|
}
|
|
122
137
|
/**
|
|
@@ -128,9 +143,9 @@ function createOrGetTsModule(options) {
|
|
|
128
143
|
* changes) the build will be super fast. If `incremental` is `false`, the
|
|
129
144
|
* `.tsbuildinfo` file will only be written to the memory.
|
|
130
145
|
*/
|
|
131
|
-
function buildSolution(tsconfig, incremental) {
|
|
146
|
+
function buildSolution(tsconfig, incremental, context) {
|
|
132
147
|
debug(`building projects for ${tsconfig} with incremental: ${incremental}`);
|
|
133
|
-
const system = incremental ?
|
|
148
|
+
const system = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
134
149
|
const host = ts.createSolutionBuilderHost(system);
|
|
135
150
|
const builder = ts.createSolutionBuilder(host, [tsconfig], {
|
|
136
151
|
force: !incremental,
|
|
@@ -139,9 +154,10 @@ function buildSolution(tsconfig, incremental) {
|
|
|
139
154
|
const exitStatus = builder.build();
|
|
140
155
|
debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
|
|
141
156
|
}
|
|
142
|
-
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd }) {
|
|
157
|
+
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd, context = globalContext }) {
|
|
158
|
+
const fsSystem = createFsSystem(context.files);
|
|
143
159
|
const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, tsconfig ? path.dirname(tsconfig) : cwd);
|
|
144
|
-
if (tsconfig && parsedCmd.projectReferences?.length) buildSolution(tsconfig, incremental);
|
|
160
|
+
if (tsconfig && parsedCmd.projectReferences?.length) buildSolution(tsconfig, incremental, context);
|
|
145
161
|
const compilerOptions = {
|
|
146
162
|
...defaultCompilerOptions,
|
|
147
163
|
...parsedCmd.options
|
|
@@ -202,4 +218,4 @@ function tscEmit(tscOptions) {
|
|
|
202
218
|
}
|
|
203
219
|
|
|
204
220
|
//#endregion
|
|
205
|
-
export { tscEmit };
|
|
221
|
+
export { createContext, tscEmit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.9",
|
|
4
4
|
"description": "A Rolldown plugin to bundle dts files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@babel/generator": "^7.27.5",
|
|
50
50
|
"@babel/parser": "^7.27.5",
|
|
51
|
-
"@babel/types": "^7.27.
|
|
51
|
+
"@babel/types": "^7.27.6",
|
|
52
52
|
"ast-kit": "^2.1.0",
|
|
53
53
|
"birpc": "^2.3.0",
|
|
54
54
|
"debug": "^4.4.1",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"@sxzz/test-utils": "^0.5.6",
|
|
62
62
|
"@types/babel__generator": "^7.27.0",
|
|
63
63
|
"@types/debug": "^4.1.12",
|
|
64
|
-
"@types/node": "^22.15.
|
|
65
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
64
|
+
"@types/node": "^22.15.30",
|
|
65
|
+
"@typescript/native-preview": "7.0.0-dev.20250608.1",
|
|
66
66
|
"@volar/typescript": "^2.4.14",
|
|
67
67
|
"@vue/language-core": "^2.2.10",
|
|
68
68
|
"bumpp": "^10.1.1",
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
"rolldown": "1.0.0-beta.11-commit.f051675",
|
|
74
74
|
"rollup-plugin-dts": "^6.2.1",
|
|
75
75
|
"tinyglobby": "^0.2.14",
|
|
76
|
-
"tsdown": "^0.12.
|
|
76
|
+
"tsdown": "^0.12.7",
|
|
77
77
|
"tsx": "^4.19.4",
|
|
78
78
|
"typescript": "^5.8.3",
|
|
79
|
-
"vitest": "^3.2.
|
|
79
|
+
"vitest": "^3.2.2",
|
|
80
80
|
"vue": "^3.5.16",
|
|
81
81
|
"vue-tsc": "^2.2.10"
|
|
82
82
|
},
|
package/dist/tsc-sXJZixaR.js
DELETED