@@ -305,7 +305,7 @@ export function resolveFilePath(
305305 config : Config ,
306306 options : {
307307 // isSrcDir?: boolean
308- commonRoot ? : string
308+ commonRoot : string
309309 framework ?: ProjectInfo [ 'framework' ] [ 'name' ]
310310 path ?: string
311311 fileIndex ?: number
@@ -357,7 +357,7 @@ export function resolveFilePath(
357357
358358 const targetDir = resolveFileTargetDirectory ( file , config )
359359
360- const relativePath = resolveNestedFilePath ( file . path , targetDir ! )
360+ const relativePath = resolveNestedFilePath ( file . path , options . commonRoot )
361361 return path . join ( targetDir ! , relativePath )
362362}
363363
@@ -418,29 +418,18 @@ export function findCommonRoot(paths: string[], needle: string): string {
418418
419419export function resolveNestedFilePath (
420420 filePath : string ,
421- targetDir : string ,
421+ commonRoot : string ,
422422) : string {
423423 // Normalize paths by removing leading/trailing slashes
424424 const normalizedFilePath = filePath . replace ( / ^ \/ | \/ $ / g, '' )
425- const normalizedTargetDir = targetDir . replace ( / ^ \/ | \/ $ / g, '' )
425+ const normalizedCommonRoot = commonRoot . replace ( / ^ \/ | \/ $ / g, '' )
426426
427- // Split paths into segments
428- const fileSegments = normalizedFilePath . split ( '/' )
429- const targetSegments = normalizedTargetDir . split ( '/' )
427+ const lastCommonRootSegment = normalizedCommonRoot . split ( '/' ) . pop ( )
430428
431- // Find the last matching segment from targetDir in filePath
432- const lastTargetSegment = targetSegments [ targetSegments . length - 1 ]
433- const commonDirIndex = fileSegments . findIndex (
434- segment => segment === lastTargetSegment ,
435- )
436-
437- if ( commonDirIndex === - 1 ) {
438- // Return just the filename if no common directory is found
439- return fileSegments [ fileSegments . length - 1 ]
440- }
441-
442- // Return everything after the common directory
443- return fileSegments . slice ( commonDirIndex + 1 ) . join ( '/' )
429+ // normalizedFilePath: registry/new-york-v4/ui/button/Button.vue
430+ // normalizedCommonRoot: registry/new-york-v4/ui/button
431+ // return button/Button.vue
432+ return lastCommonRootSegment + normalizedFilePath . replace ( normalizedCommonRoot , '' )
444433}
445434
446435export function resolvePageTarget (
0 commit comments