vite-plugin-dts 4.0.3 → 4.1.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 +60 -51
- package/README.zh-CN.md +10 -1
- package/dist/index.cjs +80 -87
- 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 +80 -86
- package/package.json +3 -3
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
|
@@ -13,66 +13,14 @@ import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePl
|
|
|
13
13
|
import { proxyCreateProgram } from '@volar/typescript';
|
|
14
14
|
import ts from 'typescript';
|
|
15
15
|
import { removeEmitGlobalTypes } from 'vue-tsc';
|
|
16
|
+
import { getPackageInfoSync, resolveModule } from 'local-pkg';
|
|
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
|
-
import { createRequire } from 'node:module';
|
|
21
|
-
import { getPackageInfoSync, resolveModule } from 'local-pkg';
|
|
22
21
|
import { compare } from 'compare-versions';
|
|
23
22
|
import MagicString from 'magic-string';
|
|
24
23
|
|
|
25
|
-
const _createProgram = proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
|
|
26
|
-
const { configFilePath } = options.options;
|
|
27
|
-
const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
|
|
28
|
-
if (options.host) {
|
|
29
|
-
const writeFile = options.host.writeFile.bind(options.host);
|
|
30
|
-
options.host.writeFile = (fileName, contents, ...args) => {
|
|
31
|
-
return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
const vueLanguagePlugin = createVueLanguagePlugin2(
|
|
35
|
-
ts2,
|
|
36
|
-
(id) => id,
|
|
37
|
-
createRootFileChecker(
|
|
38
|
-
void 0,
|
|
39
|
-
() => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
|
|
40
|
-
options.host?.useCaseSensitiveFileNames?.() ?? false
|
|
41
|
-
),
|
|
42
|
-
options.options,
|
|
43
|
-
vueOptions
|
|
44
|
-
);
|
|
45
|
-
return [vueLanguagePlugin];
|
|
46
|
-
});
|
|
47
|
-
const createProgram = (options) => {
|
|
48
|
-
const program = _createProgram(options);
|
|
49
|
-
const emit = program.emit;
|
|
50
|
-
program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
|
|
51
|
-
if (writeFile) {
|
|
52
|
-
return emit(
|
|
53
|
-
targetSourceFile,
|
|
54
|
-
(fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
55
|
-
if (fileName.endsWith(".d.ts")) {
|
|
56
|
-
data = removeEmitGlobalTypes(data);
|
|
57
|
-
}
|
|
58
|
-
return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
59
|
-
},
|
|
60
|
-
cancellationToken,
|
|
61
|
-
emitOnlyDtsFiles,
|
|
62
|
-
customTransformers
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
return emit(
|
|
66
|
-
targetSourceFile,
|
|
67
|
-
writeFile,
|
|
68
|
-
cancellationToken,
|
|
69
|
-
emitOnlyDtsFiles,
|
|
70
|
-
customTransformers
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
return program;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
24
|
const windowsSlashRE = /\\+/g;
|
|
77
25
|
function slash(p) {
|
|
78
26
|
return p.replace(windowsSlashRE, "/");
|
|
@@ -196,25 +144,9 @@ function getTsConfig(tsConfigPath, readFileSync) {
|
|
|
196
144
|
Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
|
|
197
145
|
return tsConfig;
|
|
198
146
|
}
|
|
199
|
-
function getTsLibFolder(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
libFolder = normalizePath(createRequire(import.meta.url).resolve("typescript")).replace(
|
|
203
|
-
/node_modules\/typescript.*/,
|
|
204
|
-
"node_modules/typescript"
|
|
205
|
-
);
|
|
206
|
-
} catch {
|
|
207
|
-
libFolder = resolve(root, "node_modules/typescript");
|
|
208
|
-
if (!existsSync(libFolder)) {
|
|
209
|
-
if (root !== entryRoot) {
|
|
210
|
-
libFolder = resolve(entryRoot, "node_modules/typescript");
|
|
211
|
-
if (!existsSync(libFolder))
|
|
212
|
-
libFolder = void 0;
|
|
213
|
-
}
|
|
214
|
-
libFolder = void 0;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return libFolder;
|
|
147
|
+
function getTsLibFolder() {
|
|
148
|
+
const libFolder = tryGetPackageInfo("typescript")?.rootPath;
|
|
149
|
+
return libFolder && normalizePath(libFolder);
|
|
218
150
|
}
|
|
219
151
|
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
220
152
|
function base64Encode(number) {
|
|
@@ -324,7 +256,7 @@ function parseTsAliases(basePath, paths) {
|
|
|
324
256
|
const result = [];
|
|
325
257
|
for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
|
|
326
258
|
const find = new RegExp(
|
|
327
|
-
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(
|
|
259
|
+
`^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
|
|
328
260
|
);
|
|
329
261
|
let index = 1;
|
|
330
262
|
result.push({
|
|
@@ -337,6 +269,64 @@ function parseTsAliases(basePath, paths) {
|
|
|
337
269
|
}
|
|
338
270
|
return result;
|
|
339
271
|
}
|
|
272
|
+
function tryGetPackageInfo(name) {
|
|
273
|
+
try {
|
|
274
|
+
return getPackageInfoSync(name) ?? getPackageInfoSync(name, { paths: [resolveModule(name) || process.cwd()] });
|
|
275
|
+
} catch (e) {
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const hasVue = !!tryGetPackageInfo("vue");
|
|
280
|
+
const _createProgram = !hasVue ? ts.createProgram : proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
|
|
281
|
+
const { configFilePath } = options.options;
|
|
282
|
+
const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
|
|
283
|
+
if (options.host) {
|
|
284
|
+
const writeFile = options.host.writeFile.bind(options.host);
|
|
285
|
+
options.host.writeFile = (fileName, contents, ...args) => {
|
|
286
|
+
return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const vueLanguagePlugin = createVueLanguagePlugin2(
|
|
290
|
+
ts2,
|
|
291
|
+
(id) => id,
|
|
292
|
+
createRootFileChecker(
|
|
293
|
+
void 0,
|
|
294
|
+
() => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
|
|
295
|
+
options.host?.useCaseSensitiveFileNames?.() ?? false
|
|
296
|
+
),
|
|
297
|
+
options.options,
|
|
298
|
+
vueOptions
|
|
299
|
+
);
|
|
300
|
+
return [vueLanguagePlugin];
|
|
301
|
+
});
|
|
302
|
+
const createProgram = !hasVue ? ts.createProgram : (options) => {
|
|
303
|
+
const program = _createProgram(options);
|
|
304
|
+
const emit = program.emit;
|
|
305
|
+
program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
|
|
306
|
+
if (writeFile) {
|
|
307
|
+
return emit(
|
|
308
|
+
targetSourceFile,
|
|
309
|
+
(fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
310
|
+
if (fileName.endsWith(".d.ts")) {
|
|
311
|
+
data = removeEmitGlobalTypes(data);
|
|
312
|
+
}
|
|
313
|
+
return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
314
|
+
},
|
|
315
|
+
cancellationToken,
|
|
316
|
+
emitOnlyDtsFiles,
|
|
317
|
+
customTransformers
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
return emit(
|
|
321
|
+
targetSourceFile,
|
|
322
|
+
writeFile,
|
|
323
|
+
cancellationToken,
|
|
324
|
+
emitOnlyDtsFiles,
|
|
325
|
+
customTransformers
|
|
326
|
+
);
|
|
327
|
+
};
|
|
328
|
+
return program;
|
|
329
|
+
};
|
|
340
330
|
|
|
341
331
|
const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
|
|
342
332
|
function rollupDeclarationFiles({
|
|
@@ -350,7 +340,7 @@ function rollupDeclarationFiles({
|
|
|
350
340
|
rollupConfig = {},
|
|
351
341
|
rollupOptions = {}
|
|
352
342
|
}) {
|
|
353
|
-
const configObjectFullPath = resolve
|
|
343
|
+
const configObjectFullPath = resolve(root, "api-extractor.json");
|
|
354
344
|
if (!dtsRE$1.test(fileName)) {
|
|
355
345
|
fileName += ".d.ts";
|
|
356
346
|
}
|
|
@@ -380,7 +370,7 @@ function rollupDeclarationFiles({
|
|
|
380
370
|
},
|
|
381
371
|
dtsRollup: {
|
|
382
372
|
enabled: true,
|
|
383
|
-
publicTrimmedFilePath: resolve
|
|
373
|
+
publicTrimmedFilePath: resolve(outDir, fileName)
|
|
384
374
|
},
|
|
385
375
|
tsdocMetadata: {
|
|
386
376
|
enabled: false,
|
|
@@ -407,7 +397,7 @@ function rollupDeclarationFiles({
|
|
|
407
397
|
localBuild: false,
|
|
408
398
|
showVerboseMessages: false,
|
|
409
399
|
showDiagnostics: false,
|
|
410
|
-
typescriptCompilerFolder: libFolder
|
|
400
|
+
typescriptCompilerFolder: libFolder,
|
|
411
401
|
...rollupOptions
|
|
412
402
|
});
|
|
413
403
|
}
|
|
@@ -442,9 +432,9 @@ function querySvelteVersion() {
|
|
|
442
432
|
if (typeof lowerVersion === "boolean")
|
|
443
433
|
return;
|
|
444
434
|
try {
|
|
445
|
-
const version =
|
|
435
|
+
const version = tryGetPackageInfo("svelte")?.version;
|
|
446
436
|
lowerVersion = version ? compare(version, "4.0.0", "<") : false;
|
|
447
|
-
} catch {
|
|
437
|
+
} catch (e) {
|
|
448
438
|
lowerVersion = false;
|
|
449
439
|
}
|
|
450
440
|
}
|
|
@@ -792,8 +782,9 @@ function dtsPlugin(options = {}) {
|
|
|
792
782
|
};
|
|
793
783
|
const rollupConfig = { ...options.rollupConfig || {} };
|
|
794
784
|
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
795
|
-
const cleanPath = (path) => {
|
|
796
|
-
|
|
785
|
+
const cleanPath = (path, emittedFiles) => {
|
|
786
|
+
const newPath = path.replace(".vue.d.ts", ".d.ts");
|
|
787
|
+
return !emittedFiles.has(newPath) && cleanVueFileName ? newPath : path;
|
|
797
788
|
};
|
|
798
789
|
return {
|
|
799
790
|
name: pluginName,
|
|
@@ -1163,7 +1154,10 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
1163
1154
|
const entryNames = Object.keys(entries);
|
|
1164
1155
|
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
1165
1156
|
const multiple = entryNames.length > 1;
|
|
1166
|
-
let typesPath = cleanPath(
|
|
1157
|
+
let typesPath = cleanPath(
|
|
1158
|
+
types ? resolve(root, types) : resolve(outDir, indexName),
|
|
1159
|
+
emittedFiles
|
|
1160
|
+
);
|
|
1167
1161
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
1168
1162
|
logger.warn(
|
|
1169
1163
|
`
|
|
@@ -1175,11 +1169,11 @@ ${logPrefix} ${yellow(
|
|
|
1175
1169
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
1176
1170
|
}
|
|
1177
1171
|
for (const name of entryNames) {
|
|
1178
|
-
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name))) : typesPath;
|
|
1172
|
+
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
|
|
1179
1173
|
if (existsSync(entryDtsPath))
|
|
1180
1174
|
continue;
|
|
1181
1175
|
const sourceEntry = normalizePath(
|
|
1182
|
-
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))))
|
|
1176
|
+
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
|
|
1183
1177
|
);
|
|
1184
1178
|
let fromPath = normalizePath(relative(dirname(entryDtsPath), sourceEntry));
|
|
1185
1179
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -1196,7 +1190,7 @@ export default ${libName}
|
|
|
1196
1190
|
${content}`;
|
|
1197
1191
|
}
|
|
1198
1192
|
}
|
|
1199
|
-
await writeOutput(cleanPath(entryDtsPath), content, outDir);
|
|
1193
|
+
await writeOutput(cleanPath(entryDtsPath, emittedFiles), content, outDir);
|
|
1200
1194
|
}
|
|
1201
1195
|
bundleDebug("insert index");
|
|
1202
1196
|
if (rollupTypes) {
|
|
@@ -1211,7 +1205,7 @@ ${content}`;
|
|
|
1211
1205
|
outDir,
|
|
1212
1206
|
entryPath: path,
|
|
1213
1207
|
fileName: basename(path),
|
|
1214
|
-
libFolder: getTsLibFolder(
|
|
1208
|
+
libFolder: getTsLibFolder(),
|
|
1215
1209
|
rollupConfig,
|
|
1216
1210
|
rollupOptions
|
|
1217
1211
|
});
|
|
@@ -1223,7 +1217,7 @@ ${content}`;
|
|
|
1223
1217
|
};
|
|
1224
1218
|
if (multiple) {
|
|
1225
1219
|
await runParallel(cpus().length, entryNames, async (name) => {
|
|
1226
|
-
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1220
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name)), emittedFiles));
|
|
1227
1221
|
});
|
|
1228
1222
|
} else {
|
|
1229
1223
|
await rollup(typesPath);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-dts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"packageManager": "pnpm@
|
|
5
|
+
"packageManager": "pnpm@9.9.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "qmhc",
|
|
8
8
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dev": "unbuild --stub",
|
|
12
12
|
"_postinstall": "is-ci || husky install",
|
|
13
13
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx \"{src,tests}/**\"",
|
|
14
|
-
"precommit": "lint-staged -c ./.husky/.lintstagedrc -q",
|
|
14
|
+
"precommit": "lint-staged -c ./.husky/.lintstagedrc -q --allow-empty",
|
|
15
15
|
"prepublishOnly": "pinst --disable",
|
|
16
16
|
"prettier": "pretty-quick --staged && pnpm run lint",
|
|
17
17
|
"postpublish": "pinst --enable",
|