-
Notifications
You must be signed in to change notification settings - Fork 75
/
types.ts
247 lines (220 loc) · 5.59 KB
/
types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import type ts from 'typescript'
import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
import type { LogLevel } from 'vite'
type MaybePromise<T> = T | Promise<T>
export type RollupConfig = Omit<
IExtractorConfigPrepareOptions['configObject'],
'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'
>
export interface Resolver {
/**
* The name of the resolver
*
* The later resolver with the same name will overwrite the earlier
*/
name: string,
/**
* Determine whether the resolver supports the file
*/
supports: (id: string) => void | boolean,
/**
* Transform source to declaration files
*
* Note that the path of the returns should base on `outDir`, or relative path to `root`
*/
transform: (payload: {
id: string,
code: string,
root: string,
outDir: string,
host: ts.CompilerHost,
program: ts.Program,
service: ts.LanguageService
}) => MaybePromise<{ path: string, content: string }[]>
}
export interface PluginOptions {
/**
* Specify root directory
*
* Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
*/
root?: string,
/**
* Output directory for declaration files
*
* Can be an array to output to multiple directories
*
* Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
*/
outDir?: string | string[],
/**
* Override root path of entry files (useful in monorepos)
*
* The output path of each file will be calculated based on the value provided
*
* The default is the smallest public path for all source files
*/
entryRoot?: string,
/**
* Restrict declaration files output to `outDir`
*
* If true, generated declaration files outside `outDir` will be ignored
*
* @default true
*/
strictOutput?: boolean,
/**
* Override compilerOptions
*
* @default null
*/
compilerOptions?: ts.CompilerOptions | null,
/**
* Specify tsconfig.json path
*
* Plugin resolves `include` and `exclude` globs from tsconfig.json
*
* If not specified, plugin will find config file from root
*/
tsconfigPath?: string,
/**
* Specify custom resolvers
*
* @default []
*/
resolvers?: Resolver[],
/**
* Parsing `paths` of tsconfig.json to aliases
*
* Note that these aliases only use for declaration files
*
* @default true
* @remarks Only use first replacement of each path
*/
pathsToAliases?: boolean,
/**
* Set which paths should be excluded when transforming aliases
*
* @default []
*/
aliasesExclude?: (string | RegExp)[],
/**
* Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
*
* @default false
*/
cleanVueFileName?: boolean,
/**
* Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
*
* Value is forced to `true` when `rollupTypes` is `true`
*
* @default false
*/
staticImport?: boolean,
/**
* Override `include` glob (relative to root)
*
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
*/
include?: string | string[],
/**
* Override `exclude` glob
*
* Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
*/
exclude?: string | string[],
/**
* Whether to remove `import 'xxx'`
*
* @default true
*/
clearPureImport?: boolean,
/**
* Whether to generate types entry file(s)
*
* When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
*
* Value is forced to `true` when `rollupTypes` is `true`
*
* @default false
*/
insertTypesEntry?: boolean,
/**
* Rollup type declaration files after emitting them
*
* Powered by `@microsoft/api-extractor` - time-intensive operation
*
* @default false
*/
rollupTypes?: boolean,
/**
* Bundled packages for `@microsoft/api-extractor`
*
* @default []
* @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
*/
bundledPackages?: string[],
/**
* Override the config of `@microsoft/api-extractor`
*
* @default null
* @see https://api-extractor.com/pages/setup/configure_api_report/
*/
rollupConfig?: RollupConfig,
/**
* Whether to copy .d.ts source files to `outDir`
*
* @default false
* @remarks Before 2.0, the default was `true`
*/
copyDtsFiles?: boolean,
/**
* Whether to emit declaration files only
*
* When `true`, all the original outputs of vite (rollup) will be force removed
*
* @default false
*/
declarationOnly?: boolean,
/**
* Logging level for this plugin
*
* Defaults to the 'logLevel' property of your Vite config
*/
logLevel?: LogLevel,
/**
* Hook called after diagnostic is emitted
*
* According to the `diagnostics.length`, you can judge whether there is any type error
*
* @default () => {}
*/
afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
/**
* Hook called prior to writing each declaration file
*
* This allows you to transform the path or content
*
* The file will be skipped when the return value `false` or `Promise<false>`
*
* @default () => {}
*/
beforeWriteFile?: (
filePath: string,
content: string
) => MaybePromise<
| void
| false
| {
filePath?: string,
content?: string
}
>,
/**
* Hook called after all declaration files are written
*
* @default () => {}
*/
afterBuild?: () => MaybePromise<void>
}