Skip to content
Closed
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
12 changes: 11 additions & 1 deletion packager/src/node-haste/DependencyGraph/ResolutionRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions packager/src/node-haste/__tests__/DependencyGraph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
},
});
Expand All @@ -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,
Expand Down