-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathvite.plugin.dts.ts
48 lines (43 loc) · 1.74 KB
/
vite.plugin.dts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Extractor, ExtractorConfig, ExtractorResult } from '@microsoft/api-extractor';
import path from 'path';
import url from 'url';
export default function generateDts(root: string, entryFile: string, outputFilename: string) {
const relativePath = path.relative(root, entryFile);
const dtsRoot = path.resolve(root, 'dist', 'types');
const dtsPath = path.resolve(dtsRoot, relativePath).replace('.ts', '.d.ts');
const outputFile: string = path.join(root, 'dist', outputFilename);
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
packageJsonFullPath: path.resolve(root, 'package.json'),
configObjectFullPath: undefined,
configObject: {
projectFolder: root,
mainEntryPointFilePath: dtsPath,
compiler: {
overrideTsconfig: {
compilerOptions: {
paths: {
'@src/*': [dtsRoot]
}
}
}
},
dtsRollup: {
enabled: true,
publicTrimmedFilePath: outputFile
}
}
});
const typescriptPath = path.resolve(url.fileURLToPath(import.meta.resolve('typescript')), '..', '..');
const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
localBuild: process.env.GITHUB_ACTIONS !== 'true',
typescriptCompilerFolder: typescriptPath
});
if (extractorResult.succeeded) {
console.log(`DTS bundled`, entryFile, outputFile);
} else {
throw new Error(
`API Extractor completed with ${extractorResult.errorCount} errors` +
` and ${extractorResult.warningCount} warnings`
);
}
}