-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathtypes.ts
184 lines (155 loc) · 4.29 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
import type { FilterPattern } from '@rollup/pluginutils'
import type { TransformResult } from 'unplugin'
import type { Awaitable } from '@antfu/utils'
export interface ImportInfoLegacy {
/**
* @deprecated renamed to `as`
*/
name?: string
/**
* @deprecated renamed to `name`
*/
importName?: string
/**
* @deprecated renamed to `from`
*/
path: string
sideEffects?: SideEffectsInfo
}
export interface ImportInfo {
as?: string
name?: string
from: string
}
export type SideEffectsInfo = (ImportInfo | string)[] | ImportInfo | string | undefined
export interface ComponentInfo extends ImportInfo {
sideEffects?: SideEffectsInfo
}
export type ComponentResolveResult = Awaitable<string | ComponentInfo | null | undefined | void>
export type ComponentResolverFunction = (name: string) => ComponentResolveResult
export interface ComponentResolverObject {
type: 'component' | 'directive'
resolve: ComponentResolverFunction
}
export type ComponentResolver = ComponentResolverFunction | ComponentResolverObject
export type Matcher = (id: string) => boolean | null | undefined
export type Transformer = (code: string, id: string, path: string, query: Record<string, string>) => Awaitable<TransformResult | null>
export type SupportedTransformer = 'vue3' | 'vue2'
export interface PublicPluginAPI {
/**
* Resolves a component using the configured resolvers.
*/
findComponent: (name: string, filename?: string) => Promise<ComponentInfo | undefined>
/**
* Obtain an import statement for a resolved component.
*/
stringifyImport: (info: ComponentInfo) => string
}
/**
* Plugin options.
*/
export interface Options {
/**
* RegExp or glob to match files to be transformed
*/
include?: FilterPattern
/**
* RegExp or glob to match files to NOT be transformed
*/
exclude?: FilterPattern
/**
* Relative paths to the directory to search for components.
* @default 'src/components'
*/
dirs?: string | string[]
/**
* Valid file extensions for components.
* @default ['vue']
*/
extensions?: string | string[]
/**
* Glob patterns to match file names to be detected as components.
*
* When specified, the `dirs` and `extensions` options will be ignored.
*/
globs?: string | string[]
/**
* Search for subdirectories
* @default true
*/
deep?: boolean
/**
* Allow subdirectories as namespace prefix for components
* @default false
*/
directoryAsNamespace?: boolean
/**
* Subdirectory paths for ignoring namespace prefixes
* works when `directoryAsNamespace: true`
* @default "[]"
*/
globalNamespaces?: string[]
/**
* Pass a custom function to resolve the component importing path from the component name.
*
* The component names are always in PascalCase
*/
resolvers?: (ComponentResolver | ComponentResolver[])[]
/**
* Apply custom transform over the path for importing
*/
importPathTransform?: (path: string) => string | undefined
/**
* Transformer to apply
*
* @default 'vue3'
*/
transformer?: SupportedTransformer
/**
* Generate TypeScript declaration for global components
*
* Accept boolean or a path related to project root
*
* @see https://github.com/vuejs/vue-next/pull/3399
* @see https://github.com/johnsoncodehk/volar#using
* @default true
*/
dts?: boolean | string
/**
* Do not emit warning on component overriding
*
* @default false
*/
allowOverrides?: boolean
/**
* auto import for directives.
*
* default: `true` for Vue 3, `false` for Vue 2
*
* Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
* To install Babel, run: `npm install -D @babel/parser @babel/traverse`
* @default undefined
*/
directives?: boolean
/**
* Only provide types of components in library (registered globally)
**/
types?: TypeImport[]
}
export type ResolvedOptions = Omit<
Required<Options>,
'resolvers'|'extensions'|'dirs'|'globalComponentsDeclaration'
> & {
resolvers: ComponentResolverObject[]
extensions: string[]
dirs: string[]
resolvedDirs: string[]
globs: string[]
dts: string | false
root: string
}
export type ComponentsImportMap = Record<string, string[] | undefined>
export interface TypeImport {
from: string
names: string[]
}