Skip to content

Commit 4e4e4a2

Browse files
committed
Fix relativeResolve to return normalized paths
- Wrap path.relative result with normalizePath for cross-platform consistency - Handle empty string case to avoid converting '' to '.' - Update test to expect forward slashes instead of platform-specific separators - Remove unused path import from utils test
1 parent d97aee9 commit 4e4e4a2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

registry/src/lib/path.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,10 @@ export function trimLeadingDotSlash(pathLike: string | Buffer | URL): string {
440440
*/
441441
/*@__NO_SIDE_EFFECTS__*/
442442
export function relativeResolve(from: string, to: string): string {
443-
return getPath().relative(from, to)
443+
const relative = getPath().relative(from, to)
444+
// Empty string means same path - don't normalize to '.'
445+
if (relative === '') {
446+
return ''
447+
}
448+
return normalizePath(relative)
444449
}

test/registry/utils.test.mts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path'
2-
31
import { describe, expect, it } from 'vitest'
42

53
// Helper functions moved to outer scope.
@@ -232,7 +230,7 @@ describe('utility modules tests', () => {
232230

233231
it('should get relative path', () => {
234232
expect(pathUtils.relativeResolve('/a/b', '/a/b/c')).toBe('c')
235-
expect(pathUtils.relativeResolve('/a/b', '/a/d')).toBe(`..${path.sep}d`)
233+
expect(pathUtils.relativeResolve('/a/b', '/a/d')).toBe('../d')
236234
})
237235
})
238236
})

0 commit comments

Comments
 (0)