-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathvueuse.ts
40 lines (37 loc) · 1.3 KB
/
vueuse.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
import type { ComponentResolver } from '../../types'
import { readFileSync } from 'node:fs'
import process from 'node:process'
import { resolveModule } from 'local-pkg'
let components: string[] | undefined
/**
* Resolver for VueUse
*
* @link https://github.com/vueuse/vueuse
*/
export function VueUseComponentsResolver(): ComponentResolver {
return {
type: 'component',
resolve: (name: string) => {
if (!components) {
let indexesJson: any
try {
const corePath = resolveModule('@vueuse/core') || process.cwd()
const path = resolveModule('@vueuse/core/indexes.json')
|| resolveModule('@vueuse/metadata/index.json')
|| resolveModule('@vueuse/metadata/index.json', { paths: [corePath] })
indexesJson = JSON.parse(readFileSync(path!, 'utf-8'))
components = indexesJson
.functions
.filter((i: any) => i.component && i.name)
.map(({ name }: any) => name[0].toUpperCase() + name.slice(1))
}
catch (error) {
console.error(error)
throw new Error('[vue-components] failed to load @vueuse/core, have you installed it?')
}
}
if (components && components.includes(name))
return { name, as: name, from: '@vueuse/components' }
},
}
}