Skip to content

Commit d65a7a0

Browse files
authored
fix: compactible with VueUse v8 (#382)
* Update to handle Vueuse 8 the latest version of vueuse changes the location of the index file, this change aims to adapt the resolver to the latest version of vueuse. * fix backward compatibility issue
1 parent 84d4fe0 commit d65a7a0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/core/resolvers/vueuse.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { ComponentResolver } from '../../types'
2+
import { readFileSync } from 'fs'
3+
import { resolveModule } from 'local-pkg'
24

35
let components: string[] | undefined
46

@@ -13,15 +15,19 @@ export function VueUseComponentsResolver(): ComponentResolver {
1315
resolve: (name: string) => {
1416
if (!components) {
1517
try {
16-
/* eslint-disable @typescript-eslint/no-var-requires */
17-
const indexesJson = require('@vueuse/core/indexes.json')
18+
const corePath = resolveModule('@vueuse/core') || process.cwd()
19+
const path = resolveModule('@vueuse/core/indexes.json')
20+
|| resolveModule('@vueuse/metadata/index.json')
21+
|| resolveModule('@vueuse/metadata/index.json', { paths: [corePath] })
22+
indexesJson = JSON.parse(readFileSync(path!, 'utf-8'))
1823
components = indexesJson
1924
.functions
2025
.filter((i: any) => i.component && i.name)
2126
.map(({ name }: any) => name[0].toUpperCase() + name.slice(1))
2227
}
2328
catch (error) {
24-
components = []
29+
console.error(error)
30+
throw new Error('[vue-components] failed to load @vueuse/core, have you installed it?')
2531
}
2632
}
2733

0 commit comments

Comments
 (0)