Permalink
Browse files

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
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed May 22, 2017
1 parent bfc0e8c commit 9aeed3907fda1a962c6bf5146419cbb47b7e3c33
Showing with 15 additions and 10 deletions.
  1. +15 −10 packager/src/node-haste/DependencyGraph/ResolutionRequest.js
@@ -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,

0 comments on commit 9aeed39

Please sign in to comment.