Skip to content

Commit eb19904

Browse files
Jean Lauliacfacebook-github-bot
authored andcommitted
packager: ResolutionRequest: check dir existence only on error
Reviewed By: davidaurelio Differential Revision: D5028476 fbshipit-source-id: 848d7f6a7b6ab046a5e489a56dc224f3296cea02
1 parent c0babb2 commit eb19904

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packager/src/node-haste/DependencyGraph/ResolutionRequest.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,36 +442,38 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
442442
currDir !== '.' && currDir !== realPath.parse(fromModule.path).root;
443443
currDir = path.dirname(currDir)) {
444444
const searchPath = path.join(currDir, 'node_modules');
445-
if (this._options.dirExists(searchPath)) {
446-
searchQueue.push(
447-
path.join(searchPath, realModuleName)
448-
);
449-
}
445+
searchQueue.push(path.join(searchPath, realModuleName));
450446
}
451447

448+
const extraSearchQueue = [];
452449
if (this._options.extraNodeModules) {
453450
const {extraNodeModules} = this._options;
454451
const bits = toModuleName.split(path.sep);
455452
const packageName = bits[0];
456453
if (extraNodeModules[packageName]) {
457454
bits[0] = extraNodeModules[packageName];
458-
searchQueue.push(path.join.apply(path, bits));
455+
extraSearchQueue.push(path.join.apply(path, bits));
459456
}
460457
}
461458

462-
for (let i = 0; i < searchQueue.length; ++i) {
463-
const resolvedModule = this._tryResolveNodeDep(searchQueue[i], fromModule, toModuleName);
459+
const fullSearchQueue = searchQueue.concat(extraSearchQueue);
460+
for (let i = 0; i < fullSearchQueue.length; ++i) {
461+
const resolvedModule = this._tryResolveNodeDep(fullSearchQueue[i], fromModule, toModuleName);
464462
if (resolvedModule != null) {
465463
return resolvedModule;
466464
}
467465
}
468466

469-
const hint = searchQueue.length ? ' or in these directories:' : '';
467+
const displaySearchQueue = searchQueue
468+
.filter(dirPath => this._options.dirExists(dirPath))
469+
.concat(extraSearchQueue);
470+
471+
const hint = displaySearchQueue.length ? ' or in these directories:' : '';
470472
throw new UnableToResolveError(
471473
fromModule,
472474
toModuleName,
473475
`Module does not exist in the module map${hint}\n` +
474-
searchQueue.map(searchPath => ` ${path.dirname(searchPath)}\n`).join(', ') + '\n' +
476+
displaySearchQueue.map(searchPath => ` ${path.dirname(searchPath)}\n`).join(', ') + '\n' +
475477
`This might be related to https://github.com/facebook/react-native/issues/4968\n` +
476478
`To resolve try the following:\n` +
477479
` 1. Clear watchman watches: \`watchman watch-del-all\`.\n` +

0 commit comments

Comments
 (0)