vite-plugin-dts 4.0.3 → 4.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/README.md +60 -51
- package/README.zh-CN.md +10 -1
- package/dist/index.cjs +21 -12
- package/dist/index.d.cts +50 -48
- package/dist/index.d.mts +50 -48
- package/dist/index.d.ts +50 -48
- package/dist/index.mjs +21 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,6 +53,14 @@ If you want to merge all declarations into one file, just specify `rollupTypes:
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
If you start with official Vite template, you should specify the `tsconfigPath`:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
{
|
|
60
|
+
plugins: [dts({ tsconfigPath: './tsconfig.app.json' })]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
56
64
|
Starting with `3.0.0`, you can use this plugin with Rollup.
|
|
57
65
|
|
|
58
66
|
## FAQ
|
|
@@ -148,145 +156,146 @@ export interface Resolver {
|
|
|
148
156
|
root: string,
|
|
149
157
|
outDir: string,
|
|
150
158
|
host: ts.CompilerHost,
|
|
151
|
-
program: ts.Program
|
|
152
|
-
service: ts.LanguageService
|
|
159
|
+
program: ts.Program
|
|
153
160
|
}) => MaybePromise<{ path: string, content: string }[]>
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
export interface PluginOptions {
|
|
157
164
|
/**
|
|
158
|
-
* Specify root directory
|
|
165
|
+
* Specify root directory.
|
|
159
166
|
*
|
|
160
|
-
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
167
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup.
|
|
161
168
|
*/
|
|
162
169
|
root?: string,
|
|
163
170
|
|
|
164
171
|
/**
|
|
165
|
-
* Output directory for declaration files
|
|
172
|
+
* Output directory for declaration files.
|
|
166
173
|
*
|
|
167
|
-
* Can be an array to output to multiple directories
|
|
174
|
+
* Can be an array to output to multiple directories.
|
|
168
175
|
*
|
|
169
|
-
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
176
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup.
|
|
170
177
|
*/
|
|
171
178
|
outDir?: string | string[],
|
|
172
179
|
|
|
173
180
|
/**
|
|
174
|
-
* Override root path of entry files (useful in monorepos)
|
|
181
|
+
* Override root path of entry files (useful in monorepos).
|
|
175
182
|
*
|
|
176
|
-
* The output path of each file will be calculated based on the value provided
|
|
183
|
+
* The output path of each file will be calculated based on the value provided.
|
|
177
184
|
*
|
|
178
|
-
* The default is the smallest public path for all source files
|
|
185
|
+
* The default is the smallest public path for all source files.
|
|
179
186
|
*/
|
|
180
187
|
entryRoot?: string,
|
|
181
188
|
|
|
182
189
|
/**
|
|
183
|
-
* Restrict declaration files output to `outDir
|
|
190
|
+
* Restrict declaration files output to `outDir`.
|
|
184
191
|
*
|
|
185
|
-
* If true, generated declaration files outside `outDir` will be ignored
|
|
192
|
+
* If true, generated declaration files outside `outDir` will be ignored.
|
|
186
193
|
*
|
|
187
194
|
* @default true
|
|
188
195
|
*/
|
|
189
196
|
strictOutput?: boolean,
|
|
190
197
|
|
|
191
198
|
/**
|
|
192
|
-
* Override compilerOptions
|
|
199
|
+
* Override compilerOptions.
|
|
193
200
|
*
|
|
194
201
|
* @default null
|
|
195
202
|
*/
|
|
196
203
|
compilerOptions?: ts.CompilerOptions | null,
|
|
197
204
|
|
|
198
205
|
/**
|
|
199
|
-
* Specify tsconfig.json path
|
|
206
|
+
* Specify tsconfig.json path.
|
|
200
207
|
*
|
|
201
|
-
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
208
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json.
|
|
202
209
|
*
|
|
203
|
-
* If not specified, plugin will find config file from root
|
|
210
|
+
* If not specified, plugin will find config file from root.
|
|
204
211
|
*/
|
|
205
212
|
tsconfigPath?: string,
|
|
206
213
|
|
|
207
214
|
/**
|
|
208
|
-
* Specify custom resolvers
|
|
215
|
+
* Specify custom resolvers.
|
|
209
216
|
*
|
|
210
217
|
* @default []
|
|
211
218
|
*/
|
|
212
219
|
resolvers?: Resolver[],
|
|
213
220
|
|
|
214
221
|
/**
|
|
215
|
-
* Parsing `paths` of tsconfig.json to aliases
|
|
222
|
+
* Parsing `paths` of tsconfig.json to aliases.
|
|
216
223
|
*
|
|
217
|
-
* Note that these aliases only use for declaration files
|
|
224
|
+
* Note that these aliases only use for declaration files.
|
|
218
225
|
*
|
|
219
226
|
* @default true
|
|
220
|
-
* @remarks Only use first replacement of each path
|
|
227
|
+
* @remarks Only use first replacement of each path.
|
|
221
228
|
*/
|
|
222
229
|
pathsToAliases?: boolean,
|
|
223
230
|
|
|
224
231
|
/**
|
|
225
|
-
* Set which paths should be excluded when transforming aliases
|
|
232
|
+
* Set which paths should be excluded when transforming aliases.
|
|
226
233
|
*
|
|
227
234
|
* @default []
|
|
228
235
|
*/
|
|
229
236
|
aliasesExclude?: (string | RegExp)[],
|
|
230
237
|
|
|
231
238
|
/**
|
|
232
|
-
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
239
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'.
|
|
240
|
+
*
|
|
241
|
+
* If there is a duplicate name after transform, it will fall back to the original name.
|
|
233
242
|
*
|
|
234
243
|
* @default false
|
|
235
244
|
*/
|
|
236
245
|
cleanVueFileName?: boolean,
|
|
237
246
|
|
|
238
247
|
/**
|
|
239
|
-
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
248
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`).
|
|
240
249
|
*
|
|
241
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
250
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
242
251
|
*
|
|
243
252
|
* @default false
|
|
244
253
|
*/
|
|
245
254
|
staticImport?: boolean,
|
|
246
255
|
|
|
247
256
|
/**
|
|
248
|
-
* Override `include` glob (relative to root)
|
|
257
|
+
* Override `include` glob (relative to root).
|
|
249
258
|
*
|
|
250
|
-
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
259
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located).
|
|
251
260
|
*/
|
|
252
261
|
include?: string | string[],
|
|
253
262
|
|
|
254
263
|
/**
|
|
255
|
-
* Override `exclude` glob
|
|
264
|
+
* Override `exclude` glob.
|
|
256
265
|
*
|
|
257
266
|
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
258
267
|
*/
|
|
259
268
|
exclude?: string | string[],
|
|
260
269
|
|
|
261
270
|
/**
|
|
262
|
-
* Whether to remove `import 'xxx'
|
|
271
|
+
* Whether to remove `import 'xxx'`.
|
|
263
272
|
*
|
|
264
273
|
* @default true
|
|
265
274
|
*/
|
|
266
275
|
clearPureImport?: boolean,
|
|
267
276
|
|
|
268
277
|
/**
|
|
269
|
-
* Whether to generate types entry file(s)
|
|
278
|
+
* Whether to generate types entry file(s).
|
|
270
279
|
*
|
|
271
|
-
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts
|
|
280
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`.
|
|
272
281
|
*
|
|
273
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
282
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
274
283
|
*
|
|
275
284
|
* @default false
|
|
276
285
|
*/
|
|
277
286
|
insertTypesEntry?: boolean,
|
|
278
287
|
|
|
279
288
|
/**
|
|
280
|
-
* Rollup type declaration files after emitting them
|
|
289
|
+
* Rollup type declaration files after emitting them.
|
|
281
290
|
*
|
|
282
|
-
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
291
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation.
|
|
283
292
|
*
|
|
284
293
|
* @default false
|
|
285
294
|
*/
|
|
286
295
|
rollupTypes?: boolean,
|
|
287
296
|
|
|
288
297
|
/**
|
|
289
|
-
* Bundled packages for `@microsoft/api-extractor
|
|
298
|
+
* Bundled packages for `@microsoft/api-extractor`.
|
|
290
299
|
*
|
|
291
300
|
* @default []
|
|
292
301
|
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
@@ -294,7 +303,7 @@ export interface PluginOptions {
|
|
|
294
303
|
bundledPackages?: string[],
|
|
295
304
|
|
|
296
305
|
/**
|
|
297
|
-
* Override the config of `@microsoft/api-extractor
|
|
306
|
+
* Override the config of `@microsoft/api-extractor`.
|
|
298
307
|
*
|
|
299
308
|
* @default null
|
|
300
309
|
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
@@ -302,7 +311,7 @@ export interface PluginOptions {
|
|
|
302
311
|
rollupConfig?: RollupConfig,
|
|
303
312
|
|
|
304
313
|
/**
|
|
305
|
-
* Override the invoke options of `@microsoft/api-extractor
|
|
314
|
+
* Override the invoke options of `@microsoft/api-extractor`.
|
|
306
315
|
*
|
|
307
316
|
* @default null
|
|
308
317
|
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
@@ -310,44 +319,44 @@ export interface PluginOptions {
|
|
|
310
319
|
rollupOptions?: IExtractorInvokeOptions,
|
|
311
320
|
|
|
312
321
|
/**
|
|
313
|
-
* Whether to copy .d.ts source files to `outDir
|
|
322
|
+
* Whether to copy .d.ts source files to `outDir`.
|
|
314
323
|
*
|
|
315
324
|
* @default false
|
|
316
|
-
* @remarks Before 2.0, the default was `true
|
|
325
|
+
* @remarks Before 2.0, the default was `true`.
|
|
317
326
|
*/
|
|
318
327
|
copyDtsFiles?: boolean,
|
|
319
328
|
|
|
320
329
|
/**
|
|
321
|
-
* Whether to emit declaration files only
|
|
330
|
+
* Whether to emit declaration files only.
|
|
322
331
|
*
|
|
323
|
-
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
332
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed.
|
|
324
333
|
*
|
|
325
334
|
* @default false
|
|
326
335
|
*/
|
|
327
336
|
declarationOnly?: boolean,
|
|
328
337
|
|
|
329
338
|
/**
|
|
330
|
-
* Logging level for this plugin
|
|
339
|
+
* Logging level for this plugin.
|
|
331
340
|
*
|
|
332
|
-
* Defaults to the 'logLevel' property of your Vite config
|
|
341
|
+
* Defaults to the 'logLevel' property of your Vite config.
|
|
333
342
|
*/
|
|
334
343
|
logLevel?: LogLevel,
|
|
335
344
|
|
|
336
345
|
/**
|
|
337
|
-
* Hook called after diagnostic is emitted
|
|
346
|
+
* Hook called after diagnostic is emitted.
|
|
338
347
|
*
|
|
339
|
-
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
348
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error.
|
|
340
349
|
*
|
|
341
350
|
* @default () => {}
|
|
342
351
|
*/
|
|
343
352
|
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
|
|
344
353
|
|
|
345
354
|
/**
|
|
346
|
-
* Hook called prior to writing each declaration file
|
|
355
|
+
* Hook called prior to writing each declaration file.
|
|
347
356
|
*
|
|
348
|
-
* This allows you to transform the path or content
|
|
357
|
+
* This allows you to transform the path or content.
|
|
349
358
|
*
|
|
350
|
-
* The file will be skipped when the return value `false` or `Promise<false
|
|
359
|
+
* The file will be skipped when the return value `false` or `Promise<false>`.
|
|
351
360
|
*
|
|
352
361
|
* @default () => {}
|
|
353
362
|
*/
|
|
@@ -364,20 +373,20 @@ export interface PluginOptions {
|
|
|
364
373
|
>,
|
|
365
374
|
|
|
366
375
|
/**
|
|
367
|
-
* Hook called after rolling up declaration files
|
|
376
|
+
* Hook called after rolling up declaration files.
|
|
368
377
|
*
|
|
369
378
|
* @default () => {}
|
|
370
379
|
*/
|
|
371
380
|
afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
|
|
372
381
|
|
|
373
382
|
/**
|
|
374
|
-
* Hook called after all declaration files are written
|
|
383
|
+
* Hook called after all declaration files are written.
|
|
375
384
|
*
|
|
376
|
-
* It will be received a map (path -> content) that records those emitted files
|
|
385
|
+
* It will be received a map (path -> content) that records those emitted files.
|
|
377
386
|
*
|
|
378
387
|
* @default () => {}
|
|
379
388
|
*/
|
|
380
|
-
afterBuild?: () => MaybePromise<void>
|
|
389
|
+
afterBuild?: (emittedFiles: Map<string, string>) => MaybePromise<void>
|
|
381
390
|
}
|
|
382
391
|
```
|
|
383
392
|
|
package/README.zh-CN.md
CHANGED
|
@@ -53,6 +53,14 @@ export default defineConfig({
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
如果你从 Vite 官方模板开始,你应该指定 `tsconfigPath`:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
{
|
|
60
|
+
plugins: [dts({ tsconfigPath: './tsconfig.app.json' })]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
56
64
|
从 `3.0.0` 开始,你可以在 Rollup 中使用该插件。
|
|
57
65
|
|
|
58
66
|
## 常见问题
|
|
@@ -149,7 +157,6 @@ export interface Resolver {
|
|
|
149
157
|
outDir: string,
|
|
150
158
|
host: ts.CompilerHost,
|
|
151
159
|
program: ts.Program,
|
|
152
|
-
service: ts.LanguageService
|
|
153
160
|
}) => MaybePromise<{ path: string, content: string }[]>
|
|
154
161
|
}
|
|
155
162
|
|
|
@@ -231,6 +238,8 @@ export interface PluginOptions {
|
|
|
231
238
|
/**
|
|
232
239
|
* 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
233
240
|
*
|
|
241
|
+
* 如果转换后出现重名,将会回退到原来的名字。
|
|
242
|
+
*
|
|
234
243
|
* @default false
|
|
235
244
|
*/
|
|
236
245
|
cleanVueFileName?: boolean,
|
package/dist/index.cjs
CHANGED
|
@@ -9,13 +9,13 @@ const node_os = require('node:os');
|
|
|
9
9
|
const languageCore = require('@vue/language-core');
|
|
10
10
|
const typescript = require('@volar/typescript');
|
|
11
11
|
const ts = require('typescript');
|
|
12
|
+
const localPkg = require('local-pkg');
|
|
12
13
|
const vueTsc = require('vue-tsc');
|
|
13
14
|
const pluginutils = require('@rollup/pluginutils');
|
|
14
15
|
const debug = require('debug');
|
|
15
16
|
const kolorist = require('kolorist');
|
|
16
17
|
const apiExtractor = require('@microsoft/api-extractor');
|
|
17
18
|
const node_module = require('node:module');
|
|
18
|
-
const localPkg = require('local-pkg');
|
|
19
19
|
const compareVersions = require('compare-versions');
|
|
20
20
|
const MagicString = require('magic-string');
|
|
21
21
|
|
|
@@ -26,7 +26,12 @@ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
|
26
26
|
const debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
|
|
27
27
|
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
let hasVue = false;
|
|
30
|
+
try {
|
|
31
|
+
hasVue = !!(localPkg.getPackageInfoSync("vue") ?? localPkg.getPackageInfoSync("svelte", { paths: [localPkg.resolveModule("svelte") || process.cwd()] }));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
}
|
|
34
|
+
const _createProgram = !hasVue ? ts__default.createProgram : typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
|
|
30
35
|
const { configFilePath } = options.options;
|
|
31
36
|
const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
|
|
32
37
|
if (options.host) {
|
|
@@ -48,7 +53,7 @@ const _createProgram = typescript.proxyCreateProgram(ts__default, ts__default.cr
|
|
|
48
53
|
);
|
|
49
54
|
return [vueLanguagePlugin];
|
|
50
55
|
});
|
|
51
|
-
const createProgram = (options) => {
|
|
56
|
+
const createProgram = !hasVue ? ts__default.createProgram : (options) => {
|
|
52
57
|
const program = _createProgram(options);
|
|
53
58
|
const emit = program.emit;
|
|
54
59
|
program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
|
|
@@ -328,7 +333,7 @@ function parseTsAliases(basePath, paths) {
|
|
|
328
333
|
const result = [];
|
|
329
334
|
for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
|
|
330
335
|
const find = new RegExp(
|
|
331
|
-
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(
|
|
336
|
+
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
|
|
332
337
|
);
|
|
333
338
|
let index = 1;
|
|
334
339
|
result.push({
|
|
@@ -448,7 +453,7 @@ function querySvelteVersion() {
|
|
|
448
453
|
try {
|
|
449
454
|
const version = localPkg.getPackageInfoSync("svelte")?.version ?? localPkg.getPackageInfoSync("svelte", { paths: [localPkg.resolveModule("svelte") || process.cwd()] })?.version;
|
|
450
455
|
lowerVersion = version ? compareVersions.compare(version, "4.0.0", "<") : false;
|
|
451
|
-
} catch {
|
|
456
|
+
} catch (e) {
|
|
452
457
|
lowerVersion = false;
|
|
453
458
|
}
|
|
454
459
|
}
|
|
@@ -796,8 +801,9 @@ function dtsPlugin(options = {}) {
|
|
|
796
801
|
};
|
|
797
802
|
const rollupConfig = { ...options.rollupConfig || {} };
|
|
798
803
|
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
799
|
-
const cleanPath = (path) => {
|
|
800
|
-
|
|
804
|
+
const cleanPath = (path, emittedFiles) => {
|
|
805
|
+
const newPath = path.replace(".vue.d.ts", ".d.ts");
|
|
806
|
+
return !emittedFiles.has(newPath) && cleanVueFileName ? newPath : path;
|
|
801
807
|
};
|
|
802
808
|
return {
|
|
803
809
|
name: pluginName,
|
|
@@ -1167,7 +1173,10 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
1167
1173
|
const entryNames = Object.keys(entries);
|
|
1168
1174
|
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
1169
1175
|
const multiple = entryNames.length > 1;
|
|
1170
|
-
let typesPath = cleanPath(
|
|
1176
|
+
let typesPath = cleanPath(
|
|
1177
|
+
types ? resolve(root, types) : resolve(outDir, indexName),
|
|
1178
|
+
emittedFiles
|
|
1179
|
+
);
|
|
1171
1180
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
1172
1181
|
logger.warn(
|
|
1173
1182
|
`
|
|
@@ -1179,11 +1188,11 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
1179
1188
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
1180
1189
|
}
|
|
1181
1190
|
for (const name of entryNames) {
|
|
1182
|
-
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name))) : typesPath;
|
|
1191
|
+
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
|
|
1183
1192
|
if (node_fs.existsSync(entryDtsPath))
|
|
1184
1193
|
continue;
|
|
1185
1194
|
const sourceEntry = normalizePath(
|
|
1186
|
-
cleanPath(resolve(outDir, node_path.relative(entryRoot, tsToDts(entries[name]))))
|
|
1195
|
+
cleanPath(resolve(outDir, node_path.relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
|
|
1187
1196
|
);
|
|
1188
1197
|
let fromPath = normalizePath(node_path.relative(node_path.dirname(entryDtsPath), sourceEntry));
|
|
1189
1198
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -1200,7 +1209,7 @@ export default ${libName}
|
|
|
1200
1209
|
${content}`;
|
|
1201
1210
|
}
|
|
1202
1211
|
}
|
|
1203
|
-
await writeOutput(cleanPath(entryDtsPath), content, outDir);
|
|
1212
|
+
await writeOutput(cleanPath(entryDtsPath, emittedFiles), content, outDir);
|
|
1204
1213
|
}
|
|
1205
1214
|
bundleDebug("insert index");
|
|
1206
1215
|
if (rollupTypes) {
|
|
@@ -1227,7 +1236,7 @@ ${content}`;
|
|
|
1227
1236
|
};
|
|
1228
1237
|
if (multiple) {
|
|
1229
1238
|
await runParallel(node_os.cpus().length, entryNames, async (name) => {
|
|
1230
|
-
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1239
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name)), emittedFiles));
|
|
1231
1240
|
});
|
|
1232
1241
|
} else {
|
|
1233
1242
|
await rollup(typesPath);
|
package/dist/index.d.cts
CHANGED
|
@@ -35,176 +35,178 @@ interface Resolver {
|
|
|
35
35
|
}
|
|
36
36
|
interface PluginOptions {
|
|
37
37
|
/**
|
|
38
|
-
* Specify root directory
|
|
38
|
+
* Specify root directory.
|
|
39
39
|
*
|
|
40
|
-
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
40
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup.
|
|
41
41
|
*/
|
|
42
42
|
root?: string;
|
|
43
43
|
/**
|
|
44
|
-
* Output directory for declaration files
|
|
44
|
+
* Output directory for declaration files.
|
|
45
45
|
*
|
|
46
|
-
* Can be an array to output to multiple directories
|
|
46
|
+
* Can be an array to output to multiple directories.
|
|
47
47
|
*
|
|
48
|
-
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
48
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup.
|
|
49
49
|
*/
|
|
50
50
|
outDir?: string | string[];
|
|
51
51
|
/**
|
|
52
|
-
* Override root path of entry files (useful in monorepos)
|
|
52
|
+
* Override root path of entry files (useful in monorepos).
|
|
53
53
|
*
|
|
54
|
-
* The output path of each file will be calculated based on the value provided
|
|
54
|
+
* The output path of each file will be calculated based on the value provided.
|
|
55
55
|
*
|
|
56
|
-
* The default is the smallest public path for all source files
|
|
56
|
+
* The default is the smallest public path for all source files.
|
|
57
57
|
*/
|
|
58
58
|
entryRoot?: string;
|
|
59
59
|
/**
|
|
60
|
-
* Restrict declaration files output to `outDir
|
|
60
|
+
* Restrict declaration files output to `outDir`.
|
|
61
61
|
*
|
|
62
|
-
* If true, generated declaration files outside `outDir` will be ignored
|
|
62
|
+
* If true, generated declaration files outside `outDir` will be ignored.
|
|
63
63
|
*
|
|
64
64
|
* @default true
|
|
65
65
|
*/
|
|
66
66
|
strictOutput?: boolean;
|
|
67
67
|
/**
|
|
68
|
-
* Override compilerOptions
|
|
68
|
+
* Override compilerOptions.
|
|
69
69
|
*
|
|
70
70
|
* @default null
|
|
71
71
|
*/
|
|
72
72
|
compilerOptions?: ts.CompilerOptions | null;
|
|
73
73
|
/**
|
|
74
|
-
* Specify tsconfig.json path
|
|
74
|
+
* Specify tsconfig.json path.
|
|
75
75
|
*
|
|
76
|
-
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
76
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json.
|
|
77
77
|
*
|
|
78
|
-
* If not specified, plugin will find config file from root
|
|
78
|
+
* If not specified, plugin will find config file from root.
|
|
79
79
|
*/
|
|
80
80
|
tsconfigPath?: string;
|
|
81
81
|
/**
|
|
82
|
-
* Specify custom resolvers
|
|
82
|
+
* Specify custom resolvers.
|
|
83
83
|
*
|
|
84
84
|
* @default []
|
|
85
85
|
*/
|
|
86
86
|
resolvers?: Resolver[];
|
|
87
87
|
/**
|
|
88
|
-
* Parsing `paths` of tsconfig.json to aliases
|
|
88
|
+
* Parsing `paths` of tsconfig.json to aliases.
|
|
89
89
|
*
|
|
90
|
-
* Note that these aliases only use for declaration files
|
|
90
|
+
* Note that these aliases only use for declaration files.
|
|
91
91
|
*
|
|
92
92
|
* @default true
|
|
93
|
-
* @remarks Only use first replacement of each path
|
|
93
|
+
* @remarks Only use first replacement of each path.
|
|
94
94
|
*/
|
|
95
95
|
pathsToAliases?: boolean;
|
|
96
96
|
/**
|
|
97
|
-
* Set which paths should be excluded when transforming aliases
|
|
97
|
+
* Set which paths should be excluded when transforming aliases.
|
|
98
98
|
*
|
|
99
99
|
* @default []
|
|
100
100
|
*/
|
|
101
101
|
aliasesExclude?: (string | RegExp)[];
|
|
102
102
|
/**
|
|
103
|
-
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
103
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'.
|
|
104
|
+
*
|
|
105
|
+
* If there is a duplicate name after transform, it will fall back to the original name.
|
|
104
106
|
*
|
|
105
107
|
* @default false
|
|
106
108
|
*/
|
|
107
109
|
cleanVueFileName?: boolean;
|
|
108
110
|
/**
|
|
109
|
-
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
111
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`).
|
|
110
112
|
*
|
|
111
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
113
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
112
114
|
*
|
|
113
115
|
* @default false
|
|
114
116
|
*/
|
|
115
117
|
staticImport?: boolean;
|
|
116
118
|
/**
|
|
117
|
-
* Override `include` glob (relative to root)
|
|
119
|
+
* Override `include` glob (relative to root).
|
|
118
120
|
*
|
|
119
|
-
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
121
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located).
|
|
120
122
|
*/
|
|
121
123
|
include?: string | string[];
|
|
122
124
|
/**
|
|
123
|
-
* Override `exclude` glob
|
|
125
|
+
* Override `exclude` glob.
|
|
124
126
|
*
|
|
125
127
|
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
126
128
|
*/
|
|
127
129
|
exclude?: string | string[];
|
|
128
130
|
/**
|
|
129
|
-
* Whether to remove `import 'xxx'
|
|
131
|
+
* Whether to remove `import 'xxx'`.
|
|
130
132
|
*
|
|
131
133
|
* @default true
|
|
132
134
|
*/
|
|
133
135
|
clearPureImport?: boolean;
|
|
134
136
|
/**
|
|
135
|
-
* Whether to generate types entry file(s)
|
|
137
|
+
* Whether to generate types entry file(s).
|
|
136
138
|
*
|
|
137
|
-
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts
|
|
139
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`.
|
|
138
140
|
*
|
|
139
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
141
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
140
142
|
*
|
|
141
143
|
* @default false
|
|
142
144
|
*/
|
|
143
145
|
insertTypesEntry?: boolean;
|
|
144
146
|
/**
|
|
145
|
-
* Rollup type declaration files after emitting them
|
|
147
|
+
* Rollup type declaration files after emitting them.
|
|
146
148
|
*
|
|
147
|
-
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
149
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation.
|
|
148
150
|
*
|
|
149
151
|
* @default false
|
|
150
152
|
*/
|
|
151
153
|
rollupTypes?: boolean;
|
|
152
154
|
/**
|
|
153
|
-
* Bundled packages for `@microsoft/api-extractor
|
|
155
|
+
* Bundled packages for `@microsoft/api-extractor`.
|
|
154
156
|
*
|
|
155
157
|
* @default []
|
|
156
158
|
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
157
159
|
*/
|
|
158
160
|
bundledPackages?: string[];
|
|
159
161
|
/**
|
|
160
|
-
* Override the config of `@microsoft/api-extractor
|
|
162
|
+
* Override the config of `@microsoft/api-extractor`.
|
|
161
163
|
*
|
|
162
164
|
* @default null
|
|
163
165
|
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
164
166
|
*/
|
|
165
167
|
rollupConfig?: RollupConfig;
|
|
166
168
|
/**
|
|
167
|
-
* Override the invoke options of `@microsoft/api-extractor
|
|
169
|
+
* Override the invoke options of `@microsoft/api-extractor`.
|
|
168
170
|
*
|
|
169
171
|
* @default null
|
|
170
172
|
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
171
173
|
*/
|
|
172
174
|
rollupOptions?: IExtractorInvokeOptions;
|
|
173
175
|
/**
|
|
174
|
-
* Whether to copy .d.ts source files to `outDir
|
|
176
|
+
* Whether to copy .d.ts source files to `outDir`.
|
|
175
177
|
*
|
|
176
178
|
* @default false
|
|
177
|
-
* @remarks Before 2.0, the default was `true
|
|
179
|
+
* @remarks Before 2.0, the default was `true`.
|
|
178
180
|
*/
|
|
179
181
|
copyDtsFiles?: boolean;
|
|
180
182
|
/**
|
|
181
|
-
* Whether to emit declaration files only
|
|
183
|
+
* Whether to emit declaration files only.
|
|
182
184
|
*
|
|
183
|
-
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
185
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed.
|
|
184
186
|
*
|
|
185
187
|
* @default false
|
|
186
188
|
*/
|
|
187
189
|
declarationOnly?: boolean;
|
|
188
190
|
/**
|
|
189
|
-
* Logging level for this plugin
|
|
191
|
+
* Logging level for this plugin.
|
|
190
192
|
*
|
|
191
|
-
* Defaults to the 'logLevel' property of your Vite config
|
|
193
|
+
* Defaults to the 'logLevel' property of your Vite config.
|
|
192
194
|
*/
|
|
193
195
|
logLevel?: LogLevel;
|
|
194
196
|
/**
|
|
195
|
-
* Hook called after diagnostic is emitted
|
|
197
|
+
* Hook called after diagnostic is emitted.
|
|
196
198
|
*
|
|
197
|
-
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
199
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error.
|
|
198
200
|
*
|
|
199
201
|
* @default () => {}
|
|
200
202
|
*/
|
|
201
203
|
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
|
|
202
204
|
/**
|
|
203
|
-
* Hook called prior to writing each declaration file
|
|
205
|
+
* Hook called prior to writing each declaration file.
|
|
204
206
|
*
|
|
205
|
-
* This allows you to transform the path or content
|
|
207
|
+
* This allows you to transform the path or content.
|
|
206
208
|
*
|
|
207
|
-
* The file will be skipped when the return value `false` or `Promise<false
|
|
209
|
+
* The file will be skipped when the return value `false` or `Promise<false>`.
|
|
208
210
|
*
|
|
209
211
|
* @default () => {}
|
|
210
212
|
*/
|
|
@@ -213,15 +215,15 @@ interface PluginOptions {
|
|
|
213
215
|
content?: string;
|
|
214
216
|
}>;
|
|
215
217
|
/**
|
|
216
|
-
* Hook called after rolling up declaration files
|
|
218
|
+
* Hook called after rolling up declaration files.
|
|
217
219
|
*
|
|
218
220
|
* @default () => {}
|
|
219
221
|
*/
|
|
220
222
|
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
221
223
|
/**
|
|
222
|
-
* Hook called after all declaration files are written
|
|
224
|
+
* Hook called after all declaration files are written.
|
|
223
225
|
*
|
|
224
|
-
* It will be received a map (path -> content) that records those emitted files
|
|
226
|
+
* It will be received a map (path -> content) that records those emitted files.
|
|
225
227
|
*
|
|
226
228
|
* @default () => {}
|
|
227
229
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -35,176 +35,178 @@ interface Resolver {
|
|
|
35
35
|
}
|
|
36
36
|
interface PluginOptions {
|
|
37
37
|
/**
|
|
38
|
-
* Specify root directory
|
|
38
|
+
* Specify root directory.
|
|
39
39
|
*
|
|
40
|
-
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
40
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup.
|
|
41
41
|
*/
|
|
42
42
|
root?: string;
|
|
43
43
|
/**
|
|
44
|
-
* Output directory for declaration files
|
|
44
|
+
* Output directory for declaration files.
|
|
45
45
|
*
|
|
46
|
-
* Can be an array to output to multiple directories
|
|
46
|
+
* Can be an array to output to multiple directories.
|
|
47
47
|
*
|
|
48
|
-
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
48
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup.
|
|
49
49
|
*/
|
|
50
50
|
outDir?: string | string[];
|
|
51
51
|
/**
|
|
52
|
-
* Override root path of entry files (useful in monorepos)
|
|
52
|
+
* Override root path of entry files (useful in monorepos).
|
|
53
53
|
*
|
|
54
|
-
* The output path of each file will be calculated based on the value provided
|
|
54
|
+
* The output path of each file will be calculated based on the value provided.
|
|
55
55
|
*
|
|
56
|
-
* The default is the smallest public path for all source files
|
|
56
|
+
* The default is the smallest public path for all source files.
|
|
57
57
|
*/
|
|
58
58
|
entryRoot?: string;
|
|
59
59
|
/**
|
|
60
|
-
* Restrict declaration files output to `outDir
|
|
60
|
+
* Restrict declaration files output to `outDir`.
|
|
61
61
|
*
|
|
62
|
-
* If true, generated declaration files outside `outDir` will be ignored
|
|
62
|
+
* If true, generated declaration files outside `outDir` will be ignored.
|
|
63
63
|
*
|
|
64
64
|
* @default true
|
|
65
65
|
*/
|
|
66
66
|
strictOutput?: boolean;
|
|
67
67
|
/**
|
|
68
|
-
* Override compilerOptions
|
|
68
|
+
* Override compilerOptions.
|
|
69
69
|
*
|
|
70
70
|
* @default null
|
|
71
71
|
*/
|
|
72
72
|
compilerOptions?: ts.CompilerOptions | null;
|
|
73
73
|
/**
|
|
74
|
-
* Specify tsconfig.json path
|
|
74
|
+
* Specify tsconfig.json path.
|
|
75
75
|
*
|
|
76
|
-
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
76
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json.
|
|
77
77
|
*
|
|
78
|
-
* If not specified, plugin will find config file from root
|
|
78
|
+
* If not specified, plugin will find config file from root.
|
|
79
79
|
*/
|
|
80
80
|
tsconfigPath?: string;
|
|
81
81
|
/**
|
|
82
|
-
* Specify custom resolvers
|
|
82
|
+
* Specify custom resolvers.
|
|
83
83
|
*
|
|
84
84
|
* @default []
|
|
85
85
|
*/
|
|
86
86
|
resolvers?: Resolver[];
|
|
87
87
|
/**
|
|
88
|
-
* Parsing `paths` of tsconfig.json to aliases
|
|
88
|
+
* Parsing `paths` of tsconfig.json to aliases.
|
|
89
89
|
*
|
|
90
|
-
* Note that these aliases only use for declaration files
|
|
90
|
+
* Note that these aliases only use for declaration files.
|
|
91
91
|
*
|
|
92
92
|
* @default true
|
|
93
|
-
* @remarks Only use first replacement of each path
|
|
93
|
+
* @remarks Only use first replacement of each path.
|
|
94
94
|
*/
|
|
95
95
|
pathsToAliases?: boolean;
|
|
96
96
|
/**
|
|
97
|
-
* Set which paths should be excluded when transforming aliases
|
|
97
|
+
* Set which paths should be excluded when transforming aliases.
|
|
98
98
|
*
|
|
99
99
|
* @default []
|
|
100
100
|
*/
|
|
101
101
|
aliasesExclude?: (string | RegExp)[];
|
|
102
102
|
/**
|
|
103
|
-
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
103
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'.
|
|
104
|
+
*
|
|
105
|
+
* If there is a duplicate name after transform, it will fall back to the original name.
|
|
104
106
|
*
|
|
105
107
|
* @default false
|
|
106
108
|
*/
|
|
107
109
|
cleanVueFileName?: boolean;
|
|
108
110
|
/**
|
|
109
|
-
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
111
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`).
|
|
110
112
|
*
|
|
111
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
113
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
112
114
|
*
|
|
113
115
|
* @default false
|
|
114
116
|
*/
|
|
115
117
|
staticImport?: boolean;
|
|
116
118
|
/**
|
|
117
|
-
* Override `include` glob (relative to root)
|
|
119
|
+
* Override `include` glob (relative to root).
|
|
118
120
|
*
|
|
119
|
-
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
121
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located).
|
|
120
122
|
*/
|
|
121
123
|
include?: string | string[];
|
|
122
124
|
/**
|
|
123
|
-
* Override `exclude` glob
|
|
125
|
+
* Override `exclude` glob.
|
|
124
126
|
*
|
|
125
127
|
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
126
128
|
*/
|
|
127
129
|
exclude?: string | string[];
|
|
128
130
|
/**
|
|
129
|
-
* Whether to remove `import 'xxx'
|
|
131
|
+
* Whether to remove `import 'xxx'`.
|
|
130
132
|
*
|
|
131
133
|
* @default true
|
|
132
134
|
*/
|
|
133
135
|
clearPureImport?: boolean;
|
|
134
136
|
/**
|
|
135
|
-
* Whether to generate types entry file(s)
|
|
137
|
+
* Whether to generate types entry file(s).
|
|
136
138
|
*
|
|
137
|
-
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts
|
|
139
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`.
|
|
138
140
|
*
|
|
139
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
141
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
140
142
|
*
|
|
141
143
|
* @default false
|
|
142
144
|
*/
|
|
143
145
|
insertTypesEntry?: boolean;
|
|
144
146
|
/**
|
|
145
|
-
* Rollup type declaration files after emitting them
|
|
147
|
+
* Rollup type declaration files after emitting them.
|
|
146
148
|
*
|
|
147
|
-
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
149
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation.
|
|
148
150
|
*
|
|
149
151
|
* @default false
|
|
150
152
|
*/
|
|
151
153
|
rollupTypes?: boolean;
|
|
152
154
|
/**
|
|
153
|
-
* Bundled packages for `@microsoft/api-extractor
|
|
155
|
+
* Bundled packages for `@microsoft/api-extractor`.
|
|
154
156
|
*
|
|
155
157
|
* @default []
|
|
156
158
|
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
157
159
|
*/
|
|
158
160
|
bundledPackages?: string[];
|
|
159
161
|
/**
|
|
160
|
-
* Override the config of `@microsoft/api-extractor
|
|
162
|
+
* Override the config of `@microsoft/api-extractor`.
|
|
161
163
|
*
|
|
162
164
|
* @default null
|
|
163
165
|
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
164
166
|
*/
|
|
165
167
|
rollupConfig?: RollupConfig;
|
|
166
168
|
/**
|
|
167
|
-
* Override the invoke options of `@microsoft/api-extractor
|
|
169
|
+
* Override the invoke options of `@microsoft/api-extractor`.
|
|
168
170
|
*
|
|
169
171
|
* @default null
|
|
170
172
|
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
171
173
|
*/
|
|
172
174
|
rollupOptions?: IExtractorInvokeOptions;
|
|
173
175
|
/**
|
|
174
|
-
* Whether to copy .d.ts source files to `outDir
|
|
176
|
+
* Whether to copy .d.ts source files to `outDir`.
|
|
175
177
|
*
|
|
176
178
|
* @default false
|
|
177
|
-
* @remarks Before 2.0, the default was `true
|
|
179
|
+
* @remarks Before 2.0, the default was `true`.
|
|
178
180
|
*/
|
|
179
181
|
copyDtsFiles?: boolean;
|
|
180
182
|
/**
|
|
181
|
-
* Whether to emit declaration files only
|
|
183
|
+
* Whether to emit declaration files only.
|
|
182
184
|
*
|
|
183
|
-
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
185
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed.
|
|
184
186
|
*
|
|
185
187
|
* @default false
|
|
186
188
|
*/
|
|
187
189
|
declarationOnly?: boolean;
|
|
188
190
|
/**
|
|
189
|
-
* Logging level for this plugin
|
|
191
|
+
* Logging level for this plugin.
|
|
190
192
|
*
|
|
191
|
-
* Defaults to the 'logLevel' property of your Vite config
|
|
193
|
+
* Defaults to the 'logLevel' property of your Vite config.
|
|
192
194
|
*/
|
|
193
195
|
logLevel?: LogLevel;
|
|
194
196
|
/**
|
|
195
|
-
* Hook called after diagnostic is emitted
|
|
197
|
+
* Hook called after diagnostic is emitted.
|
|
196
198
|
*
|
|
197
|
-
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
199
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error.
|
|
198
200
|
*
|
|
199
201
|
* @default () => {}
|
|
200
202
|
*/
|
|
201
203
|
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
|
|
202
204
|
/**
|
|
203
|
-
* Hook called prior to writing each declaration file
|
|
205
|
+
* Hook called prior to writing each declaration file.
|
|
204
206
|
*
|
|
205
|
-
* This allows you to transform the path or content
|
|
207
|
+
* This allows you to transform the path or content.
|
|
206
208
|
*
|
|
207
|
-
* The file will be skipped when the return value `false` or `Promise<false
|
|
209
|
+
* The file will be skipped when the return value `false` or `Promise<false>`.
|
|
208
210
|
*
|
|
209
211
|
* @default () => {}
|
|
210
212
|
*/
|
|
@@ -213,15 +215,15 @@ interface PluginOptions {
|
|
|
213
215
|
content?: string;
|
|
214
216
|
}>;
|
|
215
217
|
/**
|
|
216
|
-
* Hook called after rolling up declaration files
|
|
218
|
+
* Hook called after rolling up declaration files.
|
|
217
219
|
*
|
|
218
220
|
* @default () => {}
|
|
219
221
|
*/
|
|
220
222
|
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
221
223
|
/**
|
|
222
|
-
* Hook called after all declaration files are written
|
|
224
|
+
* Hook called after all declaration files are written.
|
|
223
225
|
*
|
|
224
|
-
* It will be received a map (path -> content) that records those emitted files
|
|
226
|
+
* It will be received a map (path -> content) that records those emitted files.
|
|
225
227
|
*
|
|
226
228
|
* @default () => {}
|
|
227
229
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -35,176 +35,178 @@ interface Resolver {
|
|
|
35
35
|
}
|
|
36
36
|
interface PluginOptions {
|
|
37
37
|
/**
|
|
38
|
-
* Specify root directory
|
|
38
|
+
* Specify root directory.
|
|
39
39
|
*
|
|
40
|
-
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
40
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup.
|
|
41
41
|
*/
|
|
42
42
|
root?: string;
|
|
43
43
|
/**
|
|
44
|
-
* Output directory for declaration files
|
|
44
|
+
* Output directory for declaration files.
|
|
45
45
|
*
|
|
46
|
-
* Can be an array to output to multiple directories
|
|
46
|
+
* Can be an array to output to multiple directories.
|
|
47
47
|
*
|
|
48
|
-
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
48
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup.
|
|
49
49
|
*/
|
|
50
50
|
outDir?: string | string[];
|
|
51
51
|
/**
|
|
52
|
-
* Override root path of entry files (useful in monorepos)
|
|
52
|
+
* Override root path of entry files (useful in monorepos).
|
|
53
53
|
*
|
|
54
|
-
* The output path of each file will be calculated based on the value provided
|
|
54
|
+
* The output path of each file will be calculated based on the value provided.
|
|
55
55
|
*
|
|
56
|
-
* The default is the smallest public path for all source files
|
|
56
|
+
* The default is the smallest public path for all source files.
|
|
57
57
|
*/
|
|
58
58
|
entryRoot?: string;
|
|
59
59
|
/**
|
|
60
|
-
* Restrict declaration files output to `outDir
|
|
60
|
+
* Restrict declaration files output to `outDir`.
|
|
61
61
|
*
|
|
62
|
-
* If true, generated declaration files outside `outDir` will be ignored
|
|
62
|
+
* If true, generated declaration files outside `outDir` will be ignored.
|
|
63
63
|
*
|
|
64
64
|
* @default true
|
|
65
65
|
*/
|
|
66
66
|
strictOutput?: boolean;
|
|
67
67
|
/**
|
|
68
|
-
* Override compilerOptions
|
|
68
|
+
* Override compilerOptions.
|
|
69
69
|
*
|
|
70
70
|
* @default null
|
|
71
71
|
*/
|
|
72
72
|
compilerOptions?: ts.CompilerOptions | null;
|
|
73
73
|
/**
|
|
74
|
-
* Specify tsconfig.json path
|
|
74
|
+
* Specify tsconfig.json path.
|
|
75
75
|
*
|
|
76
|
-
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
76
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json.
|
|
77
77
|
*
|
|
78
|
-
* If not specified, plugin will find config file from root
|
|
78
|
+
* If not specified, plugin will find config file from root.
|
|
79
79
|
*/
|
|
80
80
|
tsconfigPath?: string;
|
|
81
81
|
/**
|
|
82
|
-
* Specify custom resolvers
|
|
82
|
+
* Specify custom resolvers.
|
|
83
83
|
*
|
|
84
84
|
* @default []
|
|
85
85
|
*/
|
|
86
86
|
resolvers?: Resolver[];
|
|
87
87
|
/**
|
|
88
|
-
* Parsing `paths` of tsconfig.json to aliases
|
|
88
|
+
* Parsing `paths` of tsconfig.json to aliases.
|
|
89
89
|
*
|
|
90
|
-
* Note that these aliases only use for declaration files
|
|
90
|
+
* Note that these aliases only use for declaration files.
|
|
91
91
|
*
|
|
92
92
|
* @default true
|
|
93
|
-
* @remarks Only use first replacement of each path
|
|
93
|
+
* @remarks Only use first replacement of each path.
|
|
94
94
|
*/
|
|
95
95
|
pathsToAliases?: boolean;
|
|
96
96
|
/**
|
|
97
|
-
* Set which paths should be excluded when transforming aliases
|
|
97
|
+
* Set which paths should be excluded when transforming aliases.
|
|
98
98
|
*
|
|
99
99
|
* @default []
|
|
100
100
|
*/
|
|
101
101
|
aliasesExclude?: (string | RegExp)[];
|
|
102
102
|
/**
|
|
103
|
-
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
103
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'.
|
|
104
|
+
*
|
|
105
|
+
* If there is a duplicate name after transform, it will fall back to the original name.
|
|
104
106
|
*
|
|
105
107
|
* @default false
|
|
106
108
|
*/
|
|
107
109
|
cleanVueFileName?: boolean;
|
|
108
110
|
/**
|
|
109
|
-
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
111
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`).
|
|
110
112
|
*
|
|
111
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
113
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
112
114
|
*
|
|
113
115
|
* @default false
|
|
114
116
|
*/
|
|
115
117
|
staticImport?: boolean;
|
|
116
118
|
/**
|
|
117
|
-
* Override `include` glob (relative to root)
|
|
119
|
+
* Override `include` glob (relative to root).
|
|
118
120
|
*
|
|
119
|
-
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
121
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located).
|
|
120
122
|
*/
|
|
121
123
|
include?: string | string[];
|
|
122
124
|
/**
|
|
123
|
-
* Override `exclude` glob
|
|
125
|
+
* Override `exclude` glob.
|
|
124
126
|
*
|
|
125
127
|
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
126
128
|
*/
|
|
127
129
|
exclude?: string | string[];
|
|
128
130
|
/**
|
|
129
|
-
* Whether to remove `import 'xxx'
|
|
131
|
+
* Whether to remove `import 'xxx'`.
|
|
130
132
|
*
|
|
131
133
|
* @default true
|
|
132
134
|
*/
|
|
133
135
|
clearPureImport?: boolean;
|
|
134
136
|
/**
|
|
135
|
-
* Whether to generate types entry file(s)
|
|
137
|
+
* Whether to generate types entry file(s).
|
|
136
138
|
*
|
|
137
|
-
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts
|
|
139
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`.
|
|
138
140
|
*
|
|
139
|
-
* Value is forced to `true` when `rollupTypes` is `true
|
|
141
|
+
* Value is forced to `true` when `rollupTypes` is `true`.
|
|
140
142
|
*
|
|
141
143
|
* @default false
|
|
142
144
|
*/
|
|
143
145
|
insertTypesEntry?: boolean;
|
|
144
146
|
/**
|
|
145
|
-
* Rollup type declaration files after emitting them
|
|
147
|
+
* Rollup type declaration files after emitting them.
|
|
146
148
|
*
|
|
147
|
-
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
149
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation.
|
|
148
150
|
*
|
|
149
151
|
* @default false
|
|
150
152
|
*/
|
|
151
153
|
rollupTypes?: boolean;
|
|
152
154
|
/**
|
|
153
|
-
* Bundled packages for `@microsoft/api-extractor
|
|
155
|
+
* Bundled packages for `@microsoft/api-extractor`.
|
|
154
156
|
*
|
|
155
157
|
* @default []
|
|
156
158
|
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
157
159
|
*/
|
|
158
160
|
bundledPackages?: string[];
|
|
159
161
|
/**
|
|
160
|
-
* Override the config of `@microsoft/api-extractor
|
|
162
|
+
* Override the config of `@microsoft/api-extractor`.
|
|
161
163
|
*
|
|
162
164
|
* @default null
|
|
163
165
|
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
164
166
|
*/
|
|
165
167
|
rollupConfig?: RollupConfig;
|
|
166
168
|
/**
|
|
167
|
-
* Override the invoke options of `@microsoft/api-extractor
|
|
169
|
+
* Override the invoke options of `@microsoft/api-extractor`.
|
|
168
170
|
*
|
|
169
171
|
* @default null
|
|
170
172
|
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
171
173
|
*/
|
|
172
174
|
rollupOptions?: IExtractorInvokeOptions;
|
|
173
175
|
/**
|
|
174
|
-
* Whether to copy .d.ts source files to `outDir
|
|
176
|
+
* Whether to copy .d.ts source files to `outDir`.
|
|
175
177
|
*
|
|
176
178
|
* @default false
|
|
177
|
-
* @remarks Before 2.0, the default was `true
|
|
179
|
+
* @remarks Before 2.0, the default was `true`.
|
|
178
180
|
*/
|
|
179
181
|
copyDtsFiles?: boolean;
|
|
180
182
|
/**
|
|
181
|
-
* Whether to emit declaration files only
|
|
183
|
+
* Whether to emit declaration files only.
|
|
182
184
|
*
|
|
183
|
-
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
185
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed.
|
|
184
186
|
*
|
|
185
187
|
* @default false
|
|
186
188
|
*/
|
|
187
189
|
declarationOnly?: boolean;
|
|
188
190
|
/**
|
|
189
|
-
* Logging level for this plugin
|
|
191
|
+
* Logging level for this plugin.
|
|
190
192
|
*
|
|
191
|
-
* Defaults to the 'logLevel' property of your Vite config
|
|
193
|
+
* Defaults to the 'logLevel' property of your Vite config.
|
|
192
194
|
*/
|
|
193
195
|
logLevel?: LogLevel;
|
|
194
196
|
/**
|
|
195
|
-
* Hook called after diagnostic is emitted
|
|
197
|
+
* Hook called after diagnostic is emitted.
|
|
196
198
|
*
|
|
197
|
-
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
199
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error.
|
|
198
200
|
*
|
|
199
201
|
* @default () => {}
|
|
200
202
|
*/
|
|
201
203
|
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
|
|
202
204
|
/**
|
|
203
|
-
* Hook called prior to writing each declaration file
|
|
205
|
+
* Hook called prior to writing each declaration file.
|
|
204
206
|
*
|
|
205
|
-
* This allows you to transform the path or content
|
|
207
|
+
* This allows you to transform the path or content.
|
|
206
208
|
*
|
|
207
|
-
* The file will be skipped when the return value `false` or `Promise<false
|
|
209
|
+
* The file will be skipped when the return value `false` or `Promise<false>`.
|
|
208
210
|
*
|
|
209
211
|
* @default () => {}
|
|
210
212
|
*/
|
|
@@ -213,15 +215,15 @@ interface PluginOptions {
|
|
|
213
215
|
content?: string;
|
|
214
216
|
}>;
|
|
215
217
|
/**
|
|
216
|
-
* Hook called after rolling up declaration files
|
|
218
|
+
* Hook called after rolling up declaration files.
|
|
217
219
|
*
|
|
218
220
|
* @default () => {}
|
|
219
221
|
*/
|
|
220
222
|
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
221
223
|
/**
|
|
222
|
-
* Hook called after all declaration files are written
|
|
224
|
+
* Hook called after all declaration files are written.
|
|
223
225
|
*
|
|
224
|
-
* It will be received a map (path -> content) that records those emitted files
|
|
226
|
+
* It will be received a map (path -> content) that records those emitted files.
|
|
225
227
|
*
|
|
226
228
|
* @default () => {}
|
|
227
229
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -12,17 +12,22 @@ import { cpus } from 'node:os';
|
|
|
12
12
|
import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin2, createRootFileChecker } from '@vue/language-core';
|
|
13
13
|
import { proxyCreateProgram } from '@volar/typescript';
|
|
14
14
|
import ts from 'typescript';
|
|
15
|
+
import { getPackageInfoSync, resolveModule } from 'local-pkg';
|
|
15
16
|
import { removeEmitGlobalTypes } from 'vue-tsc';
|
|
16
17
|
import { createFilter } from '@rollup/pluginutils';
|
|
17
18
|
import debug from 'debug';
|
|
18
19
|
import { cyan, yellow, green } from 'kolorist';
|
|
19
20
|
import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
|
|
20
21
|
import { createRequire } from 'node:module';
|
|
21
|
-
import { getPackageInfoSync, resolveModule } from 'local-pkg';
|
|
22
22
|
import { compare } from 'compare-versions';
|
|
23
23
|
import MagicString from 'magic-string';
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
let hasVue = false;
|
|
26
|
+
try {
|
|
27
|
+
hasVue = !!(getPackageInfoSync("vue") ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] }));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
}
|
|
30
|
+
const _createProgram = !hasVue ? ts.createProgram : proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
|
|
26
31
|
const { configFilePath } = options.options;
|
|
27
32
|
const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
|
|
28
33
|
if (options.host) {
|
|
@@ -44,7 +49,7 @@ const _createProgram = proxyCreateProgram(ts, ts.createProgram, (ts2, options) =
|
|
|
44
49
|
);
|
|
45
50
|
return [vueLanguagePlugin];
|
|
46
51
|
});
|
|
47
|
-
const createProgram = (options) => {
|
|
52
|
+
const createProgram = !hasVue ? ts.createProgram : (options) => {
|
|
48
53
|
const program = _createProgram(options);
|
|
49
54
|
const emit = program.emit;
|
|
50
55
|
program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
|
|
@@ -324,7 +329,7 @@ function parseTsAliases(basePath, paths) {
|
|
|
324
329
|
const result = [];
|
|
325
330
|
for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
|
|
326
331
|
const find = new RegExp(
|
|
327
|
-
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(
|
|
332
|
+
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
|
|
328
333
|
);
|
|
329
334
|
let index = 1;
|
|
330
335
|
result.push({
|
|
@@ -444,7 +449,7 @@ function querySvelteVersion() {
|
|
|
444
449
|
try {
|
|
445
450
|
const version = getPackageInfoSync("svelte")?.version ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] })?.version;
|
|
446
451
|
lowerVersion = version ? compare(version, "4.0.0", "<") : false;
|
|
447
|
-
} catch {
|
|
452
|
+
} catch (e) {
|
|
448
453
|
lowerVersion = false;
|
|
449
454
|
}
|
|
450
455
|
}
|
|
@@ -792,8 +797,9 @@ function dtsPlugin(options = {}) {
|
|
|
792
797
|
};
|
|
793
798
|
const rollupConfig = { ...options.rollupConfig || {} };
|
|
794
799
|
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
795
|
-
const cleanPath = (path) => {
|
|
796
|
-
|
|
800
|
+
const cleanPath = (path, emittedFiles) => {
|
|
801
|
+
const newPath = path.replace(".vue.d.ts", ".d.ts");
|
|
802
|
+
return !emittedFiles.has(newPath) && cleanVueFileName ? newPath : path;
|
|
797
803
|
};
|
|
798
804
|
return {
|
|
799
805
|
name: pluginName,
|
|
@@ -1163,7 +1169,10 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
1163
1169
|
const entryNames = Object.keys(entries);
|
|
1164
1170
|
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
1165
1171
|
const multiple = entryNames.length > 1;
|
|
1166
|
-
let typesPath = cleanPath(
|
|
1172
|
+
let typesPath = cleanPath(
|
|
1173
|
+
types ? resolve(root, types) : resolve(outDir, indexName),
|
|
1174
|
+
emittedFiles
|
|
1175
|
+
);
|
|
1167
1176
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
1168
1177
|
logger.warn(
|
|
1169
1178
|
`
|
|
@@ -1175,11 +1184,11 @@ ${logPrefix} ${yellow(
|
|
|
1175
1184
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
1176
1185
|
}
|
|
1177
1186
|
for (const name of entryNames) {
|
|
1178
|
-
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name))) : typesPath;
|
|
1187
|
+
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
|
|
1179
1188
|
if (existsSync(entryDtsPath))
|
|
1180
1189
|
continue;
|
|
1181
1190
|
const sourceEntry = normalizePath(
|
|
1182
|
-
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))))
|
|
1191
|
+
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
|
|
1183
1192
|
);
|
|
1184
1193
|
let fromPath = normalizePath(relative(dirname(entryDtsPath), sourceEntry));
|
|
1185
1194
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -1196,7 +1205,7 @@ export default ${libName}
|
|
|
1196
1205
|
${content}`;
|
|
1197
1206
|
}
|
|
1198
1207
|
}
|
|
1199
|
-
await writeOutput(cleanPath(entryDtsPath), content, outDir);
|
|
1208
|
+
await writeOutput(cleanPath(entryDtsPath, emittedFiles), content, outDir);
|
|
1200
1209
|
}
|
|
1201
1210
|
bundleDebug("insert index");
|
|
1202
1211
|
if (rollupTypes) {
|
|
@@ -1223,7 +1232,7 @@ ${content}`;
|
|
|
1223
1232
|
};
|
|
1224
1233
|
if (multiple) {
|
|
1225
1234
|
await runParallel(cpus().length, entryNames, async (name) => {
|
|
1226
|
-
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1235
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name)), emittedFiles));
|
|
1227
1236
|
});
|
|
1228
1237
|
} else {
|
|
1229
1238
|
await rollup(typesPath);
|