Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/metro-file-map/src/lib/RootPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export class RootPathUtils {
if (right.length === 0) {
return left;
}
if (path.isAbsolute(right)) {
return right;
}
// left may already end in a path separator only if it is a filesystem root,
// '/' or 'X:\'.
if (i === this.#rootDepth) {
Expand Down
14 changes: 14 additions & 0 deletions packages/metro-file-map/src/lib/__tests__/RootPathUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ describe.each([['win32'], ['posix']])('RootPathUtils on %s', platform => {
expect(pathUtils.normalToAbsolute(normalPath)).toEqual(expected);
});

if (platform === 'win32') {
test.each(['D:\\some\\file.js', 'D:\\some\\', 'D:\\'])(
`normalToAbsolute('%s') returns cross-drive absolute normal path as-is`,
normalPath => {
// On Windows, path.relative() returns an absolute path when source
// and target are on different drives. Such paths are stored as the
// "normal path" in the file map and must be returned as-is by
// normalToAbsolute rather than being prepended with rootDir (which
// would produce invalid paths like C:\project\root\D:\file.js).
expect(pathUtils.normalToAbsolute(normalPath)).toEqual(normalPath);
},
);
}

test.each([
p('..'),
p('../root'),
Expand Down