Skip to content

Commit 8260b9e

Browse files
authored
fix(cli): resolve nested paths for all aliases, not just components (#1615)
Fixes nested file path resolution to work with all configured aliases (components, lib, composables, etc.), preventing duplicate directories segments during installation.
1 parent 9f2b528 commit 8260b9e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,26 @@ export function resolveNestedFilePath(
425425
const normalizedFilePath = filePath.replace(/^\/|\/$/g, '')
426426
const normalizedCommonRoot = commonRoot.replace(/^\/|\/$/g, '')
427427

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(/^\//, '')
428+
// Get all aliases without @ prefix and normalize
429+
const aliases = Object.values(config.aliases)
430+
.map(alias => alias.replace(/^@\//, '').replace(/^\/|\/$/g, ''))
431+
.sort((a, b) => b.length - a.length) // Sort by length descending to match most specific first
432+
433+
// Check if the common root contains any of the aliases
434+
for (const alias of aliases) {
435+
if (normalizedCommonRoot.includes(alias)) {
436+
// Find where the alias ends in the file path
437+
const aliasEndIndex = normalizedFilePath.indexOf(alias) + alias.length
438+
439+
// Return everything after the alias (skip the leading slash if present)
440+
// Example: "components/ai-elements/artifact/Artifact.vue" -> "ai-elements/artifact/Artifact.vue"
441+
// Example: "lib/utils/cn.ts" -> "utils/cn.ts"
442+
// Example: "composables/useCounter.ts" -> "useCounter.ts"
443+
return normalizedFilePath.substring(aliasEndIndex).replace(/^\//, '')
444+
}
440445
}
441446

442-
// Fallback to original logic for non-component paths
447+
// Fallback to original logic for non-aliased paths
443448
// Example: "registry/new-york-v4/ui/button/Button.vue" -> "button/Button.vue"
444449
const lastCommonRootSegment = normalizedCommonRoot.split('/').pop()
445450

0 commit comments

Comments
 (0)