packager: ResolutionRequest.js: sync _resolveHasteDependency()

Summary: Some more synchronicity, one step at a time.

Reviewed By: davidaurelio

Differential Revision: D4756542

fbshipit-source-id: 0c56dbca61b3da764aa8d28e29c0e20b54de091e
This commit is contained in:
Jean Lauliac 2017-03-23 11:07:12 -07:00 committed by Facebook Github Bot
parent aec6307c4c
commit a9589df976
1 changed files with 47 additions and 48 deletions

View File

@ -131,7 +131,7 @@ class ResolutionRequest {
if (!this._helpers.isNodeModulesDir(fromModule.path) if (!this._helpers.isNodeModulesDir(fromModule.path)
&& !(isRelativeImport(toModuleName) || isAbsolutePath(toModuleName))) { && !(isRelativeImport(toModuleName) || isAbsolutePath(toModuleName))) {
return this._tryResolve( return this._tryResolve(
() => this._resolveHasteDependency(fromModule, toModuleName), () => Promise.resolve().then(() => this._resolveHasteDependency(fromModule, toModuleName)),
() => this._resolveNodeDependency(fromModule, toModuleName) () => this._resolveNodeDependency(fromModule, toModuleName)
).then(cacheResult); ).then(cacheResult);
} }
@ -243,17 +243,17 @@ class ResolutionRequest {
}); });
} }
_resolveHasteDependency(fromModule: Module, toModuleName: string): Promise<Module> { _resolveHasteDependency(fromModule: Module, toModuleName: string): Module {
toModuleName = normalizePath(toModuleName); toModuleName = normalizePath(toModuleName);
let p = fromModule.getPackage(); const pck = fromModule.getPackage();
if (p) { let realModuleName;
p = Promise.resolve(p.redirectRequire(toModuleName)); if (pck) {
realModuleName = pck.redirectRequire(toModuleName);
} else { } else {
p = Promise.resolve(toModuleName); realModuleName = toModuleName;
} }
return p.then(realModuleName => {
const modulePath = this._moduleMap const modulePath = this._moduleMap
.getModule(realModuleName, this._platform, /* supportsNativePlatform */ true); .getModule(realModuleName, this._platform, /* supportsNativePlatform */ true);
if (modulePath != null) { if (modulePath != null) {
@ -299,7 +299,6 @@ class ResolutionRequest {
toModuleName, toModuleName,
'Unable to resolve dependency', 'Unable to resolve dependency',
); );
});
} }
_redirectRequire(fromModule: Module, modulePath: string): string | false { _redirectRequire(fromModule: Module, modulePath: string): string | false {