From d012a1fc84e6a7f25ef404103cb4a384ad74c5a3 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 23 May 2017 12:31:32 -0700 Subject: [PATCH] packager: ResolutionRequest: use _loadAsFile from _loadAsDir Summary: We can switch that case easily since it was already discarding the error if any would happen. Reviewed By: davidaurelio Differential Revision: D5103851 fbshipit-source-id: a0991f626e94a45efbf666561041af258fdbef0a --- .../DependencyGraph/ResolutionRequest.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js index c20150f6..c8c474df 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -732,13 +732,16 @@ class ResolutionRequest { ): TModule { const packageJsonPath = path.join(potentialDirPath, 'package.json'); if (this._options.hasteFS.exists(packageJsonPath)) { - const main = this._options.moduleCache - .getPackage(packageJsonPath) - .getMain(); - return tryResolveSync( - () => this._loadAsFileOrThrow(main, fromModule, toModule), - () => this._loadAsDir(main, fromModule, toModule), - ); + const package_ = this._options.moduleCache.getPackage(packageJsonPath); + const mainPrefixPath = package_.getMain(); + const dirPath = path.dirname(mainPrefixPath); + const prefixName = path.basename(mainPrefixPath); + const candidates = []; + const module = this._loadAsFile(dirPath, prefixName, candidates); + if (module != null) { + return module; + } + return this._loadAsDir(mainPrefixPath, fromModule, toModule); } return this._loadAsFileOrThrow(