-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readFileSync } from 'fs' | ||
import { resolveModule } from 'local-pkg' | ||
import type { PackageIndexes } from '@vueuse/metadata' | ||
import type { ImportsMap } from '../types' | ||
|
||
let _cache: ImportsMap | undefined | ||
|
||
export default (): ImportsMap => { | ||
if (!_cache) { | ||
let indexesJson: PackageIndexes | undefined | ||
try { | ||
const corePath = resolveModule('@vueuse/core') || process.cwd() | ||
const path = resolveModule('@vueuse/metadata/index.json') | ||
|| resolveModule('@vueuse/metadata/index.json', { paths: [corePath] }) | ||
indexesJson = JSON.parse(readFileSync(path!, 'utf-8')) | ||
} | ||
catch (error) { | ||
console.error(error) | ||
throw new Error('[auto-import] failed to load @vueuse/math, have you installed it?') | ||
} | ||
if (indexesJson) { | ||
_cache = { | ||
'@vueuse/math': indexesJson | ||
.functions | ||
.filter(i => ['math'].includes(i.package)) | ||
.flatMap(i => [i.name, ...i.alias || []]) | ||
// only include functions with 4 characters or more | ||
.filter((i: string) => i && i.length >= 4), | ||
} | ||
} | ||
} | ||
|
||
return _cache || {} | ||
} |