chore: improve building registry
This commit is contained in:
parent
19293c300d
commit
cba25e7390
|
|
@ -54,6 +54,7 @@
|
|||
"@vue/tsconfig": "^0.5.1",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"lodash.template": "^4.5.0",
|
||||
"oxc-parser": "^0.2.0",
|
||||
"pathe": "^1.1.2",
|
||||
"rimraf": "^5.0.5",
|
||||
"tailwind-merge": "^2.0.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { readFile, readdir } from 'node:fs/promises'
|
||||
import { join, normalize, resolve } from 'pathe'
|
||||
import { compileScript, parse } from 'vue/compiler-sfc'
|
||||
import oxc from 'oxc-parser'
|
||||
|
||||
import type { Registry } from '../../lib/registry'
|
||||
|
||||
|
|
@ -134,31 +135,47 @@ async function buildUIRegistry(componentPath: string, componentName: string) {
|
|||
|
||||
async function getDependencies(filename: string) {
|
||||
const code = await readFile(filename, { encoding: 'utf8' })
|
||||
const parsed = parse(code, { filename })
|
||||
|
||||
const registryDependencies = new Set<string>()
|
||||
const dependencies = new Set<string>()
|
||||
|
||||
if (parsed.descriptor.script?.content || parsed.descriptor.scriptSetup?.content) {
|
||||
const compiled = compileScript(parsed.descriptor, { id: '' })
|
||||
const populateDeps = (source: string) => {
|
||||
const peerDeps = DEPENDENCIES.get(source)
|
||||
const taggedDeps = DEPENDENCIES_WITH_TAGS.get(source)
|
||||
if (peerDeps !== undefined) {
|
||||
if (taggedDeps !== undefined)
|
||||
dependencies.add(taggedDeps)
|
||||
else
|
||||
dependencies.add(source)
|
||||
peerDeps.forEach(dep => dependencies.add(dep))
|
||||
}
|
||||
|
||||
Object.values(compiled.imports!).forEach((value) => {
|
||||
const source = value.source
|
||||
const peerDeps = DEPENDENCIES.get(source)
|
||||
const taggedDeps = DEPENDENCIES_WITH_TAGS.get(source)
|
||||
if (peerDeps !== undefined) {
|
||||
if (taggedDeps !== undefined)
|
||||
dependencies.add(taggedDeps)
|
||||
else
|
||||
dependencies.add(source)
|
||||
peerDeps.forEach(dep => dependencies.add(dep))
|
||||
}
|
||||
if (source.startsWith(REGISTRY_DEPENDENCY)) {
|
||||
const component = source.split('/').at(-1)!
|
||||
registryDependencies.add(component)
|
||||
}
|
||||
}
|
||||
|
||||
if (source.startsWith(REGISTRY_DEPENDENCY)) {
|
||||
const component = source.split('/').at(-1)!
|
||||
registryDependencies.add(component)
|
||||
}
|
||||
if (filename.endsWith('.ts')) {
|
||||
const ast = oxc.parseSync(code, {
|
||||
sourceType: 'module',
|
||||
sourceFilename: filename,
|
||||
})
|
||||
|
||||
const sources = JSON.parse(ast.program).body.filter((i: any) => i.type === 'ImportDeclaration').map((i: any) => i.source)
|
||||
sources.forEach((source: any) => {
|
||||
populateDeps(source.value)
|
||||
})
|
||||
}
|
||||
else {
|
||||
const parsed = parse(code, { filename })
|
||||
if (parsed.descriptor.script?.content || parsed.descriptor.scriptSetup?.content) {
|
||||
const compiled = compileScript(parsed.descriptor, { id: '' })
|
||||
|
||||
Object.values(compiled.imports!).forEach((value) => {
|
||||
populateDeps(value.source)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { registryDependencies, dependencies }
|
||||
|
|
|
|||
|
|
@ -156,6 +156,9 @@ importers:
|
|||
lodash.template:
|
||||
specifier: ^4.5.0
|
||||
version: 4.5.0
|
||||
oxc-parser:
|
||||
specifier: ^0.2.0
|
||||
version: 0.2.0
|
||||
pathe:
|
||||
specifier: ^1.1.2
|
||||
version: 1.1.2
|
||||
|
|
@ -3123,7 +3126,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@oxc-parser/binding-darwin-x64@0.2.0:
|
||||
|
|
@ -3131,7 +3133,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [darwin]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@oxc-parser/binding-linux-arm64-gnu@0.2.0:
|
||||
|
|
@ -3139,7 +3140,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@oxc-parser/binding-linux-x64-gnu@0.2.0:
|
||||
|
|
@ -3147,7 +3147,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@oxc-parser/binding-win32-arm64-msvc@0.2.0:
|
||||
|
|
@ -3155,7 +3154,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [win32]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@oxc-parser/binding-win32-x64-msvc@0.2.0:
|
||||
|
|
@ -3163,7 +3161,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [win32]
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/@parcel/watcher-android-arm64@2.3.0:
|
||||
|
|
@ -11115,7 +11112,6 @@ packages:
|
|||
'@oxc-parser/binding-linux-x64-gnu': 0.2.0
|
||||
'@oxc-parser/binding-win32-arm64-msvc': 0.2.0
|
||||
'@oxc-parser/binding-win32-x64-msvc': 0.2.0
|
||||
dev: false
|
||||
|
||||
/p-finally@1.0.0:
|
||||
resolution: {integrity: sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user