From e66f5a3ebbbe0ef21259ba9259ef373a15d70898 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Wed, 10 May 2017 05:14:04 -0700 Subject: [PATCH] packager: ResolutionRequest: check dir existence only on error Reviewed By: davidaurelio Differential Revision: D5028476 fbshipit-source-id: 848d7f6a7b6ab046a5e489a56dc224f3296cea02 --- .../DependencyGraph/ResolutionRequest.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js index 9da29fd3..708b47fe 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -442,36 +442,38 @@ class ResolutionRequest { currDir !== '.' && currDir !== realPath.parse(fromModule.path).root; currDir = path.dirname(currDir)) { const searchPath = path.join(currDir, 'node_modules'); - if (this._options.dirExists(searchPath)) { - searchQueue.push( - path.join(searchPath, realModuleName) - ); - } + searchQueue.push(path.join(searchPath, realModuleName)); } + const extraSearchQueue = []; if (this._options.extraNodeModules) { const {extraNodeModules} = this._options; const bits = toModuleName.split(path.sep); const packageName = bits[0]; if (extraNodeModules[packageName]) { bits[0] = extraNodeModules[packageName]; - searchQueue.push(path.join.apply(path, bits)); + extraSearchQueue.push(path.join.apply(path, bits)); } } - for (let i = 0; i < searchQueue.length; ++i) { - const resolvedModule = this._tryResolveNodeDep(searchQueue[i], fromModule, toModuleName); + const fullSearchQueue = searchQueue.concat(extraSearchQueue); + for (let i = 0; i < fullSearchQueue.length; ++i) { + const resolvedModule = this._tryResolveNodeDep(fullSearchQueue[i], fromModule, toModuleName); if (resolvedModule != null) { return resolvedModule; } } - const hint = searchQueue.length ? ' or in these directories:' : ''; + const displaySearchQueue = searchQueue + .filter(dirPath => this._options.dirExists(dirPath)) + .concat(extraSearchQueue); + + const hint = displaySearchQueue.length ? ' or in these directories:' : ''; throw new UnableToResolveError( fromModule, toModuleName, `Module does not exist in the module map${hint}\n` + - searchQueue.map(searchPath => ` ${path.dirname(searchPath)}\n`).join(', ') + '\n' + + displaySearchQueue.map(searchPath => ` ${path.dirname(searchPath)}\n`).join(', ') + '\n' + `This might be related to https://github.com/facebook/react-native/issues/4968\n` + `To resolve try the following:\n` + ` 1. Clear watchman watches: \`watchman watch-del-all\`.\n` +