rolldown-plugin-dts 0.13.8 → 0.13.10
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 +1 -1
- package/dist/index.js +42 -30
- 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 +9 -9
- package/dist/tsc-sXJZixaR.js +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ interface Options {
|
|
|
109
109
|
*
|
|
110
110
|
* **Note:** This option is not yet recommended for production environments.
|
|
111
111
|
*/
|
|
112
|
-
tsgo?: boolean
|
|
112
|
+
tsgo?: boolean;
|
|
113
113
|
}
|
|
114
114
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
115
115
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
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" });
|
|
@@ -642,21 +643,11 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
642
643
|
return {
|
|
643
644
|
name: "rolldown-plugin-dts:generate",
|
|
644
645
|
async buildStart(options) {
|
|
645
|
-
if (tsgo)
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
await spawnAsync(tsgo$1, [
|
|
651
|
-
"--noEmit",
|
|
652
|
-
"false",
|
|
653
|
-
"--declaration",
|
|
654
|
-
"--emitDeclarationOnly",
|
|
655
|
-
...tsconfig ? ["-p", tsconfig] : [],
|
|
656
|
-
"--outDir",
|
|
657
|
-
tsgoDist
|
|
658
|
-
], { stdio: "inherit" });
|
|
659
|
-
} else if (!parallel && (!isolatedDeclarations || vue)) ({tscEmit} = await import("./tsc-sXJZixaR.js"));
|
|
646
|
+
if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
|
|
647
|
+
else if (!parallel && (!isolatedDeclarations || vue)) {
|
|
648
|
+
tscModule = await import("./tsc-CJ55BCXi.js");
|
|
649
|
+
tscContext = eager ? void 0 : tscModule.createContext();
|
|
650
|
+
}
|
|
660
651
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
661
652
|
debug$1("resolving input alias %s -> %s", name, id);
|
|
662
653
|
let resolved = await this.resolve(id);
|
|
@@ -723,9 +714,12 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
723
714
|
debug$1("generate dts %s from %s", dtsId, id);
|
|
724
715
|
if (tsgo) {
|
|
725
716
|
if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
|
|
726
|
-
const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(
|
|
717
|
+
const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_ts_to_dts(id)));
|
|
727
718
|
if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
|
|
728
|
-
else
|
|
719
|
+
else {
|
|
720
|
+
debug$1("[tsgo]", dtsPath, "is missing");
|
|
721
|
+
throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
|
|
722
|
+
}
|
|
729
723
|
} else if (isolatedDeclarations && !RE_VUE.test(id)) {
|
|
730
724
|
const result = isolatedDeclaration(id, code, isolatedDeclarations);
|
|
731
725
|
if (result.errors.length) {
|
|
@@ -749,11 +743,12 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
749
743
|
cwd,
|
|
750
744
|
entries,
|
|
751
745
|
id,
|
|
752
|
-
vue
|
|
746
|
+
vue,
|
|
747
|
+
context: tscContext
|
|
753
748
|
};
|
|
754
749
|
let result;
|
|
755
750
|
if (parallel) result = await rpc.tscEmit(options);
|
|
756
|
-
else result = tscEmit(options);
|
|
751
|
+
else result = tscModule.tscEmit(options);
|
|
757
752
|
if (result.error) return this.error(result.error);
|
|
758
753
|
dtsCode = result.code;
|
|
759
754
|
map = result.map;
|
|
@@ -770,16 +765,33 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
770
765
|
} : void 0,
|
|
771
766
|
async buildEnd() {
|
|
772
767
|
childProcess?.kill();
|
|
773
|
-
if (tsgoDist) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
tsgoDist = void 0;
|
|
779
|
-
}
|
|
768
|
+
if (!debug$1.enabled && tsgoDist) await rm(tsgoDist, {
|
|
769
|
+
recursive: true,
|
|
770
|
+
force: true
|
|
771
|
+
}).catch(() => {});
|
|
772
|
+
tscContext = tsgoDist = void 0;
|
|
780
773
|
}
|
|
781
774
|
};
|
|
782
775
|
}
|
|
776
|
+
async function runTsgo(root, tsconfig) {
|
|
777
|
+
const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
|
|
778
|
+
const { default: getExePath } = await import(new URL("./lib/getExePath.js", tsgoPkg).href);
|
|
779
|
+
const tsgo = getExePath();
|
|
780
|
+
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
781
|
+
debug$1("[tsgo] tsgoDist", tsgoDist);
|
|
782
|
+
await spawnAsync(tsgo, [
|
|
783
|
+
"--noEmit",
|
|
784
|
+
"false",
|
|
785
|
+
"--declaration",
|
|
786
|
+
"--emitDeclarationOnly",
|
|
787
|
+
...tsconfig ? ["-p", tsconfig] : [],
|
|
788
|
+
"--outDir",
|
|
789
|
+
tsgoDist,
|
|
790
|
+
"--rootDir",
|
|
791
|
+
root
|
|
792
|
+
], { stdio: "inherit" });
|
|
793
|
+
return tsgoDist;
|
|
794
|
+
}
|
|
783
795
|
|
|
784
796
|
//#endregion
|
|
785
797
|
//#region src/options.ts
|
|
@@ -834,7 +846,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
834
846
|
}
|
|
835
847
|
|
|
836
848
|
//#endregion
|
|
837
|
-
//#region src/
|
|
849
|
+
//#region src/resolver.ts
|
|
838
850
|
function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
839
851
|
const resolver = createResolver({
|
|
840
852
|
tsconfig,
|
|
@@ -842,7 +854,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
842
854
|
ResolverFactory
|
|
843
855
|
});
|
|
844
856
|
return {
|
|
845
|
-
name: "rolldown-plugin-dts:
|
|
857
|
+
name: "rolldown-plugin-dts:resolver",
|
|
846
858
|
resolveId: {
|
|
847
859
|
order: "pre",
|
|
848
860
|
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.10",
|
|
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": "^
|
|
65
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
64
|
+
"@types/node": "^24.0.0",
|
|
65
|
+
"@typescript/native-preview": "7.0.0-dev.20250611.1",
|
|
66
66
|
"@volar/typescript": "^2.4.14",
|
|
67
67
|
"@vue/language-core": "^2.2.10",
|
|
68
68
|
"bumpp": "^10.1.1",
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
"eslint": "^9.28.0",
|
|
71
71
|
"estree-walker": "^3.0.3",
|
|
72
72
|
"prettier": "^3.5.3",
|
|
73
|
-
"rolldown": "1.0.0-beta.
|
|
73
|
+
"rolldown": "1.0.0-beta.14",
|
|
74
74
|
"rollup-plugin-dts": "^6.2.1",
|
|
75
75
|
"tinyglobby": "^0.2.14",
|
|
76
|
-
"tsdown": "^0.12.
|
|
77
|
-
"tsx": "^4.
|
|
76
|
+
"tsdown": "^0.12.7",
|
|
77
|
+
"tsx": "^4.20.0",
|
|
78
78
|
"typescript": "^5.8.3",
|
|
79
|
-
"vitest": "^3.2.
|
|
79
|
+
"vitest": "^3.2.3",
|
|
80
80
|
"vue": "^3.5.16",
|
|
81
81
|
"vue-tsc": "^2.2.10"
|
|
82
82
|
},
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"node": ">=20.18.0"
|
|
85
85
|
},
|
|
86
86
|
"resolutions": {
|
|
87
|
-
"rolldown": "1.0.0-beta.
|
|
87
|
+
"rolldown": "1.0.0-beta.14"
|
|
88
88
|
},
|
|
89
89
|
"prettier": "@sxzz/prettier-config",
|
|
90
90
|
"scripts": {
|
package/dist/tsc-sXJZixaR.js
DELETED