From 91fdb10abf4dd7c198ba57566c86e0601801193f Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Mon, 22 May 2017 11:30:47 -0700 Subject: [PATCH] packager: ResolutionRequest: empty module is special case Summary: Because we don't want to test for `empty-module.ios.js`, etc. We know the module is supposed to be here. This simpler version makes it easier for me to switch the rest of the `loadAsFile` callsites to the "candidates" system to the "candidates" system. Reviewed By: davidaurelio Differential Revision: D5103816 fbshipit-source-id: 7e7d9be27573a1f33d562aeb850759e073fbc72f --- .../DependencyGraph/ResolutionRequest.js | 25 +++++++++++-------- 1 file changed, 15 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 bf010ec9..c20150f6 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -481,11 +481,7 @@ class ResolutionRequest { potentialModulePath, ); if (realModuleName === false) { - return this._loadAsFileOrThrow( - ResolutionRequest.EMPTY_MODULE, - fromModule, - toModuleName, - ); + return this._getEmptyModule(fromModule, toModuleName); } return tryResolveSync( @@ -501,11 +497,7 @@ class ResolutionRequest { const realModuleName = this._redirectRequire(fromModule, toModuleName); // exclude if (realModuleName === false) { - return this._loadAsFileOrThrow( - ResolutionRequest.EMPTY_MODULE, - fromModule, - toModuleName, - ); + return this._getEmptyModule(fromModule, toModuleName); } if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) { @@ -720,6 +712,19 @@ class ResolutionRequest { return resolver.tryToResolveFileName(fileName) ? fileName : null; } + _getEmptyModule(fromModule: TModule, toModuleName: string): TModule { + const {moduleCache} = this._options; + const module = moduleCache.getModule(ResolutionRequest.EMPTY_MODULE); + if (module != null) { + return module; + } + throw new UnableToResolveError( + fromModule, + toModuleName, + "could not resolve `${ResolutionRequest.EMPTY_MODULE}'", + ); + } + _loadAsDir( potentialDirPath: string, fromModule: TModule,