vite-plugin-dts 3.8.3 → 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/README.md +7 -0
- package/README.zh-CN.md +9 -2
- package/dist/index.cjs +18 -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 +18 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -355,6 +355,13 @@ export interface PluginOptions {
|
|
|
355
355
|
}
|
|
356
356
|
>,
|
|
357
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Hook called after rolling up declaration files
|
|
360
|
+
*
|
|
361
|
+
* @default () => {}
|
|
362
|
+
*/
|
|
363
|
+
afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
|
|
364
|
+
|
|
358
365
|
/**
|
|
359
366
|
* Hook called after all declaration files are written
|
|
360
367
|
*
|
package/README.zh-CN.md
CHANGED
|
@@ -269,7 +269,7 @@ export interface PluginOptions {
|
|
|
269
269
|
insertTypesEntry?: boolean,
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
|
-
*
|
|
272
|
+
* 设置是否将发出的类型文件打包进单个文件
|
|
273
273
|
*
|
|
274
274
|
* 基于 `@microsoft/api-extractor`,过程将会消耗一些时间
|
|
275
275
|
*
|
|
@@ -356,7 +356,14 @@ export interface PluginOptions {
|
|
|
356
356
|
>,
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
*
|
|
359
|
+
* 类型文件被打包进单个文件后的钩子
|
|
360
|
+
*
|
|
361
|
+
* @default () => {}
|
|
362
|
+
*/
|
|
363
|
+
afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* 在所有类型文件被写入后的钩子
|
|
360
367
|
*
|
|
361
368
|
* 它会接收一个记录了那些最终被写入的文件的映射(path -> content)
|
|
362
369
|
*
|
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$/;
|
|
@@ -624,6 +623,7 @@ function dtsPlugin(options = {}) {
|
|
|
624
623
|
strictOutput = true,
|
|
625
624
|
afterDiagnostic = noop,
|
|
626
625
|
beforeWriteFile = noop,
|
|
626
|
+
afterRollup = noop,
|
|
627
627
|
afterBuild = noop
|
|
628
628
|
} = options;
|
|
629
629
|
let root = ensureAbsolute(options.root ?? "", process.cwd());
|
|
@@ -1043,37 +1043,30 @@ export default ${libName}
|
|
|
1043
1043
|
}
|
|
1044
1044
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
1045
1045
|
const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
const path = cleanPath(resolve(outDir, tsToDts(name)));
|
|
1049
|
-
rollupDeclarationFiles({
|
|
1050
|
-
root,
|
|
1051
|
-
configPath,
|
|
1052
|
-
compilerOptions: compilerOptions2,
|
|
1053
|
-
outDir,
|
|
1054
|
-
entryPath: path,
|
|
1055
|
-
fileName: node_path.basename(path),
|
|
1056
|
-
libFolder,
|
|
1057
|
-
rollupConfig,
|
|
1058
|
-
rollupOptions
|
|
1059
|
-
});
|
|
1060
|
-
emittedFiles.delete(path);
|
|
1061
|
-
rollupFiles.add(path);
|
|
1062
|
-
}
|
|
1063
|
-
} else {
|
|
1064
|
-
rollupDeclarationFiles({
|
|
1046
|
+
const rollup = async (path) => {
|
|
1047
|
+
const result = rollupDeclarationFiles({
|
|
1065
1048
|
root,
|
|
1066
1049
|
configPath,
|
|
1067
1050
|
compilerOptions: compilerOptions2,
|
|
1068
1051
|
outDir,
|
|
1069
|
-
entryPath:
|
|
1070
|
-
fileName: node_path.basename(
|
|
1052
|
+
entryPath: path,
|
|
1053
|
+
fileName: node_path.basename(path),
|
|
1071
1054
|
libFolder,
|
|
1072
1055
|
rollupConfig,
|
|
1073
1056
|
rollupOptions
|
|
1074
1057
|
});
|
|
1075
|
-
emittedFiles.delete(
|
|
1076
|
-
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);
|
|
1077
1070
|
}
|
|
1078
1071
|
await runParallel(node_os.cpus().length, Array.from(emittedFiles.keys()), (f) => promises.unlink(f));
|
|
1079
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$/;
|
|
@@ -621,6 +620,7 @@ function dtsPlugin(options = {}) {
|
|
|
621
620
|
strictOutput = true,
|
|
622
621
|
afterDiagnostic = noop,
|
|
623
622
|
beforeWriteFile = noop,
|
|
623
|
+
afterRollup = noop,
|
|
624
624
|
afterBuild = noop
|
|
625
625
|
} = options;
|
|
626
626
|
let root = ensureAbsolute(options.root ?? "", process.cwd());
|
|
@@ -1040,37 +1040,30 @@ export default ${libName}
|
|
|
1040
1040
|
}
|
|
1041
1041
|
const rollupFiles = /* @__PURE__ */ new Set();
|
|
1042
1042
|
const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
const path = cleanPath(resolve(outDir, tsToDts(name)));
|
|
1046
|
-
rollupDeclarationFiles({
|
|
1047
|
-
root,
|
|
1048
|
-
configPath,
|
|
1049
|
-
compilerOptions: compilerOptions2,
|
|
1050
|
-
outDir,
|
|
1051
|
-
entryPath: path,
|
|
1052
|
-
fileName: basename(path),
|
|
1053
|
-
libFolder,
|
|
1054
|
-
rollupConfig,
|
|
1055
|
-
rollupOptions
|
|
1056
|
-
});
|
|
1057
|
-
emittedFiles.delete(path);
|
|
1058
|
-
rollupFiles.add(path);
|
|
1059
|
-
}
|
|
1060
|
-
} else {
|
|
1061
|
-
rollupDeclarationFiles({
|
|
1043
|
+
const rollup = async (path) => {
|
|
1044
|
+
const result = rollupDeclarationFiles({
|
|
1062
1045
|
root,
|
|
1063
1046
|
configPath,
|
|
1064
1047
|
compilerOptions: compilerOptions2,
|
|
1065
1048
|
outDir,
|
|
1066
|
-
entryPath:
|
|
1067
|
-
fileName: basename(
|
|
1049
|
+
entryPath: path,
|
|
1050
|
+
fileName: basename(path),
|
|
1068
1051
|
libFolder,
|
|
1069
1052
|
rollupConfig,
|
|
1070
1053
|
rollupOptions
|
|
1071
1054
|
});
|
|
1072
|
-
emittedFiles.delete(
|
|
1073
|
-
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);
|
|
1074
1067
|
}
|
|
1075
1068
|
await runParallel(cpus().length, Array.from(emittedFiles.keys()), (f) => unlink(f));
|
|
1076
1069
|
removeDirIfEmpty(outDir);
|