Skip to content

Commit 0ad5da2

Browse files
authored
fix(registry): normalize registryDependencies to component slugs (#59)
1 parent 215f7e5 commit 0ad5da2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

apps/registry/server/utils/registry-builder.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ function parseImportsFromCode(code: string): string[] {
8383
}
8484
}
8585

86+
function extractRegistrySlug(modulePath: string, basePath: string): string {
87+
if (!modulePath.startsWith(basePath))
88+
return ''
89+
90+
const rest = modulePath.slice(basePath.length)
91+
.split('/')
92+
.filter(Boolean)
93+
94+
return rest[0] || ''
95+
}
96+
8697
function analyzeDependencies(
8798
imports: string[],
8899
allowedDeps: Set<string>,
@@ -110,18 +121,16 @@ function analyzeDependencies(
110121

111122
// Handle shadcn-vue components
112123
if (mod.startsWith('@/components/ui/')) {
113-
const componentName = mod.split('/').pop() || ''
114-
if (componentName) {
115-
registryDependencies.add(componentName)
116-
}
124+
const slug = extractRegistrySlug(mod, '@/components/ui/')
125+
if (slug)
126+
registryDependencies.add(slug)
117127
}
118128

119129
// Handle AI elements components
120130
if (mod.startsWith('@/components/ai-elements/')) {
121-
const componentName = mod.split('/').pop() || ''
122-
if (componentName) {
123-
registryDependencies.add(`/${componentName}.json`)
124-
}
131+
const slug = extractRegistrySlug(mod, '@/components/ai-elements/')
132+
if (slug)
133+
registryDependencies.add(slug)
125134
}
126135
}
127136

0 commit comments

Comments
 (0)