Skip to content

Commit 375e843

Browse files
authored
fix(cli): preserve intermediate directories when resolving nested file paths (#1607)
Fixes component installation paths for custom registries with additional path levels. Previously, only the last segment of the common root was preserved, causing intermediate directories to be lost. Example: - Before: components/ai-elements/artifact/Artifact.vue → artifact/Artifact.vue - After: components/ai-elements/artifact/Artifact.vue → ai-elements/artifact/Artifact.vue The function now uses the component alias from config to correctly resolve paths for any custom registry structure, not just the default "components" directory.
1 parent 52a687f commit 375e843

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/cli/src/utils/updaters/update-files.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export function resolveFilePath(
357357

358358
const targetDir = resolveFileTargetDirectory(file, config)
359359

360-
const relativePath = resolveNestedFilePath(file.path, options.commonRoot)
360+
const relativePath = resolveNestedFilePath(file.path, options.commonRoot, config)
361361
return path.join(targetDir!, relativePath)
362362
}
363363

@@ -419,11 +419,28 @@ export function findCommonRoot(paths: string[], needle: string): string {
419419
export function resolveNestedFilePath(
420420
filePath: string,
421421
commonRoot: string,
422+
config: Config,
422423
): string {
423424
// Normalize paths by removing leading/trailing slashes
424425
const normalizedFilePath = filePath.replace(/^\/|\/$/g, '')
425426
const normalizedCommonRoot = commonRoot.replace(/^\/|\/$/g, '')
426427

428+
// Get component alias without @ prefix and normalize
429+
const componentAlias = config.aliases.components.replace(/^@\//, '').replace(/^\/|\/$/g, '')
430+
431+
// Check if the common root contains the component alias
432+
if (normalizedCommonRoot.includes(componentAlias)) {
433+
// Find where the component alias ends in the file path
434+
const aliasEndIndex = normalizedFilePath.indexOf(componentAlias) + componentAlias.length
435+
436+
// Return everything after the alias (skip the leading slash if present)
437+
// Example: "components/ai-elements/artifact/Artifact.vue" -> "ai-elements/artifact/Artifact.vue"
438+
// Example: "src/ui/design-system/button/Button.vue" -> "design-system/button/Button.vue"
439+
return normalizedFilePath.substring(aliasEndIndex).replace(/^\//, '')
440+
}
441+
442+
// Fallback to original logic for non-component paths
443+
// Example: "registry/new-york-v4/ui/button/Button.vue" -> "button/Button.vue"
427444
const lastCommonRootSegment = normalizedCommonRoot.split('/').pop()
428445

429446
// normalizedFilePath: registry/new-york-v4/ui/button/Button.vue

0 commit comments

Comments
 (0)