next-auto-import 0.0.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 +62 -0
- package/dist/index.cjs +352 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +199 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +199 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +324 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
- package/src/core/biomelintrc.ts +13 -0
- package/src/core/ctx.ts +287 -0
- package/src/core/eslintrc.ts +16 -0
- package/src/core/resolvers.ts +94 -0
- package/src/core/unplugin.ts +80 -0
- package/src/index.ts +30 -0
- package/src/presets/index.ts +9 -0
- package/src/presets/react-dom.ts +15 -0
- package/src/presets/react.ts +40 -0
- package/src/types.ts +242 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { Arrayable, Awaitable } from '@antfu/utils'
|
|
2
|
+
import type {
|
|
3
|
+
Import,
|
|
4
|
+
InlinePreset,
|
|
5
|
+
PackagePreset,
|
|
6
|
+
ScanDirExportsOptions,
|
|
7
|
+
UnimportOptions,
|
|
8
|
+
} from 'unimport'
|
|
9
|
+
import type { FilterPattern } from 'unplugin-utils'
|
|
10
|
+
import type { PresetName } from './presets'
|
|
11
|
+
|
|
12
|
+
export interface ImportLegacy {
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated renamed to `as`
|
|
15
|
+
*/
|
|
16
|
+
name?: string
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated renamed to `name`
|
|
19
|
+
*/
|
|
20
|
+
importName?: string
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated renamed to `from`
|
|
23
|
+
*/
|
|
24
|
+
path: string
|
|
25
|
+
|
|
26
|
+
sideEffects?: SideEffectsInfo
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ImportExtended extends Import {
|
|
30
|
+
sideEffects?: SideEffectsInfo
|
|
31
|
+
__source?: 'dir' | 'resolver'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ImportNameAlias = [string, string]
|
|
35
|
+
export type SideEffectsInfo = Arrayable<ResolverResult | string> | undefined
|
|
36
|
+
|
|
37
|
+
export interface ResolverResult {
|
|
38
|
+
as?: string
|
|
39
|
+
name?: string
|
|
40
|
+
from: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ResolverFunction = (
|
|
44
|
+
name: string,
|
|
45
|
+
) => Awaitable<
|
|
46
|
+
string | ResolverResult | ImportExtended | null | undefined | void
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
export interface ResolverResultObject {
|
|
50
|
+
type: 'component' | 'directive'
|
|
51
|
+
resolve: ResolverFunction
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Given a identifier name, returns the import path or an import object
|
|
56
|
+
*/
|
|
57
|
+
export type Resolver = ResolverFunction | ResolverResultObject
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* module, name, alias
|
|
61
|
+
*/
|
|
62
|
+
export type ImportsMap = Record<string, (string | ImportNameAlias)[]>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Directory to search for import
|
|
66
|
+
*/
|
|
67
|
+
export interface ScanDir {
|
|
68
|
+
glob: string
|
|
69
|
+
types?: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type NormalizedScanDir = Required<ScanDir>
|
|
73
|
+
|
|
74
|
+
export type ESLintGlobalsPropValue =
|
|
75
|
+
| boolean
|
|
76
|
+
| 'readonly'
|
|
77
|
+
| 'readable'
|
|
78
|
+
| 'writable'
|
|
79
|
+
| 'writeable'
|
|
80
|
+
|
|
81
|
+
export interface ESLintrc {
|
|
82
|
+
/**
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
enabled?: boolean
|
|
86
|
+
/**
|
|
87
|
+
* Filepath to save the generated eslint config
|
|
88
|
+
*
|
|
89
|
+
* @default './.eslintrc-auto-import.json'
|
|
90
|
+
*/
|
|
91
|
+
filepath?: string
|
|
92
|
+
/**
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
globalsPropValue?: ESLintGlobalsPropValue
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface BiomeLintrc {
|
|
99
|
+
/**
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
enabled?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* Filepath to save the generated eslint config
|
|
105
|
+
*
|
|
106
|
+
* @default './.eslintrc-auto-import.json'
|
|
107
|
+
*/
|
|
108
|
+
filepath?: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface Options {
|
|
112
|
+
/**
|
|
113
|
+
* Preset names or custom imports map
|
|
114
|
+
*
|
|
115
|
+
* @default []
|
|
116
|
+
*/
|
|
117
|
+
imports?: Arrayable<ImportsMap | PresetName | InlinePreset>
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Local package presets.
|
|
121
|
+
*
|
|
122
|
+
* Register local installed packages as a preset.
|
|
123
|
+
*
|
|
124
|
+
* @default []
|
|
125
|
+
* @see https://github.com/unplugin/unplugin-auto-import#package-presets
|
|
126
|
+
*/
|
|
127
|
+
packagePresets?: (PackagePreset | string)[]
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Identifiers to be ignored
|
|
131
|
+
*/
|
|
132
|
+
ignore?: (string | RegExp)[]
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* These identifiers won't be put on the DTS file
|
|
136
|
+
*/
|
|
137
|
+
ignoreDts?: (string | RegExp)[]
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Inject the imports at the end of other imports
|
|
141
|
+
*
|
|
142
|
+
* @default true
|
|
143
|
+
*/
|
|
144
|
+
injectAtEnd?: boolean
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Options for scanning directories for auto import
|
|
148
|
+
*/
|
|
149
|
+
dirsScanOptions?: Omit<ScanDirExportsOptions, 'cwd'>
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Path for directories to be auto imported
|
|
153
|
+
*/
|
|
154
|
+
dirs?: (string | ScanDir)[]
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Pass a custom function to resolve the component importing path from the component name.
|
|
158
|
+
*
|
|
159
|
+
* The component names are always in PascalCase
|
|
160
|
+
*/
|
|
161
|
+
resolvers?: Arrayable<Arrayable<Resolver>>
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Parser to be used for parsing the source code.
|
|
165
|
+
*
|
|
166
|
+
* @see https://github.com/unjs/unimport#acorn-parser
|
|
167
|
+
* @default 'regex'
|
|
168
|
+
*/
|
|
169
|
+
parser?: UnimportOptions['parser']
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Specifies the file path for generating the corresponding .d.ts file.
|
|
173
|
+
* This option is enabled by default when `typescript` is installed locally.
|
|
174
|
+
* Set to `false` to disable this feature.
|
|
175
|
+
*/
|
|
176
|
+
dts?: string | boolean
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Mode for generating the .d.ts file.
|
|
180
|
+
* - `overwrite`: overwrite the whole existing .d.ts file with the new type definitions.
|
|
181
|
+
* - `append`: only append the new type definitions to the existing .d.ts file, means the existing type definitions will be kept.
|
|
182
|
+
* @default 'append'
|
|
183
|
+
*/
|
|
184
|
+
dtsMode?: 'overwrite' | 'append'
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Preserve the original file extensions in the generated .d.ts file.
|
|
188
|
+
* Set to `true` to keep the extensions for .ts and .tsx files.
|
|
189
|
+
* @default false
|
|
190
|
+
*/
|
|
191
|
+
dtsPreserveExts?: boolean
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Set default export alias by file name
|
|
195
|
+
*
|
|
196
|
+
* @default false
|
|
197
|
+
*/
|
|
198
|
+
defaultExportByFilename?: boolean
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Rules to include transforming target.
|
|
202
|
+
*
|
|
203
|
+
* @default [/\.[jt]sx?$/, /\.astro$/, /\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.svelte$/]
|
|
204
|
+
*/
|
|
205
|
+
include?: FilterPattern
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Rules to exclude transforming target.
|
|
209
|
+
*
|
|
210
|
+
* @default [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/]
|
|
211
|
+
*/
|
|
212
|
+
exclude?: FilterPattern
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Generate corresponding .eslintrc-auto-import.json file.
|
|
216
|
+
*/
|
|
217
|
+
eslintrc?: ESLintrc
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Generate corresponding .biomelintrc.json file.
|
|
221
|
+
*/
|
|
222
|
+
biomelintrc?: BiomeLintrc
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Save unimport items into a JSON file for other tools to consume.
|
|
226
|
+
* Provide a filepath to save the JSON file.
|
|
227
|
+
*
|
|
228
|
+
* When set to `true`, it will save to `./.unimport-items.json`
|
|
229
|
+
*
|
|
230
|
+
* @default false
|
|
231
|
+
*/
|
|
232
|
+
dumpUnimportItems?: boolean | string
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Include auto-imported packages in Vite's `optimizeDeps` option
|
|
236
|
+
*
|
|
237
|
+
* @default true
|
|
238
|
+
*/
|
|
239
|
+
viteOptimizeDeps?: boolean
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { PresetName }
|