rolldown-plugin-dts 0.15.10 → 0.16.1
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/{context-DIRjVfC4.d.ts → context-DXNtAHtR.d.ts} +7 -1
- package/dist/{context-BG0dlajy.js → context-b9aW37YD.js} +4 -1
- package/dist/{index-BPD4iQBs.d.ts → index-Cbz-60ZO.d.ts} +6 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/tsc-BQbq3o79.js +395 -0
- package/dist/tsc-context.d.ts +2 -2
- package/dist/tsc-context.js +1 -1
- package/dist/tsc-worker.d.ts +2 -2
- package/dist/tsc-worker.js +2 -2
- package/dist/tsc.d.ts +2 -2
- package/dist/tsc.js +2 -2
- package/package.json +8 -8
- package/dist/tsc-BJW5IMTs.js +0 -279
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
//#region src/tsc/context.d.ts
|
|
4
|
+
interface ParsedProject {
|
|
5
|
+
tsconfigPath: string;
|
|
6
|
+
parsedConfig: ts.ParsedCommandLine;
|
|
7
|
+
}
|
|
8
|
+
type SourceFileToProjectMap = Map<string, ParsedProject>;
|
|
4
9
|
interface TscContext {
|
|
5
10
|
programs: ts.Program[];
|
|
6
11
|
files: Map<string, string>;
|
|
12
|
+
projects: Map<string, SourceFileToProjectMap>;
|
|
7
13
|
}
|
|
8
14
|
declare function createContext(): TscContext;
|
|
9
15
|
declare function invalidateContextFile(context: TscContext, file: string): void;
|
|
10
16
|
declare const globalContext: TscContext;
|
|
11
17
|
//#endregion
|
|
12
|
-
export { TscContext, createContext, globalContext, invalidateContextFile };
|
|
18
|
+
export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
|
|
@@ -5,9 +5,11 @@ const debug = Debug("rolldown-plugin-dts:tsc-context");
|
|
|
5
5
|
function createContext() {
|
|
6
6
|
const programs = [];
|
|
7
7
|
const files = /* @__PURE__ */ new Map();
|
|
8
|
+
const projects = /* @__PURE__ */ new Map();
|
|
8
9
|
return {
|
|
9
10
|
programs,
|
|
10
|
-
files
|
|
11
|
+
files,
|
|
12
|
+
projects
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
15
|
function invalidateContextFile(context, file) {
|
|
@@ -16,6 +18,7 @@ function invalidateContextFile(context, file) {
|
|
|
16
18
|
context.programs = context.programs.filter((program) => {
|
|
17
19
|
return !program.getSourceFiles().some((sourceFile) => sourceFile.fileName === file);
|
|
18
20
|
});
|
|
21
|
+
context.projects.clear();
|
|
19
22
|
}
|
|
20
23
|
const globalContext = createContext();
|
|
21
24
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TscContext } from "./context-
|
|
1
|
+
import { TscContext } from "./context-DXNtAHtR.js";
|
|
2
2
|
import { TsConfigJson } from "get-tsconfig";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { SourceMapInput } from "rolldown";
|
|
5
5
|
|
|
6
|
-
//#region src/tsc/
|
|
6
|
+
//#region src/tsc/types.d.ts
|
|
7
7
|
interface TscModule {
|
|
8
8
|
program: ts.Program;
|
|
9
9
|
file: ts.SourceFile;
|
|
@@ -16,6 +16,7 @@ interface TscOptions {
|
|
|
16
16
|
incremental: boolean;
|
|
17
17
|
entries?: string[];
|
|
18
18
|
id: string;
|
|
19
|
+
sourcemap: boolean;
|
|
19
20
|
vue?: boolean;
|
|
20
21
|
context?: TscContext;
|
|
21
22
|
}
|
|
@@ -24,6 +25,8 @@ interface TscResult {
|
|
|
24
25
|
map?: SourceMapInput;
|
|
25
26
|
error?: string;
|
|
26
27
|
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/tsc/index.d.ts
|
|
27
30
|
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
28
31
|
//#endregion
|
|
29
|
-
export { TscModule, TscOptions, TscResult, tscEmit };
|
|
32
|
+
export { type TscModule, type TscOptions, type TscResult, tscEmit };
|
package/dist/index.d.ts
CHANGED
|
@@ -206,8 +206,9 @@ declare function createGeneratePlugin({
|
|
|
206
206
|
eager,
|
|
207
207
|
tsgo,
|
|
208
208
|
newContext,
|
|
209
|
-
emitJs
|
|
210
|
-
|
|
209
|
+
emitJs,
|
|
210
|
+
sourcemap
|
|
211
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
|
|
211
212
|
//#endregion
|
|
212
213
|
//#region src/index.d.ts
|
|
213
214
|
declare function dts(options?: Options): Plugin[];
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_to_dts, replaceTemplateName, resolveTemplateFn } from "./filename-Dd76wOJT.js";
|
|
2
|
-
import { createContext, globalContext, invalidateContextFile } from "./context-
|
|
2
|
+
import { createContext, globalContext, invalidateContextFile } from "./context-b9aW37YD.js";
|
|
3
3
|
import Debug from "debug";
|
|
4
4
|
import _generate from "@babel/generator";
|
|
5
5
|
import { parse } from "@babel/parser";
|
|
@@ -663,7 +663,7 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
|
663
663
|
child.on("close", () => resolve());
|
|
664
664
|
child.on("error", (error) => reject(error));
|
|
665
665
|
});
|
|
666
|
-
function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs }) {
|
|
666
|
+
function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
|
|
667
667
|
const dtsMap = /* @__PURE__ */ new Map();
|
|
668
668
|
/**
|
|
669
669
|
* A map of input id to output file name
|
|
@@ -800,6 +800,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
800
800
|
cwd,
|
|
801
801
|
entries,
|
|
802
802
|
id,
|
|
803
|
+
sourcemap,
|
|
803
804
|
vue,
|
|
804
805
|
context: tscContext
|
|
805
806
|
};
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { globalContext } from "./context-b9aW37YD.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import Debug from "debug";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
|
|
8
|
+
//#region src/tsc/system.ts
|
|
9
|
+
const debug$4 = Debug("rolldown-plugin-dts:tsc-system");
|
|
10
|
+
/**
|
|
11
|
+
* A system that writes files to both memory and disk. It will try read files
|
|
12
|
+
* from memory firstly and fallback to disk if not found.
|
|
13
|
+
*/
|
|
14
|
+
function createFsSystem(files) {
|
|
15
|
+
return {
|
|
16
|
+
...ts.sys,
|
|
17
|
+
write(message) {
|
|
18
|
+
debug$4(message);
|
|
19
|
+
},
|
|
20
|
+
resolvePath(path$1) {
|
|
21
|
+
if (files.has(path$1)) return path$1;
|
|
22
|
+
return ts.sys.resolvePath(path$1);
|
|
23
|
+
},
|
|
24
|
+
directoryExists(directory) {
|
|
25
|
+
if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
|
|
26
|
+
return ts.sys.directoryExists(directory);
|
|
27
|
+
},
|
|
28
|
+
fileExists(fileName) {
|
|
29
|
+
if (files.has(fileName)) return true;
|
|
30
|
+
return ts.sys.fileExists(fileName);
|
|
31
|
+
},
|
|
32
|
+
readFile(fileName, ...args) {
|
|
33
|
+
if (files.has(fileName)) return files.get(fileName);
|
|
34
|
+
return ts.sys.readFile(fileName, ...args);
|
|
35
|
+
},
|
|
36
|
+
writeFile(path$1, data, ...args) {
|
|
37
|
+
files.set(path$1, data);
|
|
38
|
+
ts.sys.writeFile(path$1, data, ...args);
|
|
39
|
+
},
|
|
40
|
+
deleteFile(fileName, ...args) {
|
|
41
|
+
files.delete(fileName);
|
|
42
|
+
ts.sys.deleteFile?.(fileName, ...args);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function createMemorySystem(files) {
|
|
47
|
+
return {
|
|
48
|
+
...createFsSystem(files),
|
|
49
|
+
writeFile(path$1, data) {
|
|
50
|
+
files.set(path$1, data);
|
|
51
|
+
},
|
|
52
|
+
deleteFile(fileName) {
|
|
53
|
+
files.delete(fileName);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/tsc/utils.ts
|
|
60
|
+
const formatHost = {
|
|
61
|
+
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
62
|
+
getNewLine: () => ts.sys.newLine,
|
|
63
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
64
|
+
};
|
|
65
|
+
const stripPrivateFields = (ctx) => {
|
|
66
|
+
const visitor = (node) => {
|
|
67
|
+
if (ts.isPropertySignature(node) && ts.isPrivateIdentifier(node.name)) return ctx.factory.updatePropertySignature(node, node.modifiers, ctx.factory.createStringLiteral(node.name.text), node.questionToken, node.type);
|
|
68
|
+
return ts.visitEachChild(node, visitor, ctx);
|
|
69
|
+
};
|
|
70
|
+
return (sourceFile) => ts.visitNode(sourceFile, visitor, ts.isSourceFile) ?? sourceFile;
|
|
71
|
+
};
|
|
72
|
+
const customTransformers = { afterDeclarations: [stripPrivateFields] };
|
|
73
|
+
function setSourceMapRoot(map, originalFilePath, finalFilePath) {
|
|
74
|
+
if (!map) return;
|
|
75
|
+
if (map.sourceRoot) return;
|
|
76
|
+
const originalDir = path.posix.dirname(pathToFileURL(originalFilePath).pathname);
|
|
77
|
+
const finalDir = path.posix.dirname(pathToFileURL(finalFilePath).pathname);
|
|
78
|
+
if (originalDir !== finalDir) map.sourceRoot = path.posix.relative(finalDir, originalDir);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/tsc/emit-build.ts
|
|
83
|
+
const debug$3 = Debug("rolldown-plugin-dts:tsc-build");
|
|
84
|
+
function tscEmitBuild(tscOptions) {
|
|
85
|
+
const { id, tsconfig, incremental, context = globalContext, sourcemap } = tscOptions;
|
|
86
|
+
debug$3(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
|
|
87
|
+
if (!tsconfig) return { error: "[rolldown-plugin-dts] build mode requires a tsconfig path" };
|
|
88
|
+
const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
89
|
+
const resolvedId = fsSystem.resolvePath(id);
|
|
90
|
+
if (resolvedId !== id) debug$3(`resolved id from ${id} to ${resolvedId}`);
|
|
91
|
+
const sourceFileToProjectMap = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap);
|
|
92
|
+
const project = sourceFileToProjectMap.get(resolvedId);
|
|
93
|
+
if (!project) {
|
|
94
|
+
debug$3(`unable to locate a project containing ${resolvedId}`);
|
|
95
|
+
return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
|
|
96
|
+
}
|
|
97
|
+
debug$3(`loaded project ${project.tsconfigPath} for ${id}`);
|
|
98
|
+
const ignoreCase = !fsSystem.useCaseSensitiveFileNames;
|
|
99
|
+
const outputFiles = ts.getOutputFileNames(project.parsedConfig, resolvedId, ignoreCase);
|
|
100
|
+
let code;
|
|
101
|
+
let map;
|
|
102
|
+
for (const outputFile of outputFiles) {
|
|
103
|
+
if (outputFile.endsWith(".d.ts")) {
|
|
104
|
+
if (!fsSystem.fileExists(outputFile)) {
|
|
105
|
+
console.warn(`[rolldown-plugin-dts] Unable to read file ${outputFile}`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
code = fsSystem.readFile(outputFile);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (outputFile.endsWith(".d.ts.map")) {
|
|
112
|
+
if (!fsSystem.fileExists(outputFile)) continue;
|
|
113
|
+
const text = fsSystem.readFile(outputFile);
|
|
114
|
+
if (!text) {
|
|
115
|
+
console.warn(`[rolldown-plugin-dts] Unexpected sourcemap ${outputFile}`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
map = JSON.parse(text);
|
|
119
|
+
setSourceMapRoot(map, outputFile, resolvedId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (code) return {
|
|
123
|
+
code,
|
|
124
|
+
map
|
|
125
|
+
};
|
|
126
|
+
if (incremental) {
|
|
127
|
+
debug$3(`incremental build failed`);
|
|
128
|
+
return tscEmitBuild({
|
|
129
|
+
...tscOptions,
|
|
130
|
+
incremental: false
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
debug$3(`unable to build .d.ts file for ${id}`);
|
|
134
|
+
if (project.parsedConfig.options.declaration !== true) return { error: `Unable to build .d.ts file for ${id}; Make sure the "declaration" option is set to true in ${project.tsconfigPath}` };
|
|
135
|
+
return { error: `Unable to build .d.ts file for ${id}; This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues` };
|
|
136
|
+
}
|
|
137
|
+
function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
|
|
138
|
+
let projectMap = context.projects.get(tsconfig);
|
|
139
|
+
if (projectMap) {
|
|
140
|
+
debug$3(`skip building projects for ${tsconfig}`);
|
|
141
|
+
return projectMap;
|
|
142
|
+
}
|
|
143
|
+
projectMap = buildProjects(fsSystem, tsconfig, force, sourcemap);
|
|
144
|
+
context.projects.set(tsconfig, projectMap);
|
|
145
|
+
return projectMap;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Use TypeScript compiler to build all projects referenced
|
|
149
|
+
*/
|
|
150
|
+
function buildProjects(fsSystem, tsconfig, force, sourcemap) {
|
|
151
|
+
debug$3(`start building projects for ${tsconfig}`);
|
|
152
|
+
const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
|
|
153
|
+
debug$3("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
|
|
154
|
+
const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
|
|
155
|
+
const builder = ts.createSolutionBuilder(host, [tsconfig], {
|
|
156
|
+
force,
|
|
157
|
+
verbose: true
|
|
158
|
+
});
|
|
159
|
+
const exitStatus = builder.build(void 0, void 0, void 0, (project) => {
|
|
160
|
+
debug$3(`transforming project ${project}`);
|
|
161
|
+
return customTransformers;
|
|
162
|
+
});
|
|
163
|
+
debug$3(`built solution for ${tsconfig} with exit status ${exitStatus}`);
|
|
164
|
+
const sourceFileToProjectMap = /* @__PURE__ */ new Map();
|
|
165
|
+
for (const project of projects) for (const fileName of project.parsedConfig.fileNames) sourceFileToProjectMap.set(fsSystem.resolvePath(fileName), project);
|
|
166
|
+
return sourceFileToProjectMap;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Collects all referenced projects from the given entry tsconfig file.
|
|
170
|
+
*/
|
|
171
|
+
function collectProjectGraph(rootTsconfigPath, fsSystem, force, sourcemap) {
|
|
172
|
+
const seen = /* @__PURE__ */ new Set();
|
|
173
|
+
const projects = [];
|
|
174
|
+
const stack = [fsSystem.resolvePath(rootTsconfigPath)];
|
|
175
|
+
while (true) {
|
|
176
|
+
const tsconfigPath = stack.pop();
|
|
177
|
+
if (!tsconfigPath) break;
|
|
178
|
+
if (seen.has(tsconfigPath)) continue;
|
|
179
|
+
seen.add(tsconfigPath);
|
|
180
|
+
const parsedConfig = parseTsconfig(tsconfigPath, fsSystem);
|
|
181
|
+
if (!parsedConfig) continue;
|
|
182
|
+
parsedConfig.options = patchCompilerOptions(parsedConfig.options, {
|
|
183
|
+
tsconfigPath,
|
|
184
|
+
force,
|
|
185
|
+
sourcemap
|
|
186
|
+
});
|
|
187
|
+
projects.push({
|
|
188
|
+
tsconfigPath,
|
|
189
|
+
parsedConfig
|
|
190
|
+
});
|
|
191
|
+
for (const ref of parsedConfig.projectReferences ?? []) stack.push(ts.resolveProjectReferencePath(ref));
|
|
192
|
+
}
|
|
193
|
+
return projects;
|
|
194
|
+
}
|
|
195
|
+
function parseTsconfig(tsconfigPath, fsSystem) {
|
|
196
|
+
const diagnostics = [];
|
|
197
|
+
const parsedConfig = ts.getParsedCommandLineOfConfigFile(tsconfigPath, void 0, {
|
|
198
|
+
...fsSystem,
|
|
199
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
200
|
+
diagnostics.push(diagnostic);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
|
|
204
|
+
return parsedConfig;
|
|
205
|
+
}
|
|
206
|
+
function patchCompilerOptions(options, extraOptions) {
|
|
207
|
+
const noEmit = options.noEmit ?? false;
|
|
208
|
+
const declaration = options.declaration ?? (options.composite ? true : false);
|
|
209
|
+
const declarationMap = options.declarationMap ?? false;
|
|
210
|
+
const shouldPrintWarning = extraOptions?.tsconfigPath && !extraOptions.force;
|
|
211
|
+
if (noEmit === true) {
|
|
212
|
+
options = {
|
|
213
|
+
...options,
|
|
214
|
+
noEmit: false
|
|
215
|
+
};
|
|
216
|
+
if (shouldPrintWarning) console.warn(`[rolldown-plugin-dts] ${extraOptions.tsconfigPath} has "noEmit" set to true. Please set it to false to generate declaration files.`);
|
|
217
|
+
}
|
|
218
|
+
if (declaration === false) {
|
|
219
|
+
options = {
|
|
220
|
+
...options,
|
|
221
|
+
declaration: true
|
|
222
|
+
};
|
|
223
|
+
if (shouldPrintWarning) console.warn(`[rolldown-plugin-dts] ${extraOptions.tsconfigPath} has "declaration" set to false. Please set it to true to generate declaration files.`);
|
|
224
|
+
}
|
|
225
|
+
if (declarationMap === false && extraOptions?.sourcemap) {
|
|
226
|
+
options = {
|
|
227
|
+
...options,
|
|
228
|
+
declarationMap: true
|
|
229
|
+
};
|
|
230
|
+
if (shouldPrintWarning) console.warn(`[rolldown-plugin-dts] ${extraOptions.tsconfigPath} has "declarationMap" set to false. Please set it to true if you want to generate source maps for declaration files.`);
|
|
231
|
+
}
|
|
232
|
+
return options;
|
|
233
|
+
}
|
|
234
|
+
const createProgramWithPatchedCompilerOptions = (rootNames, options, ...args) => {
|
|
235
|
+
return ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, patchCompilerOptions(options ?? {}, null), ...args);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/tsc/vue.ts
|
|
240
|
+
const debug$2 = Debug("rolldown-plugin-dts:vue");
|
|
241
|
+
let createVueProgram;
|
|
242
|
+
const require = createRequire(import.meta.url);
|
|
243
|
+
function loadVueLanguageTools() {
|
|
244
|
+
try {
|
|
245
|
+
const vueTscPath = require.resolve("vue-tsc");
|
|
246
|
+
const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
247
|
+
const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
248
|
+
return {
|
|
249
|
+
proxyCreateProgram,
|
|
250
|
+
vue
|
|
251
|
+
};
|
|
252
|
+
} catch (error) {
|
|
253
|
+
debug$2("vue language tools not found", error);
|
|
254
|
+
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function createVueProgramFactory(ts$1) {
|
|
258
|
+
if (createVueProgram) return createVueProgram;
|
|
259
|
+
debug$2("loading vue language tools");
|
|
260
|
+
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
261
|
+
return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
|
|
262
|
+
const $rootDir = options.options.$rootDir;
|
|
263
|
+
const $configRaw = options.options.$configRaw;
|
|
264
|
+
const resolver = new vue.CompilerOptionsResolver(ts$2.sys.fileExists);
|
|
265
|
+
resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
|
|
266
|
+
const vueOptions = resolver.build();
|
|
267
|
+
vue.writeGlobalTypes(vueOptions, ts$2.sys.writeFile);
|
|
268
|
+
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
|
|
269
|
+
return { languagePlugins: [vueLanguagePlugin] };
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/tsc/emit-compiler.ts
|
|
275
|
+
const debug$1 = Debug("rolldown-plugin-dts:tsc-compiler");
|
|
276
|
+
const defaultCompilerOptions = {
|
|
277
|
+
declaration: true,
|
|
278
|
+
noEmit: false,
|
|
279
|
+
emitDeclarationOnly: true,
|
|
280
|
+
noEmitOnError: true,
|
|
281
|
+
checkJs: false,
|
|
282
|
+
declarationMap: false,
|
|
283
|
+
skipLibCheck: true,
|
|
284
|
+
target: 99,
|
|
285
|
+
resolveJsonModule: true,
|
|
286
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
287
|
+
};
|
|
288
|
+
function createOrGetTsModule(options) {
|
|
289
|
+
const { id, entries, context = globalContext } = options;
|
|
290
|
+
const program = context.programs.find((program$1) => {
|
|
291
|
+
const roots = program$1.getRootFileNames();
|
|
292
|
+
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
293
|
+
return roots.includes(id);
|
|
294
|
+
});
|
|
295
|
+
if (program) {
|
|
296
|
+
const sourceFile = program.getSourceFile(id);
|
|
297
|
+
if (sourceFile) return {
|
|
298
|
+
program,
|
|
299
|
+
file: sourceFile
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
debug$1(`create program for module: ${id}`);
|
|
303
|
+
const module = createTsProgram(options);
|
|
304
|
+
debug$1(`created program for module: ${id}`);
|
|
305
|
+
context.programs.push(module.program);
|
|
306
|
+
return module;
|
|
307
|
+
}
|
|
308
|
+
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, cwd, context = globalContext }) {
|
|
309
|
+
const fsSystem = createFsSystem(context.files);
|
|
310
|
+
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
311
|
+
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
|
|
312
|
+
debug$1(`Creating program for root project: ${baseDir}`);
|
|
313
|
+
return createTsProgramFromParsedConfig({
|
|
314
|
+
parsedConfig,
|
|
315
|
+
fsSystem,
|
|
316
|
+
baseDir,
|
|
317
|
+
id,
|
|
318
|
+
entries,
|
|
319
|
+
vue
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue }) {
|
|
323
|
+
const compilerOptions = {
|
|
324
|
+
...defaultCompilerOptions,
|
|
325
|
+
...parsedConfig.options,
|
|
326
|
+
$configRaw: parsedConfig.raw,
|
|
327
|
+
$rootDir: baseDir
|
|
328
|
+
};
|
|
329
|
+
const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
|
|
330
|
+
const host = ts.createCompilerHost(compilerOptions, true);
|
|
331
|
+
const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
|
|
332
|
+
const program = createProgram({
|
|
333
|
+
rootNames,
|
|
334
|
+
options: compilerOptions,
|
|
335
|
+
host,
|
|
336
|
+
projectReferences: parsedConfig.projectReferences
|
|
337
|
+
});
|
|
338
|
+
const sourceFile = program.getSourceFile(id);
|
|
339
|
+
if (!sourceFile) {
|
|
340
|
+
debug$1(`source file not found in program: ${id}`);
|
|
341
|
+
const hasReferences = !!parsedConfig.projectReferences?.length;
|
|
342
|
+
if (hasReferences) throw new Error(`[rolldown-plugin-dts] Unable to load ${id}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`);
|
|
343
|
+
if (!fsSystem.fileExists(id)) {
|
|
344
|
+
debug$1(`File ${id} does not exist on disk.`);
|
|
345
|
+
throw new Error(`Source file not found: ${id}`);
|
|
346
|
+
} else {
|
|
347
|
+
debug$1(`File ${id} exists on disk.`);
|
|
348
|
+
throw new Error(`Unable to load file ${id} from the program. This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
program,
|
|
353
|
+
file: sourceFile
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function tscEmitCompiler(tscOptions) {
|
|
357
|
+
debug$1(`running tscEmitCompiler ${tscOptions.id}`);
|
|
358
|
+
const module = createOrGetTsModule(tscOptions);
|
|
359
|
+
const { program, file } = module;
|
|
360
|
+
debug$1(`got source file: ${file.fileName}`);
|
|
361
|
+
let dtsCode;
|
|
362
|
+
let map;
|
|
363
|
+
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
364
|
+
if (fileName.endsWith(".map")) {
|
|
365
|
+
debug$1(`emit dts sourcemap: ${fileName}`);
|
|
366
|
+
map = JSON.parse(code);
|
|
367
|
+
setSourceMapRoot(map, fileName, tscOptions.id);
|
|
368
|
+
} else {
|
|
369
|
+
debug$1(`emit dts: ${fileName}`);
|
|
370
|
+
dtsCode = code;
|
|
371
|
+
}
|
|
372
|
+
}, void 0, true, customTransformers, true);
|
|
373
|
+
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
374
|
+
if (!dtsCode && file.isDeclarationFile) {
|
|
375
|
+
debug$1("nothing was emitted. fallback to sourceFile text.");
|
|
376
|
+
dtsCode = file.getFullText();
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
code: dtsCode,
|
|
380
|
+
map
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/tsc/index.ts
|
|
386
|
+
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
387
|
+
debug(`loaded typescript: ${ts.version}`);
|
|
388
|
+
function tscEmit(tscOptions) {
|
|
389
|
+
debug(`running tscEmit ${tscOptions.id}`);
|
|
390
|
+
if (tscOptions.build) return tscEmitBuild(tscOptions);
|
|
391
|
+
else return tscEmitCompiler(tscOptions);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
//#endregion
|
|
395
|
+
export { tscEmit };
|
package/dist/tsc-context.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TscContext, createContext, globalContext, invalidateContextFile } from "./context-
|
|
2
|
-
export { TscContext, createContext, globalContext, invalidateContextFile };
|
|
1
|
+
import { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile } from "./context-DXNtAHtR.js";
|
|
2
|
+
export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
|
package/dist/tsc-context.js
CHANGED
package/dist/tsc-worker.d.ts
CHANGED
package/dist/tsc-worker.js
CHANGED
package/dist/tsc.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import { TscModule, TscOptions, TscResult, tscEmit } from "./index-
|
|
1
|
+
import "./context-DXNtAHtR.js";
|
|
2
|
+
import { TscModule, TscOptions, TscResult, tscEmit } from "./index-Cbz-60ZO.js";
|
|
3
3
|
export { TscModule, TscOptions, TscResult, tscEmit };
|
package/dist/tsc.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@babel/generator": "^7.28.3",
|
|
61
|
-
"@babel/parser": "^7.28.
|
|
62
|
-
"@babel/types": "^7.28.
|
|
61
|
+
"@babel/parser": "^7.28.4",
|
|
62
|
+
"@babel/types": "^7.28.4",
|
|
63
63
|
"ast-kit": "^2.1.2",
|
|
64
64
|
"birpc": "^2.5.0",
|
|
65
65
|
"debug": "^4.4.1",
|
|
@@ -72,22 +72,22 @@
|
|
|
72
72
|
"@sxzz/test-utils": "^0.5.10",
|
|
73
73
|
"@types/babel__generator": "^7.27.0",
|
|
74
74
|
"@types/debug": "^4.1.12",
|
|
75
|
-
"@types/node": "^24.3.
|
|
76
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
75
|
+
"@types/node": "^24.3.1",
|
|
76
|
+
"@typescript/native-preview": "7.0.0-dev.20250906.1",
|
|
77
77
|
"@volar/typescript": "^2.4.23",
|
|
78
78
|
"@vue/language-core": "^3.0.6",
|
|
79
79
|
"bumpp": "^10.2.3",
|
|
80
80
|
"diff": "^8.0.2",
|
|
81
|
-
"eslint": "^9.
|
|
81
|
+
"eslint": "^9.35.0",
|
|
82
82
|
"estree-walker": "^3.0.3",
|
|
83
83
|
"prettier": "^3.6.2",
|
|
84
|
-
"rolldown": "^1.0.0-beta.
|
|
84
|
+
"rolldown": "^1.0.0-beta.35",
|
|
85
85
|
"rollup-plugin-dts": "^6.2.3",
|
|
86
86
|
"tinyglobby": "^0.2.14",
|
|
87
87
|
"tsdown": "^0.14.2",
|
|
88
88
|
"typescript": "^5.9.2",
|
|
89
89
|
"vitest": "^3.2.4",
|
|
90
|
-
"vue": "^3.5.
|
|
90
|
+
"vue": "^3.5.21",
|
|
91
91
|
"vue-tsc": "^3.0.6"
|
|
92
92
|
},
|
|
93
93
|
"engines": {
|
package/dist/tsc-BJW5IMTs.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import { globalContext } from "./context-BG0dlajy.js";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import Debug from "debug";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import ts from "typescript";
|
|
6
|
-
|
|
7
|
-
//#region src/tsc/system.ts
|
|
8
|
-
const debug$2 = Debug("rolldown-plugin-dts:tsc-system");
|
|
9
|
-
/**
|
|
10
|
-
* A system that writes files to both memory and disk. It will try read files
|
|
11
|
-
* from memory firstly and fallback to disk if not found.
|
|
12
|
-
*/
|
|
13
|
-
function createFsSystem(files) {
|
|
14
|
-
return {
|
|
15
|
-
...ts.sys,
|
|
16
|
-
write(message) {
|
|
17
|
-
debug$2(message);
|
|
18
|
-
},
|
|
19
|
-
resolvePath(path$1) {
|
|
20
|
-
if (files.has(path$1)) return path$1;
|
|
21
|
-
return ts.sys.resolvePath(path$1);
|
|
22
|
-
},
|
|
23
|
-
directoryExists(directory) {
|
|
24
|
-
if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
|
|
25
|
-
return ts.sys.directoryExists(directory);
|
|
26
|
-
},
|
|
27
|
-
fileExists(fileName) {
|
|
28
|
-
if (files.has(fileName)) return true;
|
|
29
|
-
return ts.sys.fileExists(fileName);
|
|
30
|
-
},
|
|
31
|
-
readFile(fileName, ...args) {
|
|
32
|
-
if (files.has(fileName)) return files.get(fileName);
|
|
33
|
-
return ts.sys.readFile(fileName, ...args);
|
|
34
|
-
},
|
|
35
|
-
writeFile(path$1, data, ...args) {
|
|
36
|
-
files.set(path$1, data);
|
|
37
|
-
ts.sys.writeFile(path$1, data, ...args);
|
|
38
|
-
},
|
|
39
|
-
deleteFile(fileName, ...args) {
|
|
40
|
-
files.delete(fileName);
|
|
41
|
-
ts.sys.deleteFile?.(fileName, ...args);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function createMemorySystem(files) {
|
|
46
|
-
return {
|
|
47
|
-
...createFsSystem(files),
|
|
48
|
-
writeFile(path$1, data) {
|
|
49
|
-
files.set(path$1, data);
|
|
50
|
-
},
|
|
51
|
-
deleteFile(fileName) {
|
|
52
|
-
files.delete(fileName);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/tsc/vue.ts
|
|
59
|
-
const debug$1 = Debug("rolldown-plugin-dts:vue");
|
|
60
|
-
let createVueProgram;
|
|
61
|
-
const require = createRequire(import.meta.url);
|
|
62
|
-
function loadVueLanguageTools() {
|
|
63
|
-
try {
|
|
64
|
-
const vueTscPath = require.resolve("vue-tsc");
|
|
65
|
-
const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
66
|
-
const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
67
|
-
return {
|
|
68
|
-
proxyCreateProgram,
|
|
69
|
-
vue
|
|
70
|
-
};
|
|
71
|
-
} catch (error) {
|
|
72
|
-
debug$1("vue language tools not found", error);
|
|
73
|
-
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function createVueProgramFactory(ts$1) {
|
|
77
|
-
if (createVueProgram) return createVueProgram;
|
|
78
|
-
debug$1("loading vue language tools");
|
|
79
|
-
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
80
|
-
return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
|
|
81
|
-
const $rootDir = options.options.$rootDir;
|
|
82
|
-
const $configRaw = options.options.$configRaw;
|
|
83
|
-
const resolver = new vue.CompilerOptionsResolver(ts$2.sys.fileExists);
|
|
84
|
-
resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
|
|
85
|
-
const vueOptions = resolver.build();
|
|
86
|
-
vue.writeGlobalTypes(vueOptions, ts$2.sys.writeFile);
|
|
87
|
-
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
|
|
88
|
-
return { languagePlugins: [vueLanguagePlugin] };
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/tsc/index.ts
|
|
94
|
-
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
95
|
-
debug(`loaded typescript: ${ts.version}`);
|
|
96
|
-
const formatHost = {
|
|
97
|
-
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
98
|
-
getNewLine: () => ts.sys.newLine,
|
|
99
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
100
|
-
};
|
|
101
|
-
const defaultCompilerOptions = {
|
|
102
|
-
declaration: true,
|
|
103
|
-
noEmit: false,
|
|
104
|
-
emitDeclarationOnly: true,
|
|
105
|
-
noEmitOnError: true,
|
|
106
|
-
checkJs: false,
|
|
107
|
-
declarationMap: false,
|
|
108
|
-
skipLibCheck: true,
|
|
109
|
-
target: 99,
|
|
110
|
-
resolveJsonModule: true,
|
|
111
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
112
|
-
};
|
|
113
|
-
function createOrGetTsModule(options) {
|
|
114
|
-
const { id, entries, context = globalContext } = options;
|
|
115
|
-
const program = context.programs.find((program$1) => {
|
|
116
|
-
const roots = program$1.getRootFileNames();
|
|
117
|
-
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
118
|
-
return roots.includes(id);
|
|
119
|
-
});
|
|
120
|
-
if (program) {
|
|
121
|
-
const sourceFile = program.getSourceFile(id);
|
|
122
|
-
if (sourceFile) return {
|
|
123
|
-
program,
|
|
124
|
-
file: sourceFile
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
debug(`create program for module: ${id}`);
|
|
128
|
-
const module = createTsProgram(options);
|
|
129
|
-
debug(`created program for module: ${id}`);
|
|
130
|
-
context.programs.push(module.program);
|
|
131
|
-
return module;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Build the root project and all its dependencies projects.
|
|
135
|
-
* This is designed for a project (e.g. tsconfig.json) that has "references" to
|
|
136
|
-
* other composite projects (e.g., tsconfig.node.json and tsconfig.app.json).
|
|
137
|
-
* If `incremental` is `true`, the build result will be cached in the
|
|
138
|
-
* `.tsbuildinfo` file so that the next time the project is built (without
|
|
139
|
-
* changes) the build will be super fast. If `incremental` is `false`, the
|
|
140
|
-
* `.tsbuildinfo` file will only be written to the memory.
|
|
141
|
-
*/
|
|
142
|
-
function buildSolution(tsconfig, incremental, context) {
|
|
143
|
-
debug(`building projects for ${tsconfig} with incremental: ${incremental}`);
|
|
144
|
-
const system = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
145
|
-
const host = ts.createSolutionBuilderHost(system);
|
|
146
|
-
const builder = ts.createSolutionBuilder(host, [tsconfig], {
|
|
147
|
-
force: !incremental,
|
|
148
|
-
verbose: true
|
|
149
|
-
});
|
|
150
|
-
const projects = [];
|
|
151
|
-
const getCustomTransformers = (project) => {
|
|
152
|
-
projects.push(project);
|
|
153
|
-
return {};
|
|
154
|
-
};
|
|
155
|
-
const exitStatus = builder.build(void 0, void 0, void 0, getCustomTransformers);
|
|
156
|
-
debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
|
|
157
|
-
return Array.from(new Set(projects));
|
|
158
|
-
}
|
|
159
|
-
function findProjectContainingFile(projects, targetFile, fsSystem) {
|
|
160
|
-
const resolvedTargetFile = fsSystem.resolvePath(targetFile);
|
|
161
|
-
for (const tsconfigPath of projects) {
|
|
162
|
-
const parsedConfig = parseTsconfig(tsconfigPath, fsSystem);
|
|
163
|
-
if (parsedConfig && parsedConfig.fileNames.some((fileName) => fsSystem.resolvePath(fileName) === resolvedTargetFile)) return {
|
|
164
|
-
parsedConfig,
|
|
165
|
-
tsconfigPath
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function parseTsconfig(tsconfigPath, fsSystem) {
|
|
170
|
-
const diagnostics = [];
|
|
171
|
-
const parsedConfig = ts.getParsedCommandLineOfConfigFile(tsconfigPath, void 0, {
|
|
172
|
-
...fsSystem,
|
|
173
|
-
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
174
|
-
diagnostics.push(diagnostic);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
|
|
178
|
-
return parsedConfig;
|
|
179
|
-
}
|
|
180
|
-
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, build, incremental, vue, cwd, context = globalContext }) {
|
|
181
|
-
const fsSystem = createFsSystem(context.files);
|
|
182
|
-
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
183
|
-
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
|
|
184
|
-
if (tsconfig && build) {
|
|
185
|
-
const projectPaths = buildSolution(tsconfig, incremental, context);
|
|
186
|
-
debug(`collected projects: ${JSON.stringify(projectPaths)}`);
|
|
187
|
-
const project = findProjectContainingFile(projectPaths, id, fsSystem);
|
|
188
|
-
if (project) {
|
|
189
|
-
debug(`Creating program for project: ${project.tsconfigPath}`);
|
|
190
|
-
return createTsProgramFromParsedConfig({
|
|
191
|
-
parsedConfig: project.parsedConfig,
|
|
192
|
-
fsSystem,
|
|
193
|
-
baseDir: path.dirname(project.tsconfigPath),
|
|
194
|
-
id,
|
|
195
|
-
entries,
|
|
196
|
-
vue
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return createTsProgramFromParsedConfig({
|
|
201
|
-
parsedConfig,
|
|
202
|
-
fsSystem,
|
|
203
|
-
baseDir,
|
|
204
|
-
id,
|
|
205
|
-
entries,
|
|
206
|
-
vue
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue }) {
|
|
210
|
-
const compilerOptions = {
|
|
211
|
-
...defaultCompilerOptions,
|
|
212
|
-
...parsedConfig.options,
|
|
213
|
-
$configRaw: parsedConfig.raw,
|
|
214
|
-
$rootDir: baseDir
|
|
215
|
-
};
|
|
216
|
-
const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
|
|
217
|
-
const host = ts.createCompilerHost(compilerOptions, true);
|
|
218
|
-
host.readFile = fsSystem.readFile;
|
|
219
|
-
host.fileExists = fsSystem.fileExists;
|
|
220
|
-
host.directoryExists = fsSystem.directoryExists;
|
|
221
|
-
const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
|
|
222
|
-
const program = createProgram({
|
|
223
|
-
rootNames,
|
|
224
|
-
options: compilerOptions,
|
|
225
|
-
host,
|
|
226
|
-
projectReferences: parsedConfig.projectReferences
|
|
227
|
-
});
|
|
228
|
-
const sourceFile = program.getSourceFile(id);
|
|
229
|
-
if (!sourceFile) {
|
|
230
|
-
debug(`source file not found in program: ${id}`);
|
|
231
|
-
if (!fsSystem.fileExists(id)) {
|
|
232
|
-
debug(`File ${id} does not exist on disk.`);
|
|
233
|
-
throw new Error(`Source file not found: ${id}`);
|
|
234
|
-
} else {
|
|
235
|
-
debug(`File ${id} exists on disk.`);
|
|
236
|
-
throw new Error(`Unable to load file ${id} from the program. This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
program,
|
|
241
|
-
file: sourceFile
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function tscEmit(tscOptions) {
|
|
245
|
-
debug(`running tscEmit ${tscOptions.id}`);
|
|
246
|
-
const module = createOrGetTsModule(tscOptions);
|
|
247
|
-
const { program, file } = module;
|
|
248
|
-
debug(`got source file: ${file.fileName}`);
|
|
249
|
-
let dtsCode;
|
|
250
|
-
let map;
|
|
251
|
-
const stripPrivateFields = (ctx) => {
|
|
252
|
-
const visitor = (node) => {
|
|
253
|
-
if (ts.isPropertySignature(node) && ts.isPrivateIdentifier(node.name)) return ctx.factory.updatePropertySignature(node, node.modifiers, ctx.factory.createStringLiteral(node.name.text), node.questionToken, node.type);
|
|
254
|
-
return ts.visitEachChild(node, visitor, ctx);
|
|
255
|
-
};
|
|
256
|
-
return (sourceFile) => ts.visitNode(sourceFile, visitor, ts.isSourceFile) ?? sourceFile;
|
|
257
|
-
};
|
|
258
|
-
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
259
|
-
if (fileName.endsWith(".map")) {
|
|
260
|
-
debug(`emit dts sourcemap: ${fileName}`);
|
|
261
|
-
map = JSON.parse(code);
|
|
262
|
-
} else {
|
|
263
|
-
debug(`emit dts: ${fileName}`);
|
|
264
|
-
dtsCode = code;
|
|
265
|
-
}
|
|
266
|
-
}, void 0, true, { afterDeclarations: [stripPrivateFields] }, true);
|
|
267
|
-
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
268
|
-
if (!dtsCode && file.isDeclarationFile) {
|
|
269
|
-
debug("nothing was emitted. fallback to sourceFile text.");
|
|
270
|
-
dtsCode = file.getFullText();
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
code: dtsCode,
|
|
274
|
-
map
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
export { tscEmit };
|