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