diff --git a/packager/src/node-haste/DependencyGraph/ResolutionRequest.js b/packager/src/node-haste/DependencyGraph/ResolutionRequest.js index f8b690e637d29c..aec46b751419b4 100644 --- a/packager/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packager/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -278,7 +278,7 @@ class ResolutionRequest { _resolveFileOrDir(fromModule, toModuleName) { const potentialModulePath = isAbsolutePath(toModuleName) ? - toModuleName : + resolveWindowsPath(toModuleName) : path.join(path.dirname(fromModule.path), toModuleName); return this._redirectRequire(fromModule, potentialModulePath).then( @@ -509,6 +509,16 @@ function normalizePath(modulePath) { return modulePath.replace(/\/$/, ''); } +// 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) { + if (path.sep !== '\\') { + return modulePath; + } + return path.resolve(modulePath); +} + function resolveKeyWithPromise([key, promise]) { return promise.then(value => [key, value]); } diff --git a/packager/src/node-haste/__tests__/DependencyGraph-test.js b/packager/src/node-haste/__tests__/DependencyGraph-test.js index a1318d828ff6f2..d1bfdbcbabc261 100644 --- a/packager/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packager/src/node-haste/__tests__/DependencyGraph-test.js @@ -2533,7 +2533,7 @@ describe('DependencyGraph', function() { const root = 'C:\\root'; setMockFileSystem({ 'root': { - 'index.js': 'require("C:\\\\root\\\\apple.js");', + 'index.js': 'require("C:/root/apple.js");', 'apple.js': '', }, }); @@ -2548,7 +2548,7 @@ describe('DependencyGraph', function() { { id: 'C:\\root\\index.js', path: 'C:\\root\\index.js', - dependencies: ['C:\\root\\apple.js'], + dependencies: ['C:/root/apple.js'], isAsset: false, isJSON: false, isPolyfill: false,