vite-plugin-dts 3.6.0 → 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +41 -21
- package/dist/index.d.cts +226 -0
- package/dist/index.d.mts +226 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +41 -21
- package/package.json +29 -25
package/dist/index.cjs
CHANGED
|
@@ -175,7 +175,7 @@ function toCapitalCase(value) {
|
|
|
175
175
|
""
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function findTypesPath(...pkgs) {
|
|
179
179
|
let path;
|
|
180
180
|
for (const pkg of pkgs) {
|
|
181
181
|
if (typeof pkg !== "object")
|
|
@@ -546,10 +546,13 @@ function dtsPlugin(options = {}) {
|
|
|
546
546
|
if (config.build.lib) {
|
|
547
547
|
const input = typeof config.build.lib.entry === "string" ? [config.build.lib.entry] : config.build.lib.entry;
|
|
548
548
|
if (Array.isArray(input)) {
|
|
549
|
-
entries = input.reduce(
|
|
550
|
-
prev
|
|
551
|
-
|
|
552
|
-
|
|
549
|
+
entries = input.reduce(
|
|
550
|
+
(prev, current) => {
|
|
551
|
+
prev[node_path.basename(current)] = current;
|
|
552
|
+
return prev;
|
|
553
|
+
},
|
|
554
|
+
{}
|
|
555
|
+
);
|
|
553
556
|
} else {
|
|
554
557
|
entries = { ...input };
|
|
555
558
|
}
|
|
@@ -581,10 +584,13 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
581
584
|
return;
|
|
582
585
|
const input = typeof options2.input === "string" ? [options2.input] : options2.input;
|
|
583
586
|
if (Array.isArray(input)) {
|
|
584
|
-
entries = input.reduce(
|
|
585
|
-
prev
|
|
586
|
-
|
|
587
|
-
|
|
587
|
+
entries = input.reduce(
|
|
588
|
+
(prev, current) => {
|
|
589
|
+
prev[node_path.basename(current)] = current;
|
|
590
|
+
return prev;
|
|
591
|
+
},
|
|
592
|
+
{}
|
|
593
|
+
);
|
|
588
594
|
} else {
|
|
589
595
|
entries = { ...input };
|
|
590
596
|
}
|
|
@@ -603,6 +609,9 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
603
609
|
configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts__default.findConfigFile(root, ts__default.sys.fileExists);
|
|
604
610
|
const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : void 0;
|
|
605
611
|
compilerOptions = {
|
|
612
|
+
// (#277) If user don't specify `moduleResolution` in top config file,
|
|
613
|
+
// declaration of Vue files will be inferred to `any` type.
|
|
614
|
+
moduleResolution: ts__default.ModuleResolutionKind.Node10,
|
|
606
615
|
...content?.options || {},
|
|
607
616
|
...options.compilerOptions || {},
|
|
608
617
|
...fixedCompilerOptions,
|
|
@@ -640,9 +649,17 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
640
649
|
include = computeGlobs(options.include, content?.raw.include, "**/*");
|
|
641
650
|
exclude = computeGlobs(options.exclude, content?.raw.exclude, "node_modules/**");
|
|
642
651
|
filter = pluginutils.createFilter(include, exclude);
|
|
643
|
-
const rootNames =
|
|
644
|
-
|
|
645
|
-
|
|
652
|
+
const rootNames = [
|
|
653
|
+
...new Set(
|
|
654
|
+
Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath)
|
|
655
|
+
)
|
|
656
|
+
];
|
|
657
|
+
host = ts__default.createCompilerHost(compilerOptions);
|
|
658
|
+
program = vueTsc.createProgram({
|
|
659
|
+
host,
|
|
660
|
+
rootNames,
|
|
661
|
+
options: compilerOptions
|
|
662
|
+
});
|
|
646
663
|
libName = toCapitalCase(libName || "_default");
|
|
647
664
|
indexName = indexName || defaultIndex;
|
|
648
665
|
const maybeEmitted = (sourceFile) => {
|
|
@@ -777,6 +794,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
777
794
|
}
|
|
778
795
|
bundleDebug("emit output patch");
|
|
779
796
|
const currentDir = host.getCurrentDirectory();
|
|
797
|
+
const vuePathRE = /['"](.+)\.vue['"]/g;
|
|
780
798
|
await runParallel(
|
|
781
799
|
node_os.cpus().length,
|
|
782
800
|
Array.from(outputFiles.entries()),
|
|
@@ -792,7 +810,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
792
810
|
outDir,
|
|
793
811
|
node_path.relative(entryRoot, cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path)
|
|
794
812
|
);
|
|
795
|
-
content = cleanVueFileName ? content.replace(
|
|
813
|
+
content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
|
|
796
814
|
if (isMapFile) {
|
|
797
815
|
try {
|
|
798
816
|
const sourceMap = JSON.parse(content);
|
|
@@ -821,9 +839,12 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
821
839
|
} catch (e) {
|
|
822
840
|
}
|
|
823
841
|
const entryNames = Object.keys(entries);
|
|
824
|
-
const types =
|
|
842
|
+
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
825
843
|
const multiple = entryNames.length > 1;
|
|
826
|
-
|
|
844
|
+
const cleanPath = (path) => {
|
|
845
|
+
return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
|
|
846
|
+
};
|
|
847
|
+
let typesPath = cleanPath(types ? resolve(root, types) : resolve(outDir, indexName));
|
|
827
848
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
828
849
|
logger.warn(
|
|
829
850
|
`
|
|
@@ -835,12 +856,11 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
835
856
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
836
857
|
}
|
|
837
858
|
for (const name of entryNames) {
|
|
838
|
-
const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
|
|
859
|
+
const path = multiple ? cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`)) : typesPath;
|
|
839
860
|
if (node_fs.existsSync(path))
|
|
840
861
|
continue;
|
|
841
|
-
const index =
|
|
842
|
-
outDir,
|
|
843
|
-
node_path.relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`)
|
|
862
|
+
const index = cleanPath(
|
|
863
|
+
resolve(outDir, node_path.relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`))
|
|
844
864
|
);
|
|
845
865
|
let fromPath = normalizePath(node_path.relative(node_path.dirname(path), index));
|
|
846
866
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -855,7 +875,7 @@ export default ${libName}
|
|
|
855
875
|
`;
|
|
856
876
|
}
|
|
857
877
|
}
|
|
858
|
-
await writeOutput(path, content, outDir);
|
|
878
|
+
await writeOutput(cleanPath(path), content, outDir);
|
|
859
879
|
}
|
|
860
880
|
bundleDebug("insert index");
|
|
861
881
|
if (rollupTypes) {
|
|
@@ -872,7 +892,7 @@ export default ${libName}
|
|
|
872
892
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
873
893
|
if (multiple) {
|
|
874
894
|
for (const name of entryNames) {
|
|
875
|
-
const path = resolve(outDir, `${name.replace(tsRE, "")}.d.ts`);
|
|
895
|
+
const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
|
|
876
896
|
rollupDeclarationFiles({
|
|
877
897
|
root,
|
|
878
898
|
configPath,
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { LogLevel } from 'vite';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
5
|
+
|
|
6
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
+
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
8
|
+
interface Resolver {
|
|
9
|
+
/**
|
|
10
|
+
* The name of the resolver
|
|
11
|
+
*
|
|
12
|
+
* The later resolver with the same name will overwrite the earlier
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Determine whether the resolver supports the file
|
|
17
|
+
*/
|
|
18
|
+
supports: (id: string) => void | boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Transform source to declaration files
|
|
21
|
+
*
|
|
22
|
+
* Note that the path of the returns should base on `outDir`, or relative path to `root`
|
|
23
|
+
*/
|
|
24
|
+
transform: (payload: {
|
|
25
|
+
id: string;
|
|
26
|
+
code: string;
|
|
27
|
+
root: string;
|
|
28
|
+
outDir: string;
|
|
29
|
+
host: ts.CompilerHost;
|
|
30
|
+
program: ts.Program;
|
|
31
|
+
service: ts.LanguageService;
|
|
32
|
+
}) => MaybePromise<{
|
|
33
|
+
path: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
}
|
|
37
|
+
interface PluginOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Specify root directory
|
|
40
|
+
*
|
|
41
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
42
|
+
*/
|
|
43
|
+
root?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Output directory for declaration files
|
|
46
|
+
*
|
|
47
|
+
* Can be an array to output to multiple directories
|
|
48
|
+
*
|
|
49
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
50
|
+
*/
|
|
51
|
+
outDir?: string | string[];
|
|
52
|
+
/**
|
|
53
|
+
* Override root path of entry files (useful in monorepos)
|
|
54
|
+
*
|
|
55
|
+
* The output path of each file will be calculated based on the value provided
|
|
56
|
+
*
|
|
57
|
+
* The default is the smallest public path for all source files
|
|
58
|
+
*/
|
|
59
|
+
entryRoot?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Restrict declaration files output to `outDir`
|
|
62
|
+
*
|
|
63
|
+
* If true, generated declaration files outside `outDir` will be ignored
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
strictOutput?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Override compilerOptions
|
|
70
|
+
*
|
|
71
|
+
* @default null
|
|
72
|
+
*/
|
|
73
|
+
compilerOptions?: ts.CompilerOptions | null;
|
|
74
|
+
/**
|
|
75
|
+
* Specify tsconfig.json path
|
|
76
|
+
*
|
|
77
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
78
|
+
*
|
|
79
|
+
* If not specified, plugin will find config file from root
|
|
80
|
+
*/
|
|
81
|
+
tsconfigPath?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Specify custom resolvers
|
|
84
|
+
*
|
|
85
|
+
* @default []
|
|
86
|
+
*/
|
|
87
|
+
resolvers?: Resolver[];
|
|
88
|
+
/**
|
|
89
|
+
* Parsing `paths` of tsconfig.json to aliases
|
|
90
|
+
*
|
|
91
|
+
* Note that these aliases only use for declaration files
|
|
92
|
+
*
|
|
93
|
+
* @default true
|
|
94
|
+
* @remarks Only use first replacement of each path
|
|
95
|
+
*/
|
|
96
|
+
pathsToAliases?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Set which paths should be excluded when transforming aliases
|
|
99
|
+
*
|
|
100
|
+
* @default []
|
|
101
|
+
*/
|
|
102
|
+
aliasesExclude?: (string | RegExp)[];
|
|
103
|
+
/**
|
|
104
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
105
|
+
*
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
cleanVueFileName?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
111
|
+
*
|
|
112
|
+
* Value is forced to `true` when `rollupTypes` is `true`
|
|
113
|
+
*
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
staticImport?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Override `include` glob (relative to root)
|
|
119
|
+
*
|
|
120
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
121
|
+
*/
|
|
122
|
+
include?: string | string[];
|
|
123
|
+
/**
|
|
124
|
+
* Override `exclude` glob
|
|
125
|
+
*
|
|
126
|
+
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
127
|
+
*/
|
|
128
|
+
exclude?: string | string[];
|
|
129
|
+
/**
|
|
130
|
+
* Whether to remove `import 'xxx'`
|
|
131
|
+
*
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
clearPureImport?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Whether to generate types entry file(s)
|
|
137
|
+
*
|
|
138
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
|
|
139
|
+
*
|
|
140
|
+
* Value is forced to `true` when `rollupTypes` is `true`
|
|
141
|
+
*
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
insertTypesEntry?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Rollup type declaration files after emitting them
|
|
147
|
+
*
|
|
148
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
149
|
+
*
|
|
150
|
+
* @default false
|
|
151
|
+
*/
|
|
152
|
+
rollupTypes?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Bundled packages for `@microsoft/api-extractor`
|
|
155
|
+
*
|
|
156
|
+
* @default []
|
|
157
|
+
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
158
|
+
*/
|
|
159
|
+
bundledPackages?: string[];
|
|
160
|
+
/**
|
|
161
|
+
* Override the config of `@microsoft/api-extractor`
|
|
162
|
+
*
|
|
163
|
+
* @default null
|
|
164
|
+
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
165
|
+
*/
|
|
166
|
+
rollupConfig?: RollupConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Override the invoke options of `@microsoft/api-extractor`
|
|
169
|
+
*
|
|
170
|
+
* @default null
|
|
171
|
+
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
172
|
+
*/
|
|
173
|
+
rollupOptions?: IExtractorInvokeOptions;
|
|
174
|
+
/**
|
|
175
|
+
* Whether to copy .d.ts source files to `outDir`
|
|
176
|
+
*
|
|
177
|
+
* @default false
|
|
178
|
+
* @remarks Before 2.0, the default was `true`
|
|
179
|
+
*/
|
|
180
|
+
copyDtsFiles?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Whether to emit declaration files only
|
|
183
|
+
*
|
|
184
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
185
|
+
*
|
|
186
|
+
* @default false
|
|
187
|
+
*/
|
|
188
|
+
declarationOnly?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Logging level for this plugin
|
|
191
|
+
*
|
|
192
|
+
* Defaults to the 'logLevel' property of your Vite config
|
|
193
|
+
*/
|
|
194
|
+
logLevel?: LogLevel;
|
|
195
|
+
/**
|
|
196
|
+
* Hook called after diagnostic is emitted
|
|
197
|
+
*
|
|
198
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
199
|
+
*
|
|
200
|
+
* @default () => {}
|
|
201
|
+
*/
|
|
202
|
+
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Hook called prior to writing each declaration file
|
|
205
|
+
*
|
|
206
|
+
* This allows you to transform the path or content
|
|
207
|
+
*
|
|
208
|
+
* The file will be skipped when the return value `false` or `Promise<false>`
|
|
209
|
+
*
|
|
210
|
+
* @default () => {}
|
|
211
|
+
*/
|
|
212
|
+
beforeWriteFile?: (filePath: string, content: string) => MaybePromise<void | false | {
|
|
213
|
+
filePath?: string;
|
|
214
|
+
content?: string;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Hook called after all declaration files are written
|
|
218
|
+
*
|
|
219
|
+
* @default () => {}
|
|
220
|
+
*/
|
|
221
|
+
afterBuild?: () => MaybePromise<void>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare function dtsPlugin(options?: PluginOptions): vite.Plugin;
|
|
225
|
+
|
|
226
|
+
export { type PluginOptions, dtsPlugin as default };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { LogLevel } from 'vite';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
5
|
+
|
|
6
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
+
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
8
|
+
interface Resolver {
|
|
9
|
+
/**
|
|
10
|
+
* The name of the resolver
|
|
11
|
+
*
|
|
12
|
+
* The later resolver with the same name will overwrite the earlier
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Determine whether the resolver supports the file
|
|
17
|
+
*/
|
|
18
|
+
supports: (id: string) => void | boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Transform source to declaration files
|
|
21
|
+
*
|
|
22
|
+
* Note that the path of the returns should base on `outDir`, or relative path to `root`
|
|
23
|
+
*/
|
|
24
|
+
transform: (payload: {
|
|
25
|
+
id: string;
|
|
26
|
+
code: string;
|
|
27
|
+
root: string;
|
|
28
|
+
outDir: string;
|
|
29
|
+
host: ts.CompilerHost;
|
|
30
|
+
program: ts.Program;
|
|
31
|
+
service: ts.LanguageService;
|
|
32
|
+
}) => MaybePromise<{
|
|
33
|
+
path: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
}
|
|
37
|
+
interface PluginOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Specify root directory
|
|
40
|
+
*
|
|
41
|
+
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
|
|
42
|
+
*/
|
|
43
|
+
root?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Output directory for declaration files
|
|
46
|
+
*
|
|
47
|
+
* Can be an array to output to multiple directories
|
|
48
|
+
*
|
|
49
|
+
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
|
|
50
|
+
*/
|
|
51
|
+
outDir?: string | string[];
|
|
52
|
+
/**
|
|
53
|
+
* Override root path of entry files (useful in monorepos)
|
|
54
|
+
*
|
|
55
|
+
* The output path of each file will be calculated based on the value provided
|
|
56
|
+
*
|
|
57
|
+
* The default is the smallest public path for all source files
|
|
58
|
+
*/
|
|
59
|
+
entryRoot?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Restrict declaration files output to `outDir`
|
|
62
|
+
*
|
|
63
|
+
* If true, generated declaration files outside `outDir` will be ignored
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
strictOutput?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Override compilerOptions
|
|
70
|
+
*
|
|
71
|
+
* @default null
|
|
72
|
+
*/
|
|
73
|
+
compilerOptions?: ts.CompilerOptions | null;
|
|
74
|
+
/**
|
|
75
|
+
* Specify tsconfig.json path
|
|
76
|
+
*
|
|
77
|
+
* Plugin resolves `include` and `exclude` globs from tsconfig.json
|
|
78
|
+
*
|
|
79
|
+
* If not specified, plugin will find config file from root
|
|
80
|
+
*/
|
|
81
|
+
tsconfigPath?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Specify custom resolvers
|
|
84
|
+
*
|
|
85
|
+
* @default []
|
|
86
|
+
*/
|
|
87
|
+
resolvers?: Resolver[];
|
|
88
|
+
/**
|
|
89
|
+
* Parsing `paths` of tsconfig.json to aliases
|
|
90
|
+
*
|
|
91
|
+
* Note that these aliases only use for declaration files
|
|
92
|
+
*
|
|
93
|
+
* @default true
|
|
94
|
+
* @remarks Only use first replacement of each path
|
|
95
|
+
*/
|
|
96
|
+
pathsToAliases?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Set which paths should be excluded when transforming aliases
|
|
99
|
+
*
|
|
100
|
+
* @default []
|
|
101
|
+
*/
|
|
102
|
+
aliasesExclude?: (string | RegExp)[];
|
|
103
|
+
/**
|
|
104
|
+
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
|
|
105
|
+
*
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
cleanVueFileName?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
|
|
111
|
+
*
|
|
112
|
+
* Value is forced to `true` when `rollupTypes` is `true`
|
|
113
|
+
*
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
staticImport?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Override `include` glob (relative to root)
|
|
119
|
+
*
|
|
120
|
+
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
|
|
121
|
+
*/
|
|
122
|
+
include?: string | string[];
|
|
123
|
+
/**
|
|
124
|
+
* Override `exclude` glob
|
|
125
|
+
*
|
|
126
|
+
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
|
|
127
|
+
*/
|
|
128
|
+
exclude?: string | string[];
|
|
129
|
+
/**
|
|
130
|
+
* Whether to remove `import 'xxx'`
|
|
131
|
+
*
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
clearPureImport?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Whether to generate types entry file(s)
|
|
137
|
+
*
|
|
138
|
+
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
|
|
139
|
+
*
|
|
140
|
+
* Value is forced to `true` when `rollupTypes` is `true`
|
|
141
|
+
*
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
insertTypesEntry?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Rollup type declaration files after emitting them
|
|
147
|
+
*
|
|
148
|
+
* Powered by `@microsoft/api-extractor` - time-intensive operation
|
|
149
|
+
*
|
|
150
|
+
* @default false
|
|
151
|
+
*/
|
|
152
|
+
rollupTypes?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Bundled packages for `@microsoft/api-extractor`
|
|
155
|
+
*
|
|
156
|
+
* @default []
|
|
157
|
+
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
158
|
+
*/
|
|
159
|
+
bundledPackages?: string[];
|
|
160
|
+
/**
|
|
161
|
+
* Override the config of `@microsoft/api-extractor`
|
|
162
|
+
*
|
|
163
|
+
* @default null
|
|
164
|
+
* @see https://api-extractor.com/pages/setup/configure_api_report/
|
|
165
|
+
*/
|
|
166
|
+
rollupConfig?: RollupConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Override the invoke options of `@microsoft/api-extractor`
|
|
169
|
+
*
|
|
170
|
+
* @default null
|
|
171
|
+
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
|
|
172
|
+
*/
|
|
173
|
+
rollupOptions?: IExtractorInvokeOptions;
|
|
174
|
+
/**
|
|
175
|
+
* Whether to copy .d.ts source files to `outDir`
|
|
176
|
+
*
|
|
177
|
+
* @default false
|
|
178
|
+
* @remarks Before 2.0, the default was `true`
|
|
179
|
+
*/
|
|
180
|
+
copyDtsFiles?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Whether to emit declaration files only
|
|
183
|
+
*
|
|
184
|
+
* When `true`, all the original outputs of vite (rollup) will be force removed
|
|
185
|
+
*
|
|
186
|
+
* @default false
|
|
187
|
+
*/
|
|
188
|
+
declarationOnly?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Logging level for this plugin
|
|
191
|
+
*
|
|
192
|
+
* Defaults to the 'logLevel' property of your Vite config
|
|
193
|
+
*/
|
|
194
|
+
logLevel?: LogLevel;
|
|
195
|
+
/**
|
|
196
|
+
* Hook called after diagnostic is emitted
|
|
197
|
+
*
|
|
198
|
+
* According to the `diagnostics.length`, you can judge whether there is any type error
|
|
199
|
+
*
|
|
200
|
+
* @default () => {}
|
|
201
|
+
*/
|
|
202
|
+
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Hook called prior to writing each declaration file
|
|
205
|
+
*
|
|
206
|
+
* This allows you to transform the path or content
|
|
207
|
+
*
|
|
208
|
+
* The file will be skipped when the return value `false` or `Promise<false>`
|
|
209
|
+
*
|
|
210
|
+
* @default () => {}
|
|
211
|
+
*/
|
|
212
|
+
beforeWriteFile?: (filePath: string, content: string) => MaybePromise<void | false | {
|
|
213
|
+
filePath?: string;
|
|
214
|
+
content?: string;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Hook called after all declaration files are written
|
|
218
|
+
*
|
|
219
|
+
* @default () => {}
|
|
220
|
+
*/
|
|
221
|
+
afterBuild?: () => MaybePromise<void>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare function dtsPlugin(options?: PluginOptions): vite.Plugin;
|
|
225
|
+
|
|
226
|
+
export { type PluginOptions, dtsPlugin as default };
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -175,7 +175,7 @@ function toCapitalCase(value) {
|
|
|
175
175
|
""
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function findTypesPath(...pkgs) {
|
|
179
179
|
let path;
|
|
180
180
|
for (const pkg of pkgs) {
|
|
181
181
|
if (typeof pkg !== "object")
|
|
@@ -546,10 +546,13 @@ function dtsPlugin(options = {}) {
|
|
|
546
546
|
if (config.build.lib) {
|
|
547
547
|
const input = typeof config.build.lib.entry === "string" ? [config.build.lib.entry] : config.build.lib.entry;
|
|
548
548
|
if (Array.isArray(input)) {
|
|
549
|
-
entries = input.reduce(
|
|
550
|
-
prev
|
|
551
|
-
|
|
552
|
-
|
|
549
|
+
entries = input.reduce(
|
|
550
|
+
(prev, current) => {
|
|
551
|
+
prev[basename(current)] = current;
|
|
552
|
+
return prev;
|
|
553
|
+
},
|
|
554
|
+
{}
|
|
555
|
+
);
|
|
553
556
|
} else {
|
|
554
557
|
entries = { ...input };
|
|
555
558
|
}
|
|
@@ -581,10 +584,13 @@ ${logPrefix} ${yellow(
|
|
|
581
584
|
return;
|
|
582
585
|
const input = typeof options2.input === "string" ? [options2.input] : options2.input;
|
|
583
586
|
if (Array.isArray(input)) {
|
|
584
|
-
entries = input.reduce(
|
|
585
|
-
prev
|
|
586
|
-
|
|
587
|
-
|
|
587
|
+
entries = input.reduce(
|
|
588
|
+
(prev, current) => {
|
|
589
|
+
prev[basename(current)] = current;
|
|
590
|
+
return prev;
|
|
591
|
+
},
|
|
592
|
+
{}
|
|
593
|
+
);
|
|
588
594
|
} else {
|
|
589
595
|
entries = { ...input };
|
|
590
596
|
}
|
|
@@ -603,6 +609,9 @@ ${logPrefix} ${yellow(
|
|
|
603
609
|
configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists);
|
|
604
610
|
const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : void 0;
|
|
605
611
|
compilerOptions = {
|
|
612
|
+
// (#277) If user don't specify `moduleResolution` in top config file,
|
|
613
|
+
// declaration of Vue files will be inferred to `any` type.
|
|
614
|
+
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
606
615
|
...content?.options || {},
|
|
607
616
|
...options.compilerOptions || {},
|
|
608
617
|
...fixedCompilerOptions,
|
|
@@ -640,9 +649,17 @@ ${logPrefix} ${yellow(
|
|
|
640
649
|
include = computeGlobs(options.include, content?.raw.include, "**/*");
|
|
641
650
|
exclude = computeGlobs(options.exclude, content?.raw.exclude, "node_modules/**");
|
|
642
651
|
filter = createFilter(include, exclude);
|
|
643
|
-
const rootNames =
|
|
644
|
-
|
|
645
|
-
|
|
652
|
+
const rootNames = [
|
|
653
|
+
...new Set(
|
|
654
|
+
Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath)
|
|
655
|
+
)
|
|
656
|
+
];
|
|
657
|
+
host = ts.createCompilerHost(compilerOptions);
|
|
658
|
+
program = createProgram({
|
|
659
|
+
host,
|
|
660
|
+
rootNames,
|
|
661
|
+
options: compilerOptions
|
|
662
|
+
});
|
|
646
663
|
libName = toCapitalCase(libName || "_default");
|
|
647
664
|
indexName = indexName || defaultIndex;
|
|
648
665
|
const maybeEmitted = (sourceFile) => {
|
|
@@ -777,6 +794,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
777
794
|
}
|
|
778
795
|
bundleDebug("emit output patch");
|
|
779
796
|
const currentDir = host.getCurrentDirectory();
|
|
797
|
+
const vuePathRE = /['"](.+)\.vue['"]/g;
|
|
780
798
|
await runParallel(
|
|
781
799
|
cpus().length,
|
|
782
800
|
Array.from(outputFiles.entries()),
|
|
@@ -792,7 +810,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
792
810
|
outDir,
|
|
793
811
|
relative(entryRoot, cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path)
|
|
794
812
|
);
|
|
795
|
-
content = cleanVueFileName ? content.replace(
|
|
813
|
+
content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
|
|
796
814
|
if (isMapFile) {
|
|
797
815
|
try {
|
|
798
816
|
const sourceMap = JSON.parse(content);
|
|
@@ -821,9 +839,12 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
821
839
|
} catch (e) {
|
|
822
840
|
}
|
|
823
841
|
const entryNames = Object.keys(entries);
|
|
824
|
-
const types =
|
|
842
|
+
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
825
843
|
const multiple = entryNames.length > 1;
|
|
826
|
-
|
|
844
|
+
const cleanPath = (path) => {
|
|
845
|
+
return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
|
|
846
|
+
};
|
|
847
|
+
let typesPath = cleanPath(types ? resolve(root, types) : resolve(outDir, indexName));
|
|
827
848
|
if (!multiple && !dtsRE.test(typesPath)) {
|
|
828
849
|
logger.warn(
|
|
829
850
|
`
|
|
@@ -835,12 +856,11 @@ ${logPrefix} ${yellow(
|
|
|
835
856
|
typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
|
|
836
857
|
}
|
|
837
858
|
for (const name of entryNames) {
|
|
838
|
-
const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
|
|
859
|
+
const path = multiple ? cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`)) : typesPath;
|
|
839
860
|
if (existsSync(path))
|
|
840
861
|
continue;
|
|
841
|
-
const index =
|
|
842
|
-
outDir,
|
|
843
|
-
relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`)
|
|
862
|
+
const index = cleanPath(
|
|
863
|
+
resolve(outDir, relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`))
|
|
844
864
|
);
|
|
845
865
|
let fromPath = normalizePath(relative(dirname(path), index));
|
|
846
866
|
fromPath = fromPath.replace(dtsRE, "");
|
|
@@ -855,7 +875,7 @@ export default ${libName}
|
|
|
855
875
|
`;
|
|
856
876
|
}
|
|
857
877
|
}
|
|
858
|
-
await writeOutput(path, content, outDir);
|
|
878
|
+
await writeOutput(cleanPath(path), content, outDir);
|
|
859
879
|
}
|
|
860
880
|
bundleDebug("insert index");
|
|
861
881
|
if (rollupTypes) {
|
|
@@ -872,7 +892,7 @@ export default ${libName}
|
|
|
872
892
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
873
893
|
if (multiple) {
|
|
874
894
|
for (const name of entryNames) {
|
|
875
|
-
const path = resolve(outDir, `${name.replace(tsRE, "")}.d.ts`);
|
|
895
|
+
const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
|
|
876
896
|
rollupDeclarationFiles({
|
|
877
897
|
root,
|
|
878
898
|
configPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-dts",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "qmhc",
|
|
@@ -50,46 +50,50 @@
|
|
|
50
50
|
"vite-plugin",
|
|
51
51
|
"ts",
|
|
52
52
|
"dts",
|
|
53
|
-
"typescript"
|
|
53
|
+
"typescript",
|
|
54
|
+
"vue",
|
|
55
|
+
"tsc",
|
|
56
|
+
"vue-tsc",
|
|
57
|
+
"volar"
|
|
54
58
|
],
|
|
55
59
|
"dependencies": {
|
|
56
|
-
"@microsoft/api-extractor": "^7.
|
|
57
|
-
"@rollup/pluginutils": "^5.0.
|
|
58
|
-
"@vue/language-core": "^1.8.
|
|
60
|
+
"@microsoft/api-extractor": "^7.38.0",
|
|
61
|
+
"@rollup/pluginutils": "^5.0.5",
|
|
62
|
+
"@vue/language-core": "^1.8.20",
|
|
59
63
|
"debug": "^4.3.4",
|
|
60
64
|
"kolorist": "^1.8.0",
|
|
61
|
-
"vue-tsc": "^1.8.
|
|
65
|
+
"vue-tsc": "^1.8.20"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
|
-
"@commitlint/cli": "^
|
|
65
|
-
"@types/debug": "^4.1.
|
|
66
|
-
"@types/minimist": "^1.2.
|
|
67
|
-
"@types/node": "^20.
|
|
68
|
-
"@types/prompts": "^2.4.
|
|
69
|
-
"@types/semver": "^7.5.
|
|
68
|
+
"@commitlint/cli": "^18.0.0",
|
|
69
|
+
"@types/debug": "^4.1.10",
|
|
70
|
+
"@types/minimist": "^1.2.4",
|
|
71
|
+
"@types/node": "^20.8.8",
|
|
72
|
+
"@types/prompts": "^2.4.7",
|
|
73
|
+
"@types/semver": "^7.5.4",
|
|
70
74
|
"@vexip-ui/commitlint-config": "^0.2.0",
|
|
71
75
|
"@vexip-ui/eslint-config": "^0.8.1",
|
|
72
76
|
"@vexip-ui/prettier-config": "^0.2.0",
|
|
73
77
|
"@vue/eslint-config-standard": "^8.0.1",
|
|
74
|
-
"@vue/eslint-config-typescript": "^
|
|
75
|
-
"conventional-changelog-cli": "^
|
|
76
|
-
"eslint": "^8.
|
|
77
|
-
"execa": "^
|
|
78
|
+
"@vue/eslint-config-typescript": "^12.0.0",
|
|
79
|
+
"conventional-changelog-cli": "^4.1.0",
|
|
80
|
+
"eslint": "^8.52.0",
|
|
81
|
+
"execa": "^8.0.1",
|
|
78
82
|
"husky": "^8.0.3",
|
|
79
83
|
"is-ci": "^3.0.1",
|
|
80
|
-
"lint-staged": "^
|
|
84
|
+
"lint-staged": "^15.0.2",
|
|
81
85
|
"minimist": "^1.2.8",
|
|
82
86
|
"pinst": "^3.0.0",
|
|
83
|
-
"prettier": "^
|
|
87
|
+
"prettier": "^3.0.3",
|
|
84
88
|
"pretty-quick": "^3.1.3",
|
|
85
89
|
"prompts": "^2.4.2",
|
|
86
|
-
"rimraf": "^5.0.
|
|
90
|
+
"rimraf": "^5.0.5",
|
|
87
91
|
"semver": "^7.5.4",
|
|
88
|
-
"tsx": "^3.
|
|
89
|
-
"typescript": "5.
|
|
90
|
-
"unbuild": "^
|
|
91
|
-
"vite": "^4.
|
|
92
|
-
"vitest": "^0.34.
|
|
92
|
+
"tsx": "^3.14.0",
|
|
93
|
+
"typescript": "5.2.2",
|
|
94
|
+
"unbuild": "^2.0.0",
|
|
95
|
+
"vite": "^4.5.0",
|
|
96
|
+
"vitest": "^0.34.6"
|
|
93
97
|
},
|
|
94
98
|
"peerDependencies": {
|
|
95
99
|
"typescript": "*",
|
|
@@ -102,7 +106,7 @@
|
|
|
102
106
|
},
|
|
103
107
|
"pnpm": {
|
|
104
108
|
"patchedDependencies": {
|
|
105
|
-
"@microsoft/api-extractor@7.
|
|
109
|
+
"@microsoft/api-extractor@7.38.0": "patches/@microsoft__api-extractor@7.38.0.patch"
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
}
|