@quiteer/vite 0.0.6 → 0.1.0
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/bin/qvite.mjs +74 -7
- package/dist/index.d.mts +12 -8
- package/dist/index.mjs +6 -5906
- package/package.json +5 -5
- package/dist/bin/context-Db5EuGKU-B3vpL0eS.mjs +0 -24
- package/dist/bin/dist-BmyFpZwL.mjs +0 -7
- package/dist/bin/dist-BniM_x9D.mjs +0 -5256
- package/dist/bin/dist-Bvgk2hb8.mjs +0 -187
- package/dist/bin/dist-CjNY_432.mjs +0 -473
- package/dist/bin/dist-DQNZhGEj.mjs +0 -10562
- package/dist/bin/esm-CQYKr9An.mjs +0 -1557
- package/dist/bin/experimental-index-DiVJ_oZg.mjs +0 -71
- package/dist/bin/resolver-DymnxKPB-UI_9xIg2.mjs +0 -16
- package/dist/bin/src-BwxUhqZU-Dr1MNcyS.mjs +0 -5046
- package/dist/bin/tsc-TmK__neM.mjs +0 -406
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import { n as globalContext } from "./context-Db5EuGKU-B3vpL0eS.mjs";
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/rolldown-plugin-dts@0.17.4_rolldown@1.0.0-beta.47_typescript@5.9.3_vue-tsc@3.1.3_typescript@5.9.3_/node_modules/rolldown-plugin-dts/dist/tsc-Oohh5fvr.mjs
|
|
4
|
-
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
5
|
-
const { createRequire } = globalThis.process.getBuiltinModule("node:module");
|
|
6
|
-
const Debug = __cjs_require("debug");
|
|
7
|
-
const path = globalThis.process.getBuiltinModule("node:path");
|
|
8
|
-
const ts = __cjs_require("typescript");
|
|
9
|
-
const { pathToFileURL } = globalThis.process.getBuiltinModule("node:url");
|
|
10
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
11
|
-
const debug$3 = Debug("rolldown-plugin-dts:tsc-system");
|
|
12
|
-
/**
|
|
13
|
-
* A system that writes files to both memory and disk. It will try read files
|
|
14
|
-
* from memory firstly and fallback to disk if not found.
|
|
15
|
-
*/
|
|
16
|
-
function createFsSystem(files) {
|
|
17
|
-
return {
|
|
18
|
-
...ts.sys,
|
|
19
|
-
write(message) {
|
|
20
|
-
debug$3(message);
|
|
21
|
-
},
|
|
22
|
-
resolvePath(path$1) {
|
|
23
|
-
if (files.has(path$1)) return path$1;
|
|
24
|
-
return ts.sys.resolvePath(path$1);
|
|
25
|
-
},
|
|
26
|
-
directoryExists(directory) {
|
|
27
|
-
if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
|
|
28
|
-
return ts.sys.directoryExists(directory);
|
|
29
|
-
},
|
|
30
|
-
fileExists(fileName) {
|
|
31
|
-
if (files.has(fileName)) return true;
|
|
32
|
-
return ts.sys.fileExists(fileName);
|
|
33
|
-
},
|
|
34
|
-
readFile(fileName, ...args) {
|
|
35
|
-
if (files.has(fileName)) return files.get(fileName);
|
|
36
|
-
return ts.sys.readFile(fileName, ...args);
|
|
37
|
-
},
|
|
38
|
-
writeFile(path$1, data, ...args) {
|
|
39
|
-
files.set(path$1, data);
|
|
40
|
-
ts.sys.writeFile(path$1, data, ...args);
|
|
41
|
-
},
|
|
42
|
-
deleteFile(fileName, ...args) {
|
|
43
|
-
files.delete(fileName);
|
|
44
|
-
ts.sys.deleteFile?.(fileName, ...args);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function createMemorySystem(files) {
|
|
49
|
-
return {
|
|
50
|
-
...createFsSystem(files),
|
|
51
|
-
writeFile(path$1, data) {
|
|
52
|
-
files.set(path$1, data);
|
|
53
|
-
},
|
|
54
|
-
deleteFile(fileName) {
|
|
55
|
-
files.delete(fileName);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const formatHost = {
|
|
60
|
-
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
61
|
-
getNewLine: () => ts.sys.newLine,
|
|
62
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
63
|
-
};
|
|
64
|
-
const stripPrivateFields = (ctx) => {
|
|
65
|
-
const visitor = (node) => {
|
|
66
|
-
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);
|
|
67
|
-
return ts.visitEachChild(node, visitor, ctx);
|
|
68
|
-
};
|
|
69
|
-
return (sourceFile) => ts.visitNode(sourceFile, visitor, ts.isSourceFile) ?? sourceFile;
|
|
70
|
-
};
|
|
71
|
-
const customTransformers = { afterDeclarations: [stripPrivateFields] };
|
|
72
|
-
function setSourceMapRoot(map, originalFilePath, finalFilePath) {
|
|
73
|
-
if (!map) return;
|
|
74
|
-
if (map.sourceRoot) return;
|
|
75
|
-
const originalDir = path.posix.dirname(pathToFileURL(originalFilePath).pathname);
|
|
76
|
-
const finalDir = path.posix.dirname(pathToFileURL(finalFilePath).pathname);
|
|
77
|
-
if (originalDir !== finalDir) map.sourceRoot = path.posix.relative(finalDir, originalDir);
|
|
78
|
-
}
|
|
79
|
-
const debug$2 = Debug("rolldown-plugin-dts:tsc-build");
|
|
80
|
-
function tscEmitBuild(tscOptions) {
|
|
81
|
-
const { id, tsconfig, incremental, context = globalContext, sourcemap } = tscOptions;
|
|
82
|
-
debug$2(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
|
|
83
|
-
if (!tsconfig) return { error: "[rolldown-plugin-dts] build mode requires a tsconfig path" };
|
|
84
|
-
const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
85
|
-
const resolvedId = fsSystem.resolvePath(id);
|
|
86
|
-
if (resolvedId !== id) debug$2(`resolved id from ${id} to ${resolvedId}`);
|
|
87
|
-
const project = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap).get(resolvedId);
|
|
88
|
-
if (!project) {
|
|
89
|
-
debug$2(`unable to locate a project containing ${resolvedId}`);
|
|
90
|
-
return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
|
|
91
|
-
}
|
|
92
|
-
debug$2(`loaded project ${project.tsconfigPath} for ${id}`);
|
|
93
|
-
const ignoreCase = !fsSystem.useCaseSensitiveFileNames;
|
|
94
|
-
const outputFiles = ts.getOutputFileNames(project.parsedConfig, resolvedId, ignoreCase);
|
|
95
|
-
let code;
|
|
96
|
-
let map;
|
|
97
|
-
for (const outputFile of outputFiles) {
|
|
98
|
-
if (outputFile.endsWith(".d.ts")) {
|
|
99
|
-
if (!fsSystem.fileExists(outputFile)) {
|
|
100
|
-
console.warn(`[rolldown-plugin-dts] Unable to read file ${outputFile}`);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
code = fsSystem.readFile(outputFile);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (outputFile.endsWith(".d.ts.map")) {
|
|
107
|
-
if (!fsSystem.fileExists(outputFile)) continue;
|
|
108
|
-
const text = fsSystem.readFile(outputFile);
|
|
109
|
-
if (!text) {
|
|
110
|
-
console.warn(`[rolldown-plugin-dts] Unexpected sourcemap ${outputFile}`);
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
map = JSON.parse(text);
|
|
114
|
-
setSourceMapRoot(map, outputFile, resolvedId);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (code) return {
|
|
118
|
-
code,
|
|
119
|
-
map
|
|
120
|
-
};
|
|
121
|
-
if (incremental) {
|
|
122
|
-
debug$2(`incremental build failed`);
|
|
123
|
-
return tscEmitBuild({
|
|
124
|
-
...tscOptions,
|
|
125
|
-
incremental: false
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
debug$2(`unable to build .d.ts file for ${id}`);
|
|
129
|
-
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}` };
|
|
130
|
-
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` };
|
|
131
|
-
}
|
|
132
|
-
function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
|
|
133
|
-
let projectMap = context.projects.get(tsconfig);
|
|
134
|
-
if (projectMap) {
|
|
135
|
-
debug$2(`skip building projects for ${tsconfig}`);
|
|
136
|
-
return projectMap;
|
|
137
|
-
}
|
|
138
|
-
projectMap = buildProjects(fsSystem, tsconfig, force, sourcemap);
|
|
139
|
-
context.projects.set(tsconfig, projectMap);
|
|
140
|
-
return projectMap;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Use TypeScript compiler to build all projects referenced
|
|
144
|
-
*/
|
|
145
|
-
function buildProjects(fsSystem, tsconfig, force, sourcemap) {
|
|
146
|
-
debug$2(`start building projects for ${tsconfig}`);
|
|
147
|
-
const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
|
|
148
|
-
debug$2("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
|
|
149
|
-
const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
|
|
150
|
-
debug$2(`built solution for ${tsconfig} with exit status ${ts.createSolutionBuilder(host, [tsconfig], {
|
|
151
|
-
force,
|
|
152
|
-
verbose: true
|
|
153
|
-
}).build(void 0, void 0, void 0, (project) => {
|
|
154
|
-
debug$2(`transforming project ${project}`);
|
|
155
|
-
return customTransformers;
|
|
156
|
-
})}`);
|
|
157
|
-
const sourceFileToProjectMap = /* @__PURE__ */ new Map();
|
|
158
|
-
for (const project of projects) for (const fileName of project.parsedConfig.fileNames) sourceFileToProjectMap.set(fsSystem.resolvePath(fileName), project);
|
|
159
|
-
return sourceFileToProjectMap;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Collects all referenced projects from the given entry tsconfig file.
|
|
163
|
-
*/
|
|
164
|
-
function collectProjectGraph(rootTsconfigPath, fsSystem, force, sourcemap) {
|
|
165
|
-
const seen = /* @__PURE__ */ new Set();
|
|
166
|
-
const projects = [];
|
|
167
|
-
const stack = [fsSystem.resolvePath(rootTsconfigPath)];
|
|
168
|
-
while (true) {
|
|
169
|
-
const tsconfigPath = stack.pop();
|
|
170
|
-
if (!tsconfigPath) break;
|
|
171
|
-
if (seen.has(tsconfigPath)) continue;
|
|
172
|
-
seen.add(tsconfigPath);
|
|
173
|
-
const parsedConfig = parseTsconfig(tsconfigPath, fsSystem);
|
|
174
|
-
if (!parsedConfig) continue;
|
|
175
|
-
parsedConfig.options = patchCompilerOptions(parsedConfig.options, {
|
|
176
|
-
tsconfigPath,
|
|
177
|
-
force,
|
|
178
|
-
sourcemap
|
|
179
|
-
});
|
|
180
|
-
projects.push({
|
|
181
|
-
tsconfigPath,
|
|
182
|
-
parsedConfig
|
|
183
|
-
});
|
|
184
|
-
for (const ref of parsedConfig.projectReferences ?? []) stack.push(ts.resolveProjectReferencePath(ref));
|
|
185
|
-
}
|
|
186
|
-
return projects;
|
|
187
|
-
}
|
|
188
|
-
function parseTsconfig(tsconfigPath, fsSystem) {
|
|
189
|
-
const diagnostics = [];
|
|
190
|
-
const parsedConfig = ts.getParsedCommandLineOfConfigFile(tsconfigPath, void 0, {
|
|
191
|
-
...fsSystem,
|
|
192
|
-
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
193
|
-
diagnostics.push(diagnostic);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
|
|
197
|
-
return parsedConfig;
|
|
198
|
-
}
|
|
199
|
-
function patchCompilerOptions(options, extraOptions) {
|
|
200
|
-
const noEmit = options.noEmit ?? false;
|
|
201
|
-
const declaration = options.declaration ?? (options.composite ? true : false);
|
|
202
|
-
const declarationMap = options.declarationMap ?? false;
|
|
203
|
-
const shouldPrintWarning = extraOptions?.tsconfigPath && !extraOptions.force;
|
|
204
|
-
if (noEmit === true) {
|
|
205
|
-
options = {
|
|
206
|
-
...options,
|
|
207
|
-
noEmit: false
|
|
208
|
-
};
|
|
209
|
-
if (shouldPrintWarning) console.warn(`[rolldown-plugin-dts] ${extraOptions.tsconfigPath} has "noEmit" set to true. Please set it to false to generate declaration files.`);
|
|
210
|
-
}
|
|
211
|
-
if (declaration === false) {
|
|
212
|
-
options = {
|
|
213
|
-
...options,
|
|
214
|
-
declaration: true
|
|
215
|
-
};
|
|
216
|
-
if (shouldPrintWarning) console.warn(`[rolldown-plugin-dts] ${extraOptions.tsconfigPath} has "declaration" set to false. Please set it to true to generate declaration files.`);
|
|
217
|
-
}
|
|
218
|
-
if (declarationMap === false && extraOptions?.sourcemap) {
|
|
219
|
-
options = {
|
|
220
|
-
...options,
|
|
221
|
-
declarationMap: true
|
|
222
|
-
};
|
|
223
|
-
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.`);
|
|
224
|
-
}
|
|
225
|
-
return options;
|
|
226
|
-
}
|
|
227
|
-
const createProgramWithPatchedCompilerOptions = (rootNames, options, ...args) => {
|
|
228
|
-
return ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, patchCompilerOptions(options ?? {}, null), ...args);
|
|
229
|
-
};
|
|
230
|
-
function loadVueLanguageTools() {
|
|
231
|
-
const debug$4 = Debug("rolldown-plugin-dts:vue");
|
|
232
|
-
debug$4("loading vue language tools");
|
|
233
|
-
try {
|
|
234
|
-
const vueTscPath = __require.resolve("vue-tsc");
|
|
235
|
-
const { proxyCreateProgram } = __require(__require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
236
|
-
const vue = __require(__require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
237
|
-
const getLanguagePlugin = (ts$1, options) => {
|
|
238
|
-
const $rootDir = options.options.$rootDir;
|
|
239
|
-
const $configRaw = options.options.$configRaw;
|
|
240
|
-
const resolver = new vue.CompilerOptionsResolver(ts$1.sys.fileExists);
|
|
241
|
-
resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
|
|
242
|
-
const vueOptions = resolver.build();
|
|
243
|
-
vue.writeGlobalTypes(vueOptions, ts$1.sys.writeFile);
|
|
244
|
-
return vue.createVueLanguagePlugin(ts$1, options.options, vueOptions, (id) => id);
|
|
245
|
-
};
|
|
246
|
-
return {
|
|
247
|
-
proxyCreateProgram,
|
|
248
|
-
getLanguagePlugin
|
|
249
|
-
};
|
|
250
|
-
} catch (error) {
|
|
251
|
-
debug$4("vue language tools not found", error);
|
|
252
|
-
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
function loadTsMacro() {
|
|
256
|
-
const debug$4 = Debug("rolldown-plugin-dts:ts-macro");
|
|
257
|
-
debug$4("loading ts-macro language tools");
|
|
258
|
-
try {
|
|
259
|
-
const tsMacroPath = __require.resolve("@ts-macro/tsc");
|
|
260
|
-
const { proxyCreateProgram } = __require(__require.resolve("@volar/typescript", { paths: [tsMacroPath] }));
|
|
261
|
-
const tsMacro = __require(__require.resolve("@ts-macro/language-plugin", { paths: [tsMacroPath] }));
|
|
262
|
-
const { getOptions } = __require(__require.resolve("@ts-macro/language-plugin/options", { paths: [tsMacroPath] }));
|
|
263
|
-
const getLanguagePlugin = (ts$1, options) => {
|
|
264
|
-
const $rootDir = options.options.$rootDir;
|
|
265
|
-
return tsMacro.getLanguagePlugins(ts$1, options.options, getOptions(ts$1, $rootDir))[0];
|
|
266
|
-
};
|
|
267
|
-
return {
|
|
268
|
-
proxyCreateProgram,
|
|
269
|
-
getLanguagePlugin
|
|
270
|
-
};
|
|
271
|
-
} catch (error) {
|
|
272
|
-
debug$4("ts-macro language tools not found", error);
|
|
273
|
-
throw new Error("Failed to load ts-macro language tools. Please manually install @ts-macro/tsc.");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function createProgramFactory(ts$1, options) {
|
|
277
|
-
const vueLanguageTools = options.vue ? loadVueLanguageTools() : void 0;
|
|
278
|
-
const tsMacroLanguageTools = options.tsMacro ? loadTsMacro() : void 0;
|
|
279
|
-
const proxyCreateProgram = vueLanguageTools?.proxyCreateProgram || tsMacroLanguageTools?.proxyCreateProgram;
|
|
280
|
-
if (!proxyCreateProgram) return ts$1.createProgram;
|
|
281
|
-
return proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options$1) => {
|
|
282
|
-
const languagePlugins = [];
|
|
283
|
-
if (vueLanguageTools) languagePlugins.push(vueLanguageTools.getLanguagePlugin(ts$2, options$1));
|
|
284
|
-
if (tsMacroLanguageTools) languagePlugins.push(tsMacroLanguageTools.getLanguagePlugin(ts$2, options$1));
|
|
285
|
-
return { languagePlugins };
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
const debug$1 = Debug("rolldown-plugin-dts:tsc-compiler");
|
|
289
|
-
const defaultCompilerOptions = {
|
|
290
|
-
declaration: true,
|
|
291
|
-
noEmit: false,
|
|
292
|
-
emitDeclarationOnly: true,
|
|
293
|
-
noEmitOnError: true,
|
|
294
|
-
checkJs: false,
|
|
295
|
-
declarationMap: false,
|
|
296
|
-
skipLibCheck: true,
|
|
297
|
-
target: 99,
|
|
298
|
-
resolveJsonModule: true,
|
|
299
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
300
|
-
};
|
|
301
|
-
function createOrGetTsModule(options) {
|
|
302
|
-
const { id, entries, context = globalContext } = options;
|
|
303
|
-
const program = context.programs.find((program$1) => {
|
|
304
|
-
const roots = program$1.getRootFileNames();
|
|
305
|
-
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
306
|
-
return roots.includes(id);
|
|
307
|
-
});
|
|
308
|
-
if (program) {
|
|
309
|
-
const sourceFile = program.getSourceFile(id);
|
|
310
|
-
if (sourceFile) return {
|
|
311
|
-
program,
|
|
312
|
-
file: sourceFile
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
debug$1(`create program for module: ${id}`);
|
|
316
|
-
const module = createTsProgram(options);
|
|
317
|
-
debug$1(`created program for module: ${id}`);
|
|
318
|
-
context.programs.push(module.program);
|
|
319
|
-
return module;
|
|
320
|
-
}
|
|
321
|
-
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, tsMacro, cwd, context = globalContext }) {
|
|
322
|
-
const fsSystem = createFsSystem(context.files);
|
|
323
|
-
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
324
|
-
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
|
|
325
|
-
debug$1(`Creating program for root project: ${baseDir}`);
|
|
326
|
-
return createTsProgramFromParsedConfig({
|
|
327
|
-
parsedConfig,
|
|
328
|
-
fsSystem,
|
|
329
|
-
baseDir,
|
|
330
|
-
id,
|
|
331
|
-
entries,
|
|
332
|
-
vue,
|
|
333
|
-
tsMacro
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue, tsMacro }) {
|
|
337
|
-
const compilerOptions = {
|
|
338
|
-
...defaultCompilerOptions,
|
|
339
|
-
...parsedConfig.options,
|
|
340
|
-
$configRaw: parsedConfig.raw,
|
|
341
|
-
$rootDir: baseDir
|
|
342
|
-
};
|
|
343
|
-
const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
|
|
344
|
-
const host = ts.createCompilerHost(compilerOptions, true);
|
|
345
|
-
const program = createProgramFactory(ts, {
|
|
346
|
-
vue,
|
|
347
|
-
tsMacro
|
|
348
|
-
})({
|
|
349
|
-
rootNames,
|
|
350
|
-
options: compilerOptions,
|
|
351
|
-
host,
|
|
352
|
-
projectReferences: parsedConfig.projectReferences
|
|
353
|
-
});
|
|
354
|
-
const sourceFile = program.getSourceFile(id);
|
|
355
|
-
if (!sourceFile) {
|
|
356
|
-
debug$1(`source file not found in program: ${id}`);
|
|
357
|
-
if (!!parsedConfig.projectReferences?.length) 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?`);
|
|
358
|
-
if (fsSystem.fileExists(id)) {
|
|
359
|
-
debug$1(`File ${id} exists on disk.`);
|
|
360
|
-
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`);
|
|
361
|
-
} else {
|
|
362
|
-
debug$1(`File ${id} does not exist on disk.`);
|
|
363
|
-
throw new Error(`Source file not found: ${id}`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
program,
|
|
368
|
-
file: sourceFile
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
function tscEmitCompiler(tscOptions) {
|
|
372
|
-
debug$1(`running tscEmitCompiler ${tscOptions.id}`);
|
|
373
|
-
const { program, file } = createOrGetTsModule(tscOptions);
|
|
374
|
-
debug$1(`got source file: ${file.fileName}`);
|
|
375
|
-
let dtsCode;
|
|
376
|
-
let map;
|
|
377
|
-
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
378
|
-
if (fileName.endsWith(".map")) {
|
|
379
|
-
debug$1(`emit dts sourcemap: ${fileName}`);
|
|
380
|
-
map = JSON.parse(code);
|
|
381
|
-
setSourceMapRoot(map, fileName, tscOptions.id);
|
|
382
|
-
} else {
|
|
383
|
-
debug$1(`emit dts: ${fileName}`);
|
|
384
|
-
dtsCode = code;
|
|
385
|
-
}
|
|
386
|
-
}, void 0, true, customTransformers, true);
|
|
387
|
-
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
388
|
-
if (!dtsCode && file.isDeclarationFile) {
|
|
389
|
-
debug$1("nothing was emitted. fallback to sourceFile text.");
|
|
390
|
-
dtsCode = file.getFullText();
|
|
391
|
-
}
|
|
392
|
-
return {
|
|
393
|
-
code: dtsCode,
|
|
394
|
-
map
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
398
|
-
debug(`loaded typescript: ${ts.version}`);
|
|
399
|
-
function tscEmit(tscOptions) {
|
|
400
|
-
debug(`running tscEmit ${tscOptions.id}`);
|
|
401
|
-
if (tscOptions.build) return tscEmitBuild(tscOptions);
|
|
402
|
-
else return tscEmitCompiler(tscOptions);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
//#endregion
|
|
406
|
-
export { tscEmit };
|