vite-plugin-dts 4.0.2 → 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/LICENSE +21 -21
- package/README.md +417 -408
- package/README.zh-CN.md +417 -408
- package/dist/index.cjs +25 -13
- 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 +25 -13
- package/package.json +2 -2
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) => {
|
|
@@ -199,7 +204,10 @@ function getTsConfig(tsConfigPath, readFileSync) {
|
|
|
199
204
|
function getTsLibFolder({ root, entryRoot }) {
|
|
200
205
|
let libFolder;
|
|
201
206
|
try {
|
|
202
|
-
libFolder = createRequire(import.meta.url).resolve("typescript").replace(
|
|
207
|
+
libFolder = normalizePath(createRequire(import.meta.url).resolve("typescript")).replace(
|
|
208
|
+
/node_modules\/typescript.*/,
|
|
209
|
+
"node_modules/typescript"
|
|
210
|
+
);
|
|
203
211
|
} catch {
|
|
204
212
|
libFolder = resolve(root, "node_modules/typescript");
|
|
205
213
|
if (!existsSync(libFolder)) {
|
|
@@ -321,7 +329,7 @@ function parseTsAliases(basePath, paths) {
|
|
|
321
329
|
const result = [];
|
|
322
330
|
for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
|
|
323
331
|
const find = new RegExp(
|
|
324
|
-
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(
|
|
332
|
+
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
|
|
325
333
|
);
|
|
326
334
|
let index = 1;
|
|
327
335
|
result.push({
|
|
@@ -441,7 +449,7 @@ function querySvelteVersion() {
|
|
|
441
449
|
try {
|
|
442
450
|
const version = getPackageInfoSync("svelte")?.version ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] })?.version;
|
|
443
451
|
lowerVersion = version ? compare(version, "4.0.0", "<") : false;
|
|
444
|
-
} catch {
|
|
452
|
+
} catch (e) {
|
|
445
453
|
lowerVersion = false;
|
|
446
454
|
}
|
|
447
455
|
}
|
|
@@ -789,8 +797,9 @@ function dtsPlugin(options = {}) {
|
|
|
789
797
|
};
|
|
790
798
|
const rollupConfig = { ...options.rollupConfig || {} };
|
|
791
799
|
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
792
|
-
const cleanPath = (path) => {
|
|
793
|
-
|
|
800
|
+
const cleanPath = (path, emittedFiles) => {
|
|
801
|
+
const newPath = path.replace(".vue.d.ts", ".d.ts");
|
|
802
|
+
return !emittedFiles.has(newPath) && cleanVueFileName ? newPath : path;
|
|
794
803
|
};
|
|
795
804
|
return {
|
|
796
805
|
name: pluginName,
|
|
@@ -1160,7 +1169,10 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
1160
1169
|
const entryNames = Object.keys(entries);
|
|
1161
1170
|
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
1162
1171
|
const multiple = entryNames.length > 1;
|
|
1163
|
-
let typesPath = cleanPath(
|
|
1172
|
+
let typesPath = cleanPath(
|
|
1173
|
+
types ? resolve(root, types) : resolve(outDir, indexName),
|
|
1174
|
+
emittedFiles
|
|
1175
|
+
);
|
|
1164
1176
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
1165
1177
|
logger.warn(
|
|
1166
1178
|
`
|
|
@@ -1172,11 +1184,11 @@ ${logPrefix} ${yellow(
|
|
|
1172
1184
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
1173
1185
|
}
|
|
1174
1186
|
for (const name of entryNames) {
|
|
1175
|
-
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name))) : typesPath;
|
|
1187
|
+
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
|
|
1176
1188
|
if (existsSync(entryDtsPath))
|
|
1177
1189
|
continue;
|
|
1178
1190
|
const sourceEntry = normalizePath(
|
|
1179
|
-
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))))
|
|
1191
|
+
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
|
|
1180
1192
|
);
|
|
1181
1193
|
let fromPath = normalizePath(relative(dirname(entryDtsPath), sourceEntry));
|
|
1182
1194
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -1193,7 +1205,7 @@ export default ${libName}
|
|
|
1193
1205
|
${content}`;
|
|
1194
1206
|
}
|
|
1195
1207
|
}
|
|
1196
|
-
await writeOutput(cleanPath(entryDtsPath), content, outDir);
|
|
1208
|
+
await writeOutput(cleanPath(entryDtsPath, emittedFiles), content, outDir);
|
|
1197
1209
|
}
|
|
1198
1210
|
bundleDebug("insert index");
|
|
1199
1211
|
if (rollupTypes) {
|
|
@@ -1220,7 +1232,7 @@ ${content}`;
|
|
|
1220
1232
|
};
|
|
1221
1233
|
if (multiple) {
|
|
1222
1234
|
await runParallel(cpus().length, entryNames, async (name) => {
|
|
1223
|
-
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1235
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name)), emittedFiles));
|
|
1224
1236
|
});
|
|
1225
1237
|
} else {
|
|
1226
1238
|
await rollup(typesPath);
|