vite-plugin-dts 3.2.0 → 3.3.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/README.md +332 -331
- package/README.zh-CN.md +332 -331
- package/dist/index.cjs +246 -170
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +248 -172
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import __cjs_mod__ from 'module';
|
|
|
5
5
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
7
7
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
8
|
-
import { resolve as resolve$1,
|
|
8
|
+
import { posix, resolve as resolve$1, isAbsolute, dirname, normalize, sep, relative, basename } from 'node:path';
|
|
9
9
|
import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
|
|
10
10
|
import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
|
|
11
11
|
import { cpus } from 'node:os';
|
|
@@ -15,12 +15,166 @@ import { createFilter } from '@rollup/pluginutils';
|
|
|
15
15
|
import { createProgram } from 'vue-tsc';
|
|
16
16
|
import debug from 'debug';
|
|
17
17
|
import { cyan, yellow, green } from 'kolorist';
|
|
18
|
-
import { ExtractorConfig,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
|
|
19
|
+
|
|
20
|
+
const windowsSlashRE = /\\+/g;
|
|
21
|
+
function slash(p) {
|
|
22
|
+
return p.replace(windowsSlashRE, "/");
|
|
23
|
+
}
|
|
24
|
+
function normalizePath(id) {
|
|
25
|
+
return posix.normalize(slash(id));
|
|
26
|
+
}
|
|
27
|
+
function resolve(...paths) {
|
|
28
|
+
return normalizePath(resolve$1(...paths));
|
|
29
|
+
}
|
|
30
|
+
function isNativeObj(value) {
|
|
31
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
32
|
+
}
|
|
33
|
+
function isRegExp(value) {
|
|
34
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
35
|
+
}
|
|
36
|
+
function isPromise(value) {
|
|
37
|
+
return !!value && (typeof value === "function" || typeof value === "object") && typeof value.then === "function";
|
|
38
|
+
}
|
|
39
|
+
async function wrapPromise(maybePromise) {
|
|
40
|
+
return isPromise(maybePromise) ? await maybePromise : maybePromise;
|
|
41
|
+
}
|
|
42
|
+
function ensureAbsolute(path, root) {
|
|
43
|
+
return normalizePath(path ? isAbsolute(path) ? path : resolve(root, path) : root);
|
|
44
|
+
}
|
|
45
|
+
function ensureArray(value) {
|
|
46
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
47
|
+
}
|
|
48
|
+
async function runParallel(maxConcurrency, source, iteratorFn) {
|
|
49
|
+
const ret = [];
|
|
50
|
+
const executing = [];
|
|
51
|
+
for (const item of source) {
|
|
52
|
+
const p = Promise.resolve().then(() => iteratorFn(item, source));
|
|
53
|
+
ret.push(p);
|
|
54
|
+
if (maxConcurrency <= source.length) {
|
|
55
|
+
const e = p.then(() => executing.splice(executing.indexOf(e), 1));
|
|
56
|
+
executing.push(e);
|
|
57
|
+
if (executing.length >= maxConcurrency) {
|
|
58
|
+
await Promise.race(executing);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return Promise.all(ret);
|
|
63
|
+
}
|
|
64
|
+
const speRE = /[\\/]/;
|
|
65
|
+
function queryPublicPath(paths) {
|
|
66
|
+
if (paths.length === 0) {
|
|
67
|
+
return "";
|
|
68
|
+
} else if (paths.length === 1) {
|
|
69
|
+
return dirname(paths[0]);
|
|
70
|
+
}
|
|
71
|
+
let publicPath = normalize(dirname(paths[0])) + sep;
|
|
72
|
+
let publicUnits = publicPath.split(speRE);
|
|
73
|
+
let index = publicUnits.length - 1;
|
|
74
|
+
for (const path of paths.slice(1)) {
|
|
75
|
+
if (!index) {
|
|
76
|
+
return publicPath;
|
|
77
|
+
}
|
|
78
|
+
const dirPath = normalize(dirname(path)) + sep;
|
|
79
|
+
if (dirPath.startsWith(publicPath)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const units = dirPath.split(speRE);
|
|
83
|
+
if (units.length < index) {
|
|
84
|
+
publicPath = dirPath;
|
|
85
|
+
publicUnits = units;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i <= index; ++i) {
|
|
89
|
+
if (publicUnits[i] !== units[i]) {
|
|
90
|
+
if (!i) {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
index = i - 1;
|
|
94
|
+
publicUnits = publicUnits.slice(0, index + 1);
|
|
95
|
+
publicPath = publicUnits.join(sep) + sep;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return publicPath.slice(0, -1);
|
|
101
|
+
}
|
|
102
|
+
function removeDirIfEmpty(dir) {
|
|
103
|
+
if (!existsSync(dir)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let onlyHasDir = true;
|
|
107
|
+
for (const file of readdirSync(dir)) {
|
|
108
|
+
const abs = resolve(dir, file);
|
|
109
|
+
if (lstatSync(abs).isDirectory()) {
|
|
110
|
+
if (!removeDirIfEmpty(abs)) {
|
|
111
|
+
onlyHasDir = false;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
onlyHasDir = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (onlyHasDir) {
|
|
118
|
+
rmdirSync(dir);
|
|
119
|
+
}
|
|
120
|
+
return onlyHasDir;
|
|
121
|
+
}
|
|
122
|
+
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
123
|
+
function base64Encode(number) {
|
|
124
|
+
if (number >= 0 && number < BASE64_ALPHABET.length) {
|
|
125
|
+
return BASE64_ALPHABET[number];
|
|
126
|
+
}
|
|
127
|
+
throw new TypeError("Base64 integer must be between 0 and 63: " + number);
|
|
128
|
+
}
|
|
129
|
+
const VLQ_BASE_SHIFT = 5;
|
|
130
|
+
const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
|
131
|
+
const VLQ_BASE_MASK = VLQ_BASE - 1;
|
|
132
|
+
const VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|
133
|
+
function toVLQSigned(number) {
|
|
134
|
+
return number < 0 ? (-number << 1) + 1 : (number << 1) + 0;
|
|
135
|
+
}
|
|
136
|
+
function base64VLQEncode(numbers) {
|
|
137
|
+
let encoded = "";
|
|
138
|
+
for (const number of numbers) {
|
|
139
|
+
let vlq = toVLQSigned(number);
|
|
140
|
+
let digit;
|
|
141
|
+
do {
|
|
142
|
+
digit = vlq & VLQ_BASE_MASK;
|
|
143
|
+
vlq >>>= VLQ_BASE_SHIFT;
|
|
144
|
+
if (vlq > 0) {
|
|
145
|
+
digit |= VLQ_CONTINUATION_BIT;
|
|
146
|
+
}
|
|
147
|
+
encoded += base64Encode(digit);
|
|
148
|
+
} while (vlq > 0);
|
|
149
|
+
}
|
|
150
|
+
return encoded;
|
|
151
|
+
}
|
|
152
|
+
const pkgPathCache = /* @__PURE__ */ new Map();
|
|
153
|
+
function tryGetPkgPath(beginPath) {
|
|
154
|
+
beginPath = normalizePath(beginPath);
|
|
155
|
+
if (pkgPathCache.has(beginPath)) {
|
|
156
|
+
return pkgPathCache.get(beginPath);
|
|
157
|
+
}
|
|
158
|
+
const pkgPath = resolve(beginPath, "package.json");
|
|
159
|
+
if (existsSync(pkgPath)) {
|
|
160
|
+
pkgPathCache.set(beginPath, pkgPath);
|
|
161
|
+
return pkgPath;
|
|
162
|
+
}
|
|
163
|
+
const parentDir = normalizePath(dirname(beginPath));
|
|
164
|
+
if (!parentDir || parentDir === beginPath) {
|
|
165
|
+
pkgPathCache.set(beginPath, void 0);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return tryGetPkgPath(parentDir);
|
|
169
|
+
}
|
|
170
|
+
function toCapitalCase(value) {
|
|
171
|
+
value = value.trim().replace(/\s+/g, "-");
|
|
172
|
+
value = value.replace(/-+(\w)/g, (_, char) => char ? char.toUpperCase() : "");
|
|
173
|
+
return (value.charAt(0).toLocaleUpperCase() + value.slice(1)).replace(
|
|
174
|
+
/[^\w]/g,
|
|
175
|
+
""
|
|
176
|
+
);
|
|
177
|
+
}
|
|
24
178
|
|
|
25
179
|
const dtsRE$1 = /\.d\.tsx?$/;
|
|
26
180
|
function rollupDeclarationFiles({
|
|
@@ -34,8 +188,6 @@ function rollupDeclarationFiles({
|
|
|
34
188
|
bundledPackages
|
|
35
189
|
}) {
|
|
36
190
|
const configObjectFullPath = resolve$1(root, "api-extractor.json");
|
|
37
|
-
const packageJsonLookup = new PackageJsonLookup();
|
|
38
|
-
const packageJsonFullPath = packageJsonLookup.tryGetPackageJsonFilePathFor(configObjectFullPath);
|
|
39
191
|
if (!dtsRE$1.test(fileName)) {
|
|
40
192
|
fileName += ".d.ts";
|
|
41
193
|
}
|
|
@@ -48,10 +200,7 @@ function rollupDeclarationFiles({
|
|
|
48
200
|
tsconfigFilePath: configPath,
|
|
49
201
|
overrideTsconfig: {
|
|
50
202
|
$schema: "http://json.schemastore.org/tsconfig",
|
|
51
|
-
compilerOptions
|
|
52
|
-
...compilerOptions,
|
|
53
|
-
target: "ESNext"
|
|
54
|
-
}
|
|
203
|
+
compilerOptions
|
|
55
204
|
}
|
|
56
205
|
},
|
|
57
206
|
apiReport: {
|
|
@@ -82,36 +231,15 @@ function rollupDeclarationFiles({
|
|
|
82
231
|
}
|
|
83
232
|
},
|
|
84
233
|
configObjectFullPath,
|
|
85
|
-
packageJsonFullPath
|
|
234
|
+
packageJsonFullPath: tryGetPkgPath(configObjectFullPath)
|
|
86
235
|
});
|
|
87
|
-
const
|
|
236
|
+
const result = Extractor.invoke(extractorConfig, {
|
|
88
237
|
localBuild: false,
|
|
89
238
|
showVerboseMessages: false,
|
|
90
|
-
typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0
|
|
91
|
-
});
|
|
92
|
-
const sourceMapper = new SourceMapper();
|
|
93
|
-
const messageRouter = new MessageRouter({
|
|
94
|
-
workingPackageFolder: root,
|
|
95
|
-
messageCallback: void 0,
|
|
96
|
-
messagesConfig: extractorConfig.messages,
|
|
97
|
-
showVerboseMessages: false,
|
|
98
239
|
showDiagnostics: false,
|
|
99
|
-
|
|
100
|
-
sourceMapper
|
|
101
|
-
});
|
|
102
|
-
const collector = new Collector({
|
|
103
|
-
program: compilerState.program,
|
|
104
|
-
messageRouter,
|
|
105
|
-
extractorConfig,
|
|
106
|
-
sourceMapper
|
|
240
|
+
typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0
|
|
107
241
|
});
|
|
108
|
-
|
|
109
|
-
DtsRollupGenerator.writeTypingsFile(
|
|
110
|
-
collector,
|
|
111
|
-
extractorConfig.publicTrimmedFilePath,
|
|
112
|
-
DtsRollupKind.PublicRelease,
|
|
113
|
-
extractorConfig.newlineKind
|
|
114
|
-
);
|
|
242
|
+
return result.succeeded;
|
|
115
243
|
}
|
|
116
244
|
|
|
117
245
|
const jsonRE = /\.json$/;
|
|
@@ -163,16 +291,36 @@ function VueResolver() {
|
|
|
163
291
|
supports(id) {
|
|
164
292
|
return vueRE.test(id);
|
|
165
293
|
},
|
|
166
|
-
transform({ id, program, service }) {
|
|
294
|
+
transform({ id, code, program, service }) {
|
|
167
295
|
const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
|
|
168
296
|
if (!sourceFile)
|
|
169
297
|
return [];
|
|
170
|
-
|
|
298
|
+
const outputs = service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
|
|
171
299
|
return {
|
|
172
300
|
path: file.name,
|
|
173
301
|
content: file.text
|
|
174
302
|
};
|
|
175
303
|
});
|
|
304
|
+
if (!program.getCompilerOptions().declarationMap)
|
|
305
|
+
return outputs;
|
|
306
|
+
const [beforeScript] = code.split(/\s*<script.*>/);
|
|
307
|
+
const beforeLines = beforeScript.split("\n").length;
|
|
308
|
+
for (const output of outputs) {
|
|
309
|
+
if (output.path.endsWith(".map")) {
|
|
310
|
+
try {
|
|
311
|
+
const sourceMap = JSON.parse(output.content);
|
|
312
|
+
sourceMap.sources = sourceMap.sources.map(
|
|
313
|
+
(source) => source.replace(/\.vue\.ts$/, ".vue")
|
|
314
|
+
);
|
|
315
|
+
if (beforeScript && beforeScript !== code && beforeLines) {
|
|
316
|
+
sourceMap.mappings = `${base64VLQEncode([0, 0, beforeLines, 0])};${sourceMap.mappings}`;
|
|
317
|
+
}
|
|
318
|
+
output.content = JSON.stringify(sourceMap);
|
|
319
|
+
} catch (e) {
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return outputs;
|
|
176
324
|
}
|
|
177
325
|
};
|
|
178
326
|
}
|
|
@@ -185,106 +333,6 @@ function parseResolvers(resolvers) {
|
|
|
185
333
|
return Array.from(nameMap.values());
|
|
186
334
|
}
|
|
187
335
|
|
|
188
|
-
const windowsSlashRE = /\\+/g;
|
|
189
|
-
function slash(p) {
|
|
190
|
-
return p.replace(windowsSlashRE, "/");
|
|
191
|
-
}
|
|
192
|
-
function normalizePath(id) {
|
|
193
|
-
return posix.normalize(slash(id));
|
|
194
|
-
}
|
|
195
|
-
function resolve(...paths) {
|
|
196
|
-
return normalizePath(resolve$1(...paths));
|
|
197
|
-
}
|
|
198
|
-
function isNativeObj(value) {
|
|
199
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
200
|
-
}
|
|
201
|
-
function isRegExp(value) {
|
|
202
|
-
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
203
|
-
}
|
|
204
|
-
function isPromise(value) {
|
|
205
|
-
return !!value && (typeof value === "function" || typeof value === "object") && typeof value.then === "function";
|
|
206
|
-
}
|
|
207
|
-
function ensureAbsolute(path, root) {
|
|
208
|
-
return normalizePath(path ? isAbsolute(path) ? path : resolve(root, path) : root);
|
|
209
|
-
}
|
|
210
|
-
function ensureArray(value) {
|
|
211
|
-
return Array.isArray(value) ? value : value ? [value] : [];
|
|
212
|
-
}
|
|
213
|
-
async function runParallel(maxConcurrency, source, iteratorFn) {
|
|
214
|
-
const ret = [];
|
|
215
|
-
const executing = [];
|
|
216
|
-
for (const item of source) {
|
|
217
|
-
const p = Promise.resolve().then(() => iteratorFn(item, source));
|
|
218
|
-
ret.push(p);
|
|
219
|
-
if (maxConcurrency <= source.length) {
|
|
220
|
-
const e = p.then(() => executing.splice(executing.indexOf(e), 1));
|
|
221
|
-
executing.push(e);
|
|
222
|
-
if (executing.length >= maxConcurrency) {
|
|
223
|
-
await Promise.race(executing);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return Promise.all(ret);
|
|
228
|
-
}
|
|
229
|
-
const speRE = /[\\/]/;
|
|
230
|
-
function queryPublicPath(paths) {
|
|
231
|
-
if (paths.length === 0) {
|
|
232
|
-
return "";
|
|
233
|
-
} else if (paths.length === 1) {
|
|
234
|
-
return dirname(paths[0]);
|
|
235
|
-
}
|
|
236
|
-
let publicPath = normalize(dirname(paths[0])) + sep;
|
|
237
|
-
let publicUnits = publicPath.split(speRE);
|
|
238
|
-
let index = publicUnits.length - 1;
|
|
239
|
-
for (const path of paths.slice(1)) {
|
|
240
|
-
if (!index) {
|
|
241
|
-
return publicPath;
|
|
242
|
-
}
|
|
243
|
-
const dirPath = normalize(dirname(path)) + sep;
|
|
244
|
-
if (dirPath.startsWith(publicPath)) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
const units = dirPath.split(speRE);
|
|
248
|
-
if (units.length < index) {
|
|
249
|
-
publicPath = dirPath;
|
|
250
|
-
publicUnits = units;
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
for (let i = 0; i <= index; ++i) {
|
|
254
|
-
if (publicUnits[i] !== units[i]) {
|
|
255
|
-
if (!i) {
|
|
256
|
-
return "";
|
|
257
|
-
}
|
|
258
|
-
index = i - 1;
|
|
259
|
-
publicUnits = publicUnits.slice(0, index + 1);
|
|
260
|
-
publicPath = publicUnits.join(sep) + sep;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return publicPath.slice(0, -1);
|
|
266
|
-
}
|
|
267
|
-
function removeDirIfEmpty(dir) {
|
|
268
|
-
if (!existsSync(dir)) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
let onlyHasDir = true;
|
|
272
|
-
for (const file of readdirSync(dir)) {
|
|
273
|
-
const abs = resolve(dir, file);
|
|
274
|
-
if (lstatSync(abs).isDirectory()) {
|
|
275
|
-
if (!removeDirIfEmpty(abs)) {
|
|
276
|
-
onlyHasDir = false;
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
onlyHasDir = false;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (onlyHasDir) {
|
|
283
|
-
rmdirSync(dir);
|
|
284
|
-
}
|
|
285
|
-
return onlyHasDir;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
336
|
const globSuffixRE = /^((?:.*\.[^.]+)|(?:\*+))$/;
|
|
289
337
|
function normalizeGlob(path) {
|
|
290
338
|
if (/[\\/]$/.test(path)) {
|
|
@@ -571,7 +619,7 @@ ${cyan(
|
|
|
571
619
|
const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
|
|
572
620
|
host = ts.createCompilerHost(compilerOptions, true);
|
|
573
621
|
program = createProgram({ host, rootNames, options: compilerOptions });
|
|
574
|
-
libName = libName || "_default";
|
|
622
|
+
libName = toCapitalCase(libName || "_default");
|
|
575
623
|
indexName = indexName || defaultIndex;
|
|
576
624
|
const maybeEmitted = (sourceFile) => {
|
|
577
625
|
return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
|
|
@@ -587,8 +635,7 @@ ${cyan(
|
|
|
587
635
|
logger.error(ts.formatDiagnostics(diagnostics, host));
|
|
588
636
|
}
|
|
589
637
|
if (typeof afterDiagnostic === "function") {
|
|
590
|
-
|
|
591
|
-
isPromise(result) && await result;
|
|
638
|
+
await wrapPromise(afterDiagnostic(diagnostics));
|
|
592
639
|
}
|
|
593
640
|
rootNames.forEach((file) => {
|
|
594
641
|
this.addWatchFile(file);
|
|
@@ -599,13 +646,14 @@ ${cyan(
|
|
|
599
646
|
},
|
|
600
647
|
async transform(code, id) {
|
|
601
648
|
let resolver;
|
|
602
|
-
id = normalizePath(id)
|
|
649
|
+
id = normalizePath(id);
|
|
603
650
|
if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id)) {
|
|
604
651
|
return;
|
|
605
652
|
}
|
|
606
653
|
const startTime = Date.now();
|
|
607
654
|
const outDir = outDirs[0];
|
|
608
655
|
const service = program.__vue.languageService;
|
|
656
|
+
id = id.split("?")[0];
|
|
609
657
|
rootFiles.delete(id);
|
|
610
658
|
if (resolver) {
|
|
611
659
|
const result = await resolver.transform({
|
|
@@ -640,11 +688,12 @@ ${cyan(
|
|
|
640
688
|
timeRecord += Date.now() - startTime;
|
|
641
689
|
},
|
|
642
690
|
watchChange(id) {
|
|
643
|
-
id = normalizePath(id)
|
|
691
|
+
id = normalizePath(id);
|
|
644
692
|
if (!host || !program || !filter(id) || !resolvers.find((r) => r.supports(id)) && !tjsRE.test(id)) {
|
|
645
693
|
return;
|
|
646
694
|
}
|
|
647
|
-
|
|
695
|
+
id = id.split("?")[0];
|
|
696
|
+
const sourceFile = host.getSourceFile(id, ts.ScriptTarget.ESNext);
|
|
648
697
|
if (sourceFile) {
|
|
649
698
|
rootFiles.add(sourceFile.fileName);
|
|
650
699
|
program.__vue.projectVersion++;
|
|
@@ -653,7 +702,7 @@ ${cyan(
|
|
|
653
702
|
}
|
|
654
703
|
},
|
|
655
704
|
async writeBundle() {
|
|
656
|
-
if (!program || bundled)
|
|
705
|
+
if (!host || !program || bundled)
|
|
657
706
|
return;
|
|
658
707
|
bundled = true;
|
|
659
708
|
bundleDebug("begin writeBundle");
|
|
@@ -662,7 +711,16 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
662
711
|
const startTime = Date.now();
|
|
663
712
|
const outDir = outDirs[0];
|
|
664
713
|
const emittedFiles = /* @__PURE__ */ new Map();
|
|
665
|
-
const writeOutput = async (path, content, outDir2) => {
|
|
714
|
+
const writeOutput = async (path, content, outDir2, record = true) => {
|
|
715
|
+
if (typeof beforeWriteFile === "function") {
|
|
716
|
+
const result = await wrapPromise(beforeWriteFile(path, content));
|
|
717
|
+
if (result === false)
|
|
718
|
+
return;
|
|
719
|
+
if (result) {
|
|
720
|
+
path = result.filePath || path;
|
|
721
|
+
content = result.content ?? content;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
666
724
|
path = normalizePath(path);
|
|
667
725
|
const dir = normalizePath(dirname(path));
|
|
668
726
|
if (strictOutput && !dir.startsWith(normalizePath(outDir2))) {
|
|
@@ -673,7 +731,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
673
731
|
await mkdir(dir, { recursive: true });
|
|
674
732
|
}
|
|
675
733
|
await writeFile(path, content, "utf-8");
|
|
676
|
-
emittedFiles.set(path, content);
|
|
734
|
+
record && emittedFiles.set(path, content);
|
|
677
735
|
};
|
|
678
736
|
const service = program.__vue.languageService;
|
|
679
737
|
const sourceFiles = program.getSourceFiles();
|
|
@@ -694,11 +752,13 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
694
752
|
}
|
|
695
753
|
}
|
|
696
754
|
bundleDebug("emit output patch");
|
|
755
|
+
const currentDir = host.getCurrentDirectory();
|
|
697
756
|
await runParallel(
|
|
698
757
|
cpus().length,
|
|
699
758
|
Array.from(outputFiles.entries()),
|
|
700
759
|
async ([path, content]) => {
|
|
701
760
|
const isMapFile = path.endsWith(".map");
|
|
761
|
+
const baseDir = dirname(path);
|
|
702
762
|
if (!isMapFile && content) {
|
|
703
763
|
content = clearPureImport ? removePureImport(content) : content;
|
|
704
764
|
content = transformAliasImport(path, content, aliases, aliasesExclude);
|
|
@@ -709,13 +769,20 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
709
769
|
relative(entryRoot, cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path)
|
|
710
770
|
);
|
|
711
771
|
content = cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content;
|
|
712
|
-
if (
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
772
|
+
if (isMapFile) {
|
|
773
|
+
try {
|
|
774
|
+
const sourceMap = JSON.parse(content);
|
|
775
|
+
sourceMap.sources = sourceMap.sources.map((source) => {
|
|
776
|
+
return normalizePath(
|
|
777
|
+
relative(
|
|
778
|
+
dirname(path),
|
|
779
|
+
resolve(currentDir, relative(publicRoot, baseDir), source)
|
|
780
|
+
)
|
|
781
|
+
);
|
|
782
|
+
});
|
|
783
|
+
content = JSON.stringify(sourceMap);
|
|
784
|
+
} catch (e) {
|
|
785
|
+
logger.warn(`${logPrefix} ${yellow("Processing source map fail:")} ${path}`);
|
|
719
786
|
}
|
|
720
787
|
}
|
|
721
788
|
await writeOutput(path, content, outDir);
|
|
@@ -723,14 +790,18 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
723
790
|
);
|
|
724
791
|
bundleDebug("write output");
|
|
725
792
|
if (insertTypesEntry || rollupTypes) {
|
|
726
|
-
const pkgPath =
|
|
727
|
-
|
|
793
|
+
const pkgPath = tryGetPkgPath(root);
|
|
794
|
+
let pkg;
|
|
795
|
+
try {
|
|
796
|
+
pkg = pkgPath && existsSync(pkgPath) ? JSON.parse(await readFile(pkgPath, "utf-8")) : {};
|
|
797
|
+
} catch (e) {
|
|
798
|
+
}
|
|
728
799
|
const entryNames = Object.keys(entries);
|
|
729
800
|
const types = pkg.types || pkg.typings || pkg.publishConfig?.types || pkg.publishConfig?.typings || (pkg.exports?.["."] || pkg.exports?.["./"])?.types;
|
|
730
801
|
const multiple = entryNames.length > 1;
|
|
731
802
|
const typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
|
|
732
803
|
for (const name of entryNames) {
|
|
733
|
-
|
|
804
|
+
const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
|
|
734
805
|
if (existsSync(path))
|
|
735
806
|
continue;
|
|
736
807
|
const index = resolve(
|
|
@@ -750,15 +821,6 @@ export default ${libName}
|
|
|
750
821
|
`;
|
|
751
822
|
}
|
|
752
823
|
}
|
|
753
|
-
if (typeof beforeWriteFile === "function") {
|
|
754
|
-
const result = beforeWriteFile(path, content);
|
|
755
|
-
if (result === false)
|
|
756
|
-
return;
|
|
757
|
-
if (result && isNativeObj(result)) {
|
|
758
|
-
path = result.filePath ?? path;
|
|
759
|
-
content = result.content ?? content;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
824
|
await writeOutput(path, content, outDir);
|
|
763
825
|
}
|
|
764
826
|
bundleDebug("insert index");
|
|
@@ -818,15 +880,29 @@ export default ${libName}
|
|
|
818
880
|
await runParallel(cpus().length, Array.from(emittedFiles), async ([wroteFile, content]) => {
|
|
819
881
|
const relativePath = relative(outDir, wroteFile);
|
|
820
882
|
await Promise.all(
|
|
821
|
-
extraOutDirs.map(async (
|
|
822
|
-
|
|
883
|
+
extraOutDirs.map(async (targetOutDir) => {
|
|
884
|
+
const path = resolve(targetOutDir, relativePath);
|
|
885
|
+
if (wroteFile.endsWith(".map")) {
|
|
886
|
+
const relativeOutDir = relative(outDir, targetOutDir);
|
|
887
|
+
if (relativeOutDir) {
|
|
888
|
+
try {
|
|
889
|
+
const sourceMap = JSON.parse(content);
|
|
890
|
+
sourceMap.sources = sourceMap.sources.map((source) => {
|
|
891
|
+
return normalizePath(relative(relativeOutDir, source));
|
|
892
|
+
});
|
|
893
|
+
content = JSON.stringify(sourceMap);
|
|
894
|
+
} catch (e) {
|
|
895
|
+
logger.warn(`${logPrefix} ${yellow("Processing source map fail:")} ${path}`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
await writeOutput(path, content, targetOutDir, false);
|
|
823
900
|
})
|
|
824
901
|
);
|
|
825
902
|
});
|
|
826
903
|
}
|
|
827
904
|
if (typeof afterBuild === "function") {
|
|
828
|
-
|
|
829
|
-
isPromise(result) && await result;
|
|
905
|
+
await wrapPromise(afterBuild());
|
|
830
906
|
}
|
|
831
907
|
bundleDebug("finish");
|
|
832
908
|
logger.info(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-dts",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "qmhc",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@microsoft/api-extractor": "^7.36.0",
|
|
57
57
|
"@rollup/pluginutils": "^5.0.2",
|
|
58
|
-
"@rushstack/node-core-library": "^3.59.4",
|
|
59
58
|
"@vue/language-core": "^1.8.1",
|
|
60
59
|
"debug": "^4.3.4",
|
|
61
60
|
"kolorist": "^1.8.0",
|
|
@@ -96,10 +95,12 @@
|
|
|
96
95
|
"vitest": "^0.32.2"
|
|
97
96
|
},
|
|
98
97
|
"peerDependencies": {
|
|
99
|
-
"typescript": "*"
|
|
100
|
-
},
|
|
101
|
-
"optionalDependencies": {
|
|
102
|
-
"rollup": "*",
|
|
98
|
+
"typescript": "*",
|
|
103
99
|
"vite": "*"
|
|
100
|
+
},
|
|
101
|
+
"peerDependenciesMeta": {
|
|
102
|
+
"vite": {
|
|
103
|
+
"optional": true
|
|
104
|
+
}
|
|
104
105
|
}
|
|
105
106
|
}
|