diff --git a/packages/metro-resolver/src/PackageResolve.js b/packages/metro-resolver/src/PackageResolve.js index 187da7e1e2..f42d63b1ae 100644 --- a/packages/metro-resolver/src/PackageResolve.js +++ b/packages/metro-resolver/src/PackageResolve.js @@ -134,7 +134,9 @@ export function redirectModulePath( // BRITTLE ASSUMPTION: This is always treated as a package-relative path // and is converted back, even if the redirected path is a specifier // referring to another package. - redirectedPath = path.resolve(containingPackage.rootPath, redirectedPath); + redirectedPath = path.isAbsolute(redirectedPath) + ? path.normalize(redirectedPath) + : path.join(containingPackage.rootPath, redirectedPath); } } else { // Otherwise, `modulePath` may be an unprefixed relative path or a bare diff --git a/packages/metro-resolver/src/resolve.js b/packages/metro-resolver/src/resolve.js index 3aa4c4f899..1799358c00 100644 --- a/packages/metro-resolver/src/resolve.js +++ b/packages/metro-resolver/src/resolve.js @@ -220,8 +220,11 @@ function resolveModulePath( toModuleName: string, platform: string | null, ): Result { + // System-separated absolute path const modulePath = path.isAbsolute(toModuleName) - ? resolveWindowsPath(toModuleName) + ? path.sep === '/' + ? toModuleName + : toModuleName.replaceAll('/', '\\') : path.join(path.dirname(context.originModulePath), toModuleName); const redirectedPath = context.redirectModulePath(modulePath); if (redirectedPath === false) { @@ -584,16 +587,6 @@ function resolveSourceFileForExt( return null; } -// HasteFS stores paths with backslashes on Windows, this ensures the path is in -// the proper format. Will also add drive letter if not present so `/root` will -// resolve to `C:\root`. Noop on other platforms. -function resolveWindowsPath(modulePath: string) { - if (path.sep !== '\\') { - return modulePath; - } - return path.resolve(modulePath); -} - function isRelativeImport(filePath: string) { return /^[.][.]?(?:[/]|$)/.test(filePath); }