vite-plugin-dts 3.3.0 → 3.4.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 +349 -332
- package/README.zh-CN.md +349 -332
- package/dist/index.cjs +33 -13
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +33 -13
- package/package.json +14 -17
package/dist/index.cjs
CHANGED
|
@@ -167,6 +167,14 @@ function tryGetPkgPath(beginPath) {
|
|
|
167
167
|
}
|
|
168
168
|
return tryGetPkgPath(parentDir);
|
|
169
169
|
}
|
|
170
|
+
function toCapitalCase(value) {
|
|
171
|
+
value = value.trim().replace(/\s+/g, "-");
|
|
172
|
+
value = value.replace(/-+(\w)/g, (_, char) => char ? char.toUpperCase() : "");
|
|
173
|
+
return (value.charAt(0).toLocaleUpperCase() + value.slice(1)).replace(
|
|
174
|
+
/[^\w]/g,
|
|
175
|
+
""
|
|
176
|
+
);
|
|
177
|
+
}
|
|
170
178
|
|
|
171
179
|
const dtsRE$1 = /\.d\.tsx?$/;
|
|
172
180
|
function rollupDeclarationFiles({
|
|
@@ -177,7 +185,7 @@ function rollupDeclarationFiles({
|
|
|
177
185
|
entryPath,
|
|
178
186
|
fileName,
|
|
179
187
|
libFolder,
|
|
180
|
-
|
|
188
|
+
rollupConfig = {}
|
|
181
189
|
}) {
|
|
182
190
|
const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
|
|
183
191
|
if (!dtsRE$1.test(fileName)) {
|
|
@@ -185,9 +193,9 @@ function rollupDeclarationFiles({
|
|
|
185
193
|
}
|
|
186
194
|
const extractorConfig = apiExtractor.ExtractorConfig.prepare({
|
|
187
195
|
configObject: {
|
|
196
|
+
...rollupConfig,
|
|
188
197
|
projectFolder: root,
|
|
189
198
|
mainEntryPointFilePath: entryPath,
|
|
190
|
-
bundledPackages,
|
|
191
199
|
compiler: {
|
|
192
200
|
tsconfigFilePath: configPath,
|
|
193
201
|
overrideTsconfig: {
|
|
@@ -196,17 +204,21 @@ function rollupDeclarationFiles({
|
|
|
196
204
|
}
|
|
197
205
|
},
|
|
198
206
|
apiReport: {
|
|
199
|
-
enabled: false
|
|
207
|
+
enabled: false,
|
|
208
|
+
reportFileName: "<unscopedPackageName>.api.md",
|
|
209
|
+
...rollupConfig.apiReport
|
|
200
210
|
},
|
|
201
211
|
docModel: {
|
|
202
|
-
enabled: false
|
|
212
|
+
enabled: false,
|
|
213
|
+
...rollupConfig.docModel
|
|
203
214
|
},
|
|
204
215
|
dtsRollup: {
|
|
205
216
|
enabled: true,
|
|
206
217
|
publicTrimmedFilePath: node_path.resolve(outDir, fileName)
|
|
207
218
|
},
|
|
208
219
|
tsdocMetadata: {
|
|
209
|
-
enabled: false
|
|
220
|
+
enabled: false,
|
|
221
|
+
...rollupConfig.tsdocMetadata
|
|
210
222
|
},
|
|
211
223
|
messages: {
|
|
212
224
|
compilerMessageReporting: {
|
|
@@ -218,7 +230,8 @@ function rollupDeclarationFiles({
|
|
|
218
230
|
default: {
|
|
219
231
|
logLevel: "none"
|
|
220
232
|
}
|
|
221
|
-
}
|
|
233
|
+
},
|
|
234
|
+
...rollupConfig.messages
|
|
222
235
|
}
|
|
223
236
|
},
|
|
224
237
|
configObjectFullPath,
|
|
@@ -455,7 +468,6 @@ function dtsPlugin(options = {}) {
|
|
|
455
468
|
cleanVueFileName = false,
|
|
456
469
|
insertTypesEntry = false,
|
|
457
470
|
rollupTypes = false,
|
|
458
|
-
bundledPackages = [],
|
|
459
471
|
pathsToAliases = true,
|
|
460
472
|
aliasesExclude = [],
|
|
461
473
|
copyDtsFiles = false,
|
|
@@ -491,6 +503,8 @@ function dtsPlugin(options = {}) {
|
|
|
491
503
|
]);
|
|
492
504
|
const rootFiles = /* @__PURE__ */ new Set();
|
|
493
505
|
const outputFiles = /* @__PURE__ */ new Map();
|
|
506
|
+
const rollupConfig = { ...options.rollupConfig || {} };
|
|
507
|
+
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
494
508
|
return {
|
|
495
509
|
name: "vite:dts",
|
|
496
510
|
apply: "build",
|
|
@@ -610,7 +624,7 @@ ${kolorist.cyan(
|
|
|
610
624
|
const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
|
|
611
625
|
host = ts__default.createCompilerHost(compilerOptions, true);
|
|
612
626
|
program = vueTsc.createProgram({ host, rootNames, options: compilerOptions });
|
|
613
|
-
libName = libName || "_default";
|
|
627
|
+
libName = toCapitalCase(libName || "_default");
|
|
614
628
|
indexName = indexName || defaultIndex;
|
|
615
629
|
const maybeEmitted = (sourceFile) => {
|
|
616
630
|
return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
|
|
@@ -665,7 +679,7 @@ ${kolorist.cyan(
|
|
|
665
679
|
} else {
|
|
666
680
|
const sourceFile = program.getSourceFile(id);
|
|
667
681
|
if (sourceFile) {
|
|
668
|
-
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
|
|
682
|
+
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true, true).outputFiles) {
|
|
669
683
|
outputFiles.set(
|
|
670
684
|
resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
|
|
671
685
|
outputFile.text
|
|
@@ -693,7 +707,7 @@ ${kolorist.cyan(
|
|
|
693
707
|
}
|
|
694
708
|
},
|
|
695
709
|
async writeBundle() {
|
|
696
|
-
if (!program || bundled)
|
|
710
|
+
if (!host || !program || bundled)
|
|
697
711
|
return;
|
|
698
712
|
bundled = true;
|
|
699
713
|
bundleDebug("begin writeBundle");
|
|
@@ -743,6 +757,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
743
757
|
}
|
|
744
758
|
}
|
|
745
759
|
bundleDebug("emit output patch");
|
|
760
|
+
const currentDir = host.getCurrentDirectory();
|
|
746
761
|
await runParallel(
|
|
747
762
|
node_os.cpus().length,
|
|
748
763
|
Array.from(outputFiles.entries()),
|
|
@@ -763,7 +778,12 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
763
778
|
try {
|
|
764
779
|
const sourceMap = JSON.parse(content);
|
|
765
780
|
sourceMap.sources = sourceMap.sources.map((source) => {
|
|
766
|
-
return normalizePath(
|
|
781
|
+
return normalizePath(
|
|
782
|
+
node_path.relative(
|
|
783
|
+
node_path.dirname(path),
|
|
784
|
+
resolve(currentDir, node_path.relative(publicRoot, baseDir), source)
|
|
785
|
+
)
|
|
786
|
+
);
|
|
767
787
|
});
|
|
768
788
|
content = JSON.stringify(sourceMap);
|
|
769
789
|
} catch (e) {
|
|
@@ -832,7 +852,7 @@ export default ${libName}
|
|
|
832
852
|
entryPath: path,
|
|
833
853
|
fileName: node_path.basename(path),
|
|
834
854
|
libFolder,
|
|
835
|
-
|
|
855
|
+
rollupConfig
|
|
836
856
|
});
|
|
837
857
|
emittedFiles.delete(path);
|
|
838
858
|
rollupFiles.add(path);
|
|
@@ -846,7 +866,7 @@ export default ${libName}
|
|
|
846
866
|
entryPath: typesPath,
|
|
847
867
|
fileName: node_path.basename(typesPath),
|
|
848
868
|
libFolder,
|
|
849
|
-
|
|
869
|
+
rollupConfig
|
|
850
870
|
});
|
|
851
871
|
emittedFiles.delete(typesPath);
|
|
852
872
|
rollupFiles.add(typesPath);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { LogLevel } from 'vite';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
+
import { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
4
5
|
|
|
5
6
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
+
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
6
8
|
interface Resolver {
|
|
7
9
|
/**
|
|
8
10
|
* The name of the resolver
|
|
@@ -155,6 +157,13 @@ interface PluginOptions {
|
|
|
155
157
|
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
|
|
156
158
|
*/
|
|
157
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;
|
|
158
167
|
/**
|
|
159
168
|
* Whether to copy .d.ts source files to `outDir`
|
|
160
169
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -167,6 +167,14 @@ function tryGetPkgPath(beginPath) {
|
|
|
167
167
|
}
|
|
168
168
|
return tryGetPkgPath(parentDir);
|
|
169
169
|
}
|
|
170
|
+
function toCapitalCase(value) {
|
|
171
|
+
value = value.trim().replace(/\s+/g, "-");
|
|
172
|
+
value = value.replace(/-+(\w)/g, (_, char) => char ? char.toUpperCase() : "");
|
|
173
|
+
return (value.charAt(0).toLocaleUpperCase() + value.slice(1)).replace(
|
|
174
|
+
/[^\w]/g,
|
|
175
|
+
""
|
|
176
|
+
);
|
|
177
|
+
}
|
|
170
178
|
|
|
171
179
|
const dtsRE$1 = /\.d\.tsx?$/;
|
|
172
180
|
function rollupDeclarationFiles({
|
|
@@ -177,7 +185,7 @@ function rollupDeclarationFiles({
|
|
|
177
185
|
entryPath,
|
|
178
186
|
fileName,
|
|
179
187
|
libFolder,
|
|
180
|
-
|
|
188
|
+
rollupConfig = {}
|
|
181
189
|
}) {
|
|
182
190
|
const configObjectFullPath = resolve$1(root, "api-extractor.json");
|
|
183
191
|
if (!dtsRE$1.test(fileName)) {
|
|
@@ -185,9 +193,9 @@ function rollupDeclarationFiles({
|
|
|
185
193
|
}
|
|
186
194
|
const extractorConfig = ExtractorConfig.prepare({
|
|
187
195
|
configObject: {
|
|
196
|
+
...rollupConfig,
|
|
188
197
|
projectFolder: root,
|
|
189
198
|
mainEntryPointFilePath: entryPath,
|
|
190
|
-
bundledPackages,
|
|
191
199
|
compiler: {
|
|
192
200
|
tsconfigFilePath: configPath,
|
|
193
201
|
overrideTsconfig: {
|
|
@@ -196,17 +204,21 @@ function rollupDeclarationFiles({
|
|
|
196
204
|
}
|
|
197
205
|
},
|
|
198
206
|
apiReport: {
|
|
199
|
-
enabled: false
|
|
207
|
+
enabled: false,
|
|
208
|
+
reportFileName: "<unscopedPackageName>.api.md",
|
|
209
|
+
...rollupConfig.apiReport
|
|
200
210
|
},
|
|
201
211
|
docModel: {
|
|
202
|
-
enabled: false
|
|
212
|
+
enabled: false,
|
|
213
|
+
...rollupConfig.docModel
|
|
203
214
|
},
|
|
204
215
|
dtsRollup: {
|
|
205
216
|
enabled: true,
|
|
206
217
|
publicTrimmedFilePath: resolve$1(outDir, fileName)
|
|
207
218
|
},
|
|
208
219
|
tsdocMetadata: {
|
|
209
|
-
enabled: false
|
|
220
|
+
enabled: false,
|
|
221
|
+
...rollupConfig.tsdocMetadata
|
|
210
222
|
},
|
|
211
223
|
messages: {
|
|
212
224
|
compilerMessageReporting: {
|
|
@@ -218,7 +230,8 @@ function rollupDeclarationFiles({
|
|
|
218
230
|
default: {
|
|
219
231
|
logLevel: "none"
|
|
220
232
|
}
|
|
221
|
-
}
|
|
233
|
+
},
|
|
234
|
+
...rollupConfig.messages
|
|
222
235
|
}
|
|
223
236
|
},
|
|
224
237
|
configObjectFullPath,
|
|
@@ -455,7 +468,6 @@ function dtsPlugin(options = {}) {
|
|
|
455
468
|
cleanVueFileName = false,
|
|
456
469
|
insertTypesEntry = false,
|
|
457
470
|
rollupTypes = false,
|
|
458
|
-
bundledPackages = [],
|
|
459
471
|
pathsToAliases = true,
|
|
460
472
|
aliasesExclude = [],
|
|
461
473
|
copyDtsFiles = false,
|
|
@@ -491,6 +503,8 @@ function dtsPlugin(options = {}) {
|
|
|
491
503
|
]);
|
|
492
504
|
const rootFiles = /* @__PURE__ */ new Set();
|
|
493
505
|
const outputFiles = /* @__PURE__ */ new Map();
|
|
506
|
+
const rollupConfig = { ...options.rollupConfig || {} };
|
|
507
|
+
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
|
|
494
508
|
return {
|
|
495
509
|
name: "vite:dts",
|
|
496
510
|
apply: "build",
|
|
@@ -610,7 +624,7 @@ ${cyan(
|
|
|
610
624
|
const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
|
|
611
625
|
host = ts.createCompilerHost(compilerOptions, true);
|
|
612
626
|
program = createProgram({ host, rootNames, options: compilerOptions });
|
|
613
|
-
libName = libName || "_default";
|
|
627
|
+
libName = toCapitalCase(libName || "_default");
|
|
614
628
|
indexName = indexName || defaultIndex;
|
|
615
629
|
const maybeEmitted = (sourceFile) => {
|
|
616
630
|
return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
|
|
@@ -665,7 +679,7 @@ ${cyan(
|
|
|
665
679
|
} else {
|
|
666
680
|
const sourceFile = program.getSourceFile(id);
|
|
667
681
|
if (sourceFile) {
|
|
668
|
-
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
|
|
682
|
+
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true, true).outputFiles) {
|
|
669
683
|
outputFiles.set(
|
|
670
684
|
resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
|
|
671
685
|
outputFile.text
|
|
@@ -693,7 +707,7 @@ ${cyan(
|
|
|
693
707
|
}
|
|
694
708
|
},
|
|
695
709
|
async writeBundle() {
|
|
696
|
-
if (!program || bundled)
|
|
710
|
+
if (!host || !program || bundled)
|
|
697
711
|
return;
|
|
698
712
|
bundled = true;
|
|
699
713
|
bundleDebug("begin writeBundle");
|
|
@@ -743,6 +757,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
743
757
|
}
|
|
744
758
|
}
|
|
745
759
|
bundleDebug("emit output patch");
|
|
760
|
+
const currentDir = host.getCurrentDirectory();
|
|
746
761
|
await runParallel(
|
|
747
762
|
cpus().length,
|
|
748
763
|
Array.from(outputFiles.entries()),
|
|
@@ -763,7 +778,12 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
763
778
|
try {
|
|
764
779
|
const sourceMap = JSON.parse(content);
|
|
765
780
|
sourceMap.sources = sourceMap.sources.map((source) => {
|
|
766
|
-
return normalizePath(
|
|
781
|
+
return normalizePath(
|
|
782
|
+
relative(
|
|
783
|
+
dirname(path),
|
|
784
|
+
resolve(currentDir, relative(publicRoot, baseDir), source)
|
|
785
|
+
)
|
|
786
|
+
);
|
|
767
787
|
});
|
|
768
788
|
content = JSON.stringify(sourceMap);
|
|
769
789
|
} catch (e) {
|
|
@@ -832,7 +852,7 @@ export default ${libName}
|
|
|
832
852
|
entryPath: path,
|
|
833
853
|
fileName: basename(path),
|
|
834
854
|
libFolder,
|
|
835
|
-
|
|
855
|
+
rollupConfig
|
|
836
856
|
});
|
|
837
857
|
emittedFiles.delete(path);
|
|
838
858
|
rollupFiles.add(path);
|
|
@@ -846,7 +866,7 @@ export default ${libName}
|
|
|
846
866
|
entryPath: typesPath,
|
|
847
867
|
fileName: basename(typesPath),
|
|
848
868
|
libFolder,
|
|
849
|
-
|
|
869
|
+
rollupConfig
|
|
850
870
|
});
|
|
851
871
|
emittedFiles.delete(typesPath);
|
|
852
872
|
rollupFiles.add(typesPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-dts",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "qmhc",
|
|
@@ -53,46 +53,43 @@
|
|
|
53
53
|
"typescript"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@microsoft/api-extractor": "^7.36.
|
|
56
|
+
"@microsoft/api-extractor": "^7.36.3",
|
|
57
57
|
"@rollup/pluginutils": "^5.0.2",
|
|
58
|
-
"@vue/language-core": "^1.8.
|
|
58
|
+
"@vue/language-core": "^1.8.8",
|
|
59
59
|
"debug": "^4.3.4",
|
|
60
60
|
"kolorist": "^1.8.0",
|
|
61
|
-
"vue-tsc": "^1.8.
|
|
61
|
+
"vue-tsc": "^1.8.8"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@commitlint/cli": "^17.6.
|
|
65
|
-
"@commitlint/config-conventional": "^17.6.6",
|
|
64
|
+
"@commitlint/cli": "^17.6.7",
|
|
66
65
|
"@types/debug": "^4.1.8",
|
|
67
66
|
"@types/minimist": "^1.2.2",
|
|
68
|
-
"@types/node": "^20.
|
|
67
|
+
"@types/node": "^20.4.5",
|
|
69
68
|
"@types/prompts": "^2.4.4",
|
|
70
69
|
"@types/semver": "^7.5.0",
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@vexip-ui/commitlint-config": "^0.1.0",
|
|
74
|
-
"@vexip-ui/eslint-config": "^0.6.3",
|
|
70
|
+
"@vexip-ui/commitlint-config": "^0.2.0",
|
|
71
|
+
"@vexip-ui/eslint-config": "^0.8.1",
|
|
75
72
|
"@vexip-ui/prettier-config": "^0.2.0",
|
|
76
73
|
"@vue/eslint-config-standard": "^8.0.1",
|
|
77
74
|
"@vue/eslint-config-typescript": "^11.0.3",
|
|
78
75
|
"conventional-changelog-cli": "^3.0.0",
|
|
79
|
-
"eslint": "^8.
|
|
80
|
-
"execa": "^7.
|
|
76
|
+
"eslint": "^8.46.0",
|
|
77
|
+
"execa": "^7.2.0",
|
|
81
78
|
"husky": "^8.0.3",
|
|
82
79
|
"is-ci": "^3.0.1",
|
|
83
|
-
"lint-staged": "^13.2.
|
|
80
|
+
"lint-staged": "^13.2.3",
|
|
84
81
|
"minimist": "^1.2.8",
|
|
85
82
|
"pinst": "^3.0.0",
|
|
86
83
|
"prettier": "^2.8.8",
|
|
87
84
|
"pretty-quick": "^3.1.3",
|
|
88
85
|
"prompts": "^2.4.2",
|
|
89
86
|
"rimraf": "^5.0.1",
|
|
90
|
-
"semver": "^7.5.
|
|
87
|
+
"semver": "^7.5.4",
|
|
91
88
|
"tsx": "^3.12.7",
|
|
92
89
|
"typescript": "5.0.4",
|
|
93
90
|
"unbuild": "^1.2.1",
|
|
94
|
-
"vite": "^4.
|
|
95
|
-
"vitest": "^0.
|
|
91
|
+
"vite": "^4.4.7",
|
|
92
|
+
"vitest": "^0.33.0"
|
|
96
93
|
},
|
|
97
94
|
"peerDependencies": {
|
|
98
95
|
"typescript": "*",
|