Permalink
Browse files

packager: ResolutionRequest.js: resolveDependency() now sync

Reviewed By: davidaurelio

Differential Revision: D4763593

fbshipit-source-id: b3dc95229d040c776833a88c9a156b9168e0cc4c
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Mar 27, 2017
1 parent b96e210 commit e0ad42592b99c3a912210d7259b773c839f4eb08
Showing with 14 additions and 15 deletions.
  1. +14 −15 packager/src/node-haste/DependencyGraph/ResolutionRequest.js
@@ -116,11 +116,12 @@ class ResolutionRequest {
}
// 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);
if (this._immediateResolutionCache[resHash]) {
return Promise.resolve(this._immediateResolutionCache[resHash]);
const immediateResolution = this._immediateResolutionCache[resHash];
if (immediateResolution) {
return immediateResolution;
}
const cacheResult = result => {
@@ -130,15 +131,14 @@ class ResolutionRequest {
if (!this._helpers.isNodeModulesDir(fromModule.path)
&& !(isRelativeImport(toModuleName) || isAbsolutePath(toModuleName))) {
return this._tryResolve(
() => Promise.resolve().then(() => this._resolveHasteDependency(fromModule, toModuleName)),
() => Promise.resolve().then(() => this._resolveNodeDependency(fromModule, toModuleName))
).then(cacheResult);
const result = tryResolveSync(
() => this._resolveHasteDependency(fromModule, toModuleName),
() => this._resolveNodeDependency(fromModule, toModuleName),
);
return cacheResult(result);
}
return Promise.resolve()
.then(() => this._resolveNodeDependency(fromModule, toModuleName))
.then(cacheResult);
return cacheResult(this._resolveNodeDependency(fromModule, toModuleName));
}
getOrderedDependencies({
@@ -160,11 +160,10 @@ class ResolutionRequest {
const resolveDependencies = module =>
module.getDependencies(transformOptions)
.then(dependencyNames =>
Promise.all(
dependencyNames.map(name => this.resolveDependency(module, name))
).then(dependencies => [dependencyNames, dependencies])
);
.then(dependencyNames => {
const dependencies = dependencyNames.map(name => this.resolveDependency(module, name));
return [dependencyNames, dependencies];
});
const collectedDependencies = new MapWithDefaults(module => collect(module));
const crawlDependencies = (mod, [depNames, dependencies]) => {

0 comments on commit e0ad425

Please sign in to comment.