vite-plugin-dts 3.8.2 → 3.9.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 +400 -393
- package/README.zh-CN.md +400 -393
- package/dist/index.cjs +26 -25
- package/dist/index.d.cts +7 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +26 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -307,14 +307,13 @@ function rollupDeclarationFiles({
|
|
|
307
307
|
configObjectFullPath,
|
|
308
308
|
packageJsonFullPath: tryGetPkgPath(configObjectFullPath)
|
|
309
309
|
});
|
|
310
|
-
|
|
310
|
+
return apiExtractor.Extractor.invoke(extractorConfig, {
|
|
311
311
|
localBuild: false,
|
|
312
312
|
showVerboseMessages: false,
|
|
313
313
|
showDiagnostics: false,
|
|
314
314
|
typescriptCompilerFolder: libFolder ? node_path.resolve(libFolder) : void 0,
|
|
315
315
|
...rollupOptions
|
|
316
316
|
});
|
|
317
|
-
return result.succeeded;
|
|
318
317
|
}
|
|
319
318
|
|
|
320
319
|
const jsonRE = /\.json$/;
|
|
@@ -563,6 +562,14 @@ function hasExportDefault(content) {
|
|
|
563
562
|
for (const element of node.exportClause.elements) {
|
|
564
563
|
if (element.name.escapedText === "default") {
|
|
565
564
|
has = true;
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
} else if ("modifiers" in node && Array.isArray(node.modifiers) && node.modifiers.length > 1) {
|
|
569
|
+
for (let i = 0, len = node.modifiers.length; i < len; ++i) {
|
|
570
|
+
if (node.modifiers[i].kind === ts__default.SyntaxKind.ExportKeyword && node.modifiers[i + 1]?.kind === ts__default.SyntaxKind.DefaultKeyword) {
|
|
571
|
+
has = true;
|
|
572
|
+
break;
|
|
566
573
|
}
|
|
567
574
|
}
|
|
568
575
|
}
|
|
@@ -616,6 +623,7 @@ function dtsPlugin(options = {}) {
|
|
|
616
623
|
strictOutput = true,
|
|
617
624
|
afterDiagnostic = noop,
|
|
618
625
|
beforeWriteFile = noop,
|
|
626
|
+
afterRollup = noop,
|
|
619
627
|
afterBuild = noop
|
|
620
628
|
} = options;
|
|
621
629
|
let root = ensureAbsolute(options.root ?? "", process.cwd());
|
|
@@ -1035,37 +1043,30 @@ export default ${libName}
|
|
|
1035
1043
|
}
|
|
1036
1044
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
1037
1045
|
const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const path = cleanPath(resolve(outDir, tsToDts(name)));
|
|
1041
|
-
rollupDeclarationFiles({
|
|
1042
|
-
root,
|
|
1043
|
-
configPath,
|
|
1044
|
-
compilerOptions: compilerOptions2,
|
|
1045
|
-
outDir,
|
|
1046
|
-
entryPath: path,
|
|
1047
|
-
fileName: node_path.basename(path),
|
|
1048
|
-
libFolder,
|
|
1049
|
-
rollupConfig,
|
|
1050
|
-
rollupOptions
|
|
1051
|
-
});
|
|
1052
|
-
emittedFiles.delete(path);
|
|
1053
|
-
rollupFiles.add(path);
|
|
1054
|
-
}
|
|
1055
|
-
} else {
|
|
1056
|
-
rollupDeclarationFiles({
|
|
1046
|
+
const rollup = async (path) => {
|
|
1047
|
+
const result = rollupDeclarationFiles({
|
|
1057
1048
|
root,
|
|
1058
1049
|
configPath,
|
|
1059
1050
|
compilerOptions: compilerOptions2,
|
|
1060
1051
|
outDir,
|
|
1061
|
-
entryPath:
|
|
1062
|
-
fileName: node_path.basename(
|
|
1052
|
+
entryPath: path,
|
|
1053
|
+
fileName: node_path.basename(path),
|
|
1063
1054
|
libFolder,
|
|
1064
1055
|
rollupConfig,
|
|
1065
1056
|
rollupOptions
|
|
1066
1057
|
});
|
|
1067
|
-
emittedFiles.delete(
|
|
1068
|
-
rollupFiles.add(
|
|
1058
|
+
emittedFiles.delete(path);
|
|
1059
|
+
rollupFiles.add(path);
|
|
1060
|
+
if (typeof afterRollup === "function") {
|
|
1061
|
+
await unwrapPromise(afterRollup(result));
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
if (multiple) {
|
|
1065
|
+
await runParallel(node_os.cpus().length, entryNames, async (name) => {
|
|
1066
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1067
|
+
});
|
|
1068
|
+
} else {
|
|
1069
|
+
await rollup(typesPath);
|
|
1069
1070
|
}
|
|
1070
1071
|
await runParallel(node_os.cpus().length, Array.from(emittedFiles.keys()), (f) => promises.unlink(f));
|
|
1071
1072
|
removeDirIfEmpty(outDir);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { LogLevel } from 'vite';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
4
|
+
import { IExtractorInvokeOptions, ExtractorResult, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
5
5
|
|
|
6
6
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
7
|
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
@@ -213,6 +213,12 @@ interface PluginOptions {
|
|
|
213
213
|
filePath?: string;
|
|
214
214
|
content?: string;
|
|
215
215
|
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Hook called after rolling up declaration files
|
|
218
|
+
*
|
|
219
|
+
* @default () => {}
|
|
220
|
+
*/
|
|
221
|
+
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
216
222
|
/**
|
|
217
223
|
* Hook called after all declaration files are written
|
|
218
224
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { LogLevel } from 'vite';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
4
|
+
import { IExtractorInvokeOptions, ExtractorResult, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
5
5
|
|
|
6
6
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
7
|
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
@@ -213,6 +213,12 @@ interface PluginOptions {
|
|
|
213
213
|
filePath?: string;
|
|
214
214
|
content?: string;
|
|
215
215
|
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Hook called after rolling up declaration files
|
|
218
|
+
*
|
|
219
|
+
* @default () => {}
|
|
220
|
+
*/
|
|
221
|
+
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
216
222
|
/**
|
|
217
223
|
* Hook called after all declaration files are written
|
|
218
224
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { LogLevel } from 'vite';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
4
|
+
import { IExtractorInvokeOptions, ExtractorResult, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
|
|
5
5
|
|
|
6
6
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
7
|
type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
|
|
@@ -213,6 +213,12 @@ interface PluginOptions {
|
|
|
213
213
|
filePath?: string;
|
|
214
214
|
content?: string;
|
|
215
215
|
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Hook called after rolling up declaration files
|
|
218
|
+
*
|
|
219
|
+
* @default () => {}
|
|
220
|
+
*/
|
|
221
|
+
afterRollup?: (result: ExtractorResult) => MaybePromise<void>;
|
|
216
222
|
/**
|
|
217
223
|
* Hook called after all declaration files are written
|
|
218
224
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -304,14 +304,13 @@ function rollupDeclarationFiles({
|
|
|
304
304
|
configObjectFullPath,
|
|
305
305
|
packageJsonFullPath: tryGetPkgPath(configObjectFullPath)
|
|
306
306
|
});
|
|
307
|
-
|
|
307
|
+
return Extractor.invoke(extractorConfig, {
|
|
308
308
|
localBuild: false,
|
|
309
309
|
showVerboseMessages: false,
|
|
310
310
|
showDiagnostics: false,
|
|
311
311
|
typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0,
|
|
312
312
|
...rollupOptions
|
|
313
313
|
});
|
|
314
|
-
return result.succeeded;
|
|
315
314
|
}
|
|
316
315
|
|
|
317
316
|
const jsonRE = /\.json$/;
|
|
@@ -560,6 +559,14 @@ function hasExportDefault(content) {
|
|
|
560
559
|
for (const element of node.exportClause.elements) {
|
|
561
560
|
if (element.name.escapedText === "default") {
|
|
562
561
|
has = true;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
} else if ("modifiers" in node && Array.isArray(node.modifiers) && node.modifiers.length > 1) {
|
|
566
|
+
for (let i = 0, len = node.modifiers.length; i < len; ++i) {
|
|
567
|
+
if (node.modifiers[i].kind === ts.SyntaxKind.ExportKeyword && node.modifiers[i + 1]?.kind === ts.SyntaxKind.DefaultKeyword) {
|
|
568
|
+
has = true;
|
|
569
|
+
break;
|
|
563
570
|
}
|
|
564
571
|
}
|
|
565
572
|
}
|
|
@@ -613,6 +620,7 @@ function dtsPlugin(options = {}) {
|
|
|
613
620
|
strictOutput = true,
|
|
614
621
|
afterDiagnostic = noop,
|
|
615
622
|
beforeWriteFile = noop,
|
|
623
|
+
afterRollup = noop,
|
|
616
624
|
afterBuild = noop
|
|
617
625
|
} = options;
|
|
618
626
|
let root = ensureAbsolute(options.root ?? "", process.cwd());
|
|
@@ -1032,37 +1040,30 @@ export default ${libName}
|
|
|
1032
1040
|
}
|
|
1033
1041
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
1034
1042
|
const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
const path = cleanPath(resolve(outDir, tsToDts(name)));
|
|
1038
|
-
rollupDeclarationFiles({
|
|
1039
|
-
root,
|
|
1040
|
-
configPath,
|
|
1041
|
-
compilerOptions: compilerOptions2,
|
|
1042
|
-
outDir,
|
|
1043
|
-
entryPath: path,
|
|
1044
|
-
fileName: basename(path),
|
|
1045
|
-
libFolder,
|
|
1046
|
-
rollupConfig,
|
|
1047
|
-
rollupOptions
|
|
1048
|
-
});
|
|
1049
|
-
emittedFiles.delete(path);
|
|
1050
|
-
rollupFiles.add(path);
|
|
1051
|
-
}
|
|
1052
|
-
} else {
|
|
1053
|
-
rollupDeclarationFiles({
|
|
1043
|
+
const rollup = async (path) => {
|
|
1044
|
+
const result = rollupDeclarationFiles({
|
|
1054
1045
|
root,
|
|
1055
1046
|
configPath,
|
|
1056
1047
|
compilerOptions: compilerOptions2,
|
|
1057
1048
|
outDir,
|
|
1058
|
-
entryPath:
|
|
1059
|
-
fileName: basename(
|
|
1049
|
+
entryPath: path,
|
|
1050
|
+
fileName: basename(path),
|
|
1060
1051
|
libFolder,
|
|
1061
1052
|
rollupConfig,
|
|
1062
1053
|
rollupOptions
|
|
1063
1054
|
});
|
|
1064
|
-
emittedFiles.delete(
|
|
1065
|
-
rollupFiles.add(
|
|
1055
|
+
emittedFiles.delete(path);
|
|
1056
|
+
rollupFiles.add(path);
|
|
1057
|
+
if (typeof afterRollup === "function") {
|
|
1058
|
+
await unwrapPromise(afterRollup(result));
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
if (multiple) {
|
|
1062
|
+
await runParallel(cpus().length, entryNames, async (name) => {
|
|
1063
|
+
await rollup(cleanPath(resolve(outDir, tsToDts(name))));
|
|
1064
|
+
});
|
|
1065
|
+
} else {
|
|
1066
|
+
await rollup(typesPath);
|
|
1066
1067
|
}
|
|
1067
1068
|
await runParallel(cpus().length, Array.from(emittedFiles.keys()), (f) => unlink(f));
|
|
1068
1069
|
removeDirIfEmpty(outDir);
|