-
-
Notifications
You must be signed in to change notification settings - Fork 200
/
types.ts
244 lines (209 loc) · 5.3 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
import type { Arrayable, Awaitable } from '@antfu/utils'
import type { FilterPattern } from '@rollup/pluginutils'
import type { AddonVueDirectivesOptions, Import, InlinePreset, PackagePreset, UnimportOptions } from 'unimport'
import { PresetName } from './presets'
export interface ImportLegacy {
/**
* @deprecated renamed to `as`
*/
name?: string
/**
* @deprecated renamed to `name`
*/
importName?: string
/**
* @deprecated renamed to `from`
*/
path: string
sideEffects?: SideEffectsInfo
}
export interface ImportExtended extends Import {
sideEffects?: SideEffectsInfo
__source?: 'dir' | 'resolver'
}
export type ImportNameAlias = [string, string]
export type SideEffectsInfo = Arrayable<ResolverResult | string> | undefined
export interface ResolverResult {
as?: string
name?: string
from: string
}
export type ResolverFunction = (name: string) => Awaitable<string | ResolverResult | ImportExtended | null | undefined | void>
export interface ResolverResultObject {
type: 'component' | 'directive'
resolve: ResolverFunction
}
/**
* Given a identifier name, returns the import path or an import object
*/
export type Resolver = ResolverFunction | ResolverResultObject
/**
* module, name, alias
*/
export type ImportsMap = Record<string, (string | ImportNameAlias)[]>
export interface ScanDirExportsOptions {
/**
* Register type exports
*
* @default true
*/
types?: boolean
}
/**
* Directory to search for import
*/
export interface ScanDir {
glob: string
types?: boolean
}
export type NormalizedScanDir = Required<ScanDir>
export type ESLintGlobalsPropValue = boolean | 'readonly' | 'readable' | 'writable' | 'writeable'
export interface ESLintrc {
/**
* @default false
*/
enabled?: boolean
/**
* Filepath to save the generated eslint config
*
* @default './.eslintrc-auto-import.json'
*/
filepath?: string
/**
* @default true
*/
globalsPropValue?: ESLintGlobalsPropValue
}
export interface BiomeLintrc {
/**
* @default false
*/
enabled?: boolean
/**
* Filepath to save the generated eslint config
*
* @default './.eslintrc-auto-import.json'
*/
filepath?: string
}
export interface Options {
/**
* Preset names or custom imports map
*
* @default []
*/
imports?: Arrayable<ImportsMap | PresetName | InlinePreset>
/**
* Local package presets.
*
* Register local installed packages as a preset.
*
* @default []
* @see https://github.com/unplugin/unplugin-auto-import#package-presets
*/
packagePresets?: (PackagePreset | string)[]
/**
* Identifiers to be ignored
*/
ignore?: (string | RegExp)[]
/**
* These identifiers won't be put on the DTS file
*/
ignoreDts?: (string | RegExp)[]
/**
* Inject the imports at the end of other imports
*
* @default true
*/
injectAtEnd?: boolean
/**
* Options for scanning directories for auto import
*/
dirsScanOptions?: ScanDirExportsOptions
/**
* Path for directories to be auto imported
*/
dirs?: (string | ScanDir)[]
/**
* Pass a custom function to resolve the component importing path from the component name.
*
* The component names are always in PascalCase
*/
resolvers?: Arrayable<Arrayable<Resolver>>
/**
* Parser to be used for parsing the source code.
*
* @see https://github.com/unjs/unimport#acorn-parser
* @default 'regex'
*/
parser?: UnimportOptions['parser']
/**
* Filepath to generate corresponding .d.ts file.
* Default enabled when `typescript` is installed locally.
* Set `false` to disable.
*
* @default './auto-imports.d.ts'
*/
dts?: string | boolean
/**
* Auto import inside Vue templates
*
* @see https://github.com/unjs/unimport/pull/15
* @see https://github.com/unjs/unimport/pull/72
* @default false
*/
vueTemplate?: boolean
/**
* Enable auto import directives for Vue's SFC.
*
* Library authors should include `meta.vueDirective: true` in the import metadata.
*
* When using a local directives folder, provide the `isDirective`
* callback to check if the import is a Vue directive.
*
* @see https://github.com/unjs/unimport?tab=readme-ov-file#vue-directives-auto-import-and-typescript-declaration-generation
*/
vueDirectives?: true | AddonVueDirectivesOptions
/**
* Set default export alias by file name
*
* @default false
*/
defaultExportByFilename?: boolean
/**
* Rules to include transforming target.
*
* @default [/\.[jt]sx?$/, /\.astro$/, /\.vue$/, /\.vue\?vue/, /\.svelte$/]
*/
include?: FilterPattern
/**
* Rules to exclude transforming target.
*
* @default [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/]
*/
exclude?: FilterPattern
/**
* Generate corresponding .eslintrc-auto-import.json file.
*/
eslintrc?: ESLintrc
/**
* Generate corresponding .biomelintrc.json file.
*/
biomelintrc?: BiomeLintrc
/**
* Save unimport items into a JSON file for other tools to consume.
* Provide a filepath to save the JSON file.
*
* When set to `true`, it will save to `./.unimport-items.json`
*
* @default false
*/
dumpUnimportItems?: boolean | string
/**
* Include auto-imported packages in Vite's `optimizeDeps` option
*
* @default true
*/
viteOptimizeDeps?: boolean
}
export { PresetName }