packager: ResolutionRequest.js: resolveDependency() now sync

Reviewed By: davidaurelio

Differential Revision: D4763593

fbshipit-source-id: b3dc95229d040c776833a88c9a156b9168e0cc4c
This commit is contained in:
Jean Lauliac 2017-03-27 09:43:13 -07:00 committed by Facebook Github Bot
parent 62c07e39dc
commit f2340c746b
1 changed files with 14 additions and 15 deletions

View File

@ -116,11 +116,12 @@ class ResolutionRequest {
} }
// TODO(cpojer): Remove 'any' type. This is used for ModuleGraph/node-haste // TODO(cpojer): Remove 'any' type. This is used for ModuleGraph/node-haste
resolveDependency(fromModule: Module | any, toModuleName: string) { resolveDependency(fromModule: Module | any, toModuleName: string): Module {
const resHash = resolutionHash(fromModule.path, toModuleName); const resHash = resolutionHash(fromModule.path, toModuleName);
if (this._immediateResolutionCache[resHash]) { const immediateResolution = this._immediateResolutionCache[resHash];
return Promise.resolve(this._immediateResolutionCache[resHash]); if (immediateResolution) {
return immediateResolution;
} }
const cacheResult = result => { const cacheResult = result => {
@ -130,15 +131,14 @@ 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( const result = tryResolveSync(
() => Promise.resolve().then(() => this._resolveHasteDependency(fromModule, toModuleName)), () => this._resolveHasteDependency(fromModule, toModuleName),
() => Promise.resolve().then(() => this._resolveNodeDependency(fromModule, toModuleName)) () => this._resolveNodeDependency(fromModule, toModuleName),
).then(cacheResult); );
return cacheResult(result);
} }
return Promise.resolve() return cacheResult(this._resolveNodeDependency(fromModule, toModuleName));
.then(() => this._resolveNodeDependency(fromModule, toModuleName))
.then(cacheResult);
} }
getOrderedDependencies({ getOrderedDependencies({
@ -160,11 +160,10 @@ class ResolutionRequest {
const resolveDependencies = module => const resolveDependencies = module =>
module.getDependencies(transformOptions) module.getDependencies(transformOptions)
.then(dependencyNames => .then(dependencyNames => {
Promise.all( const dependencies = dependencyNames.map(name => this.resolveDependency(module, name));
dependencyNames.map(name => this.resolveDependency(module, name)) return [dependencyNames, dependencies];
).then(dependencies => [dependencyNames, dependencies]) });
);
const collectedDependencies = new MapWithDefaults(module => collect(module)); const collectedDependencies = new MapWithDefaults(module => collect(module));
const crawlDependencies = (mod, [depNames, dependencies]) => { const crawlDependencies = (mod, [depNames, dependencies]) => {