MCPcopy Create free account
hub / github.com/cn-docs/vueuse / getTypeDefinition

Function getTypeDefinition

scripts/utils.ts:23–50  ·  view source on GitHub ↗
(pkg: string, name: string)

Source from the content-addressed store, hash-verified

21const DIR_TYPES = resolve(__dirname, '../types/packages')
22
23export async function getTypeDefinition(pkg: string, name: string): Promise<string | undefined> {
24 const typingFilepath = join(DIR_TYPES, `${pkg}/${name}/index.d.ts`)
25
26 if (!existsSync(typingFilepath))
27 return
28
29 let types = await fs.readFile(typingFilepath, 'utf-8')
30
31 if (!types)
32 return
33
34 // clean up types
35 types = types
36 .replace(/import\(.*?\)\./g, '')
37 .replace(/import[\s\S]+?from ?["'][\s\S]+?["']/g, '')
38 .replace(/export \{\}/g, '')
39
40 const prettier = await import('prettier')
41 return (await prettier
42 .format(
43 types,
44 {
45 semi: false,
46 parser: 'typescript',
47 },
48 ))
49 .trim()
50}
51
52export async function updateImport({ packages, functions }: PackageIndexes) {
53 for (const { name, dir, manualImport } of Object.values(packages)) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected