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
This commit is contained in:
Jean Lauliac 2017-05-22 11:30:47 -07:00 committed by Facebook Github Bot
parent 307eede076
commit 91fdb10abf
1 changed files with 15 additions and 10 deletions

View File

@ -481,11 +481,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
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<TModule: Moduleish, TPackage: Packageish> {
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<TModule: Moduleish, TPackage: Packageish> {
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,