mirror of
https://github.com/status-im/react-native.git
synced 2025-02-06 22:54:27 +00:00
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:
parent
3f0f7357cf
commit
337daa3d19
@ -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,63 +243,62 @@ 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) {
|
const module = this._moduleCache.getModule(modulePath);
|
||||||
const module = this._moduleCache.getModule(modulePath);
|
/* temporary until we strengthen the typing */
|
||||||
/* temporary until we strengthen the typing */
|
invariant(module.type === 'Module', 'expected Module type');
|
||||||
invariant(module.type === 'Module', 'expected Module type');
|
return module;
|
||||||
return module;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let packageName = realModuleName;
|
|
||||||
let packagePath;
|
|
||||||
while (packageName && packageName !== '.') {
|
|
||||||
packagePath = this._moduleMap
|
|
||||||
.getPackage(packageName, this._platform, /* supportsNativePlatform */ true);
|
|
||||||
if (packagePath != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
packageName = path.dirname(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let packageName = realModuleName;
|
||||||
|
let packagePath;
|
||||||
|
while (packageName && packageName !== '.') {
|
||||||
|
packagePath = this._moduleMap
|
||||||
|
.getPackage(packageName, this._platform, /* supportsNativePlatform */ true);
|
||||||
if (packagePath != null) {
|
if (packagePath != null) {
|
||||||
|
break;
|
||||||
const package_ = this._moduleCache.getPackage(packagePath);
|
|
||||||
/* temporary until we strengthen the typing */
|
|
||||||
invariant(package_.type === 'Package', 'expected Package type');
|
|
||||||
|
|
||||||
const potentialModulePath = path.join(
|
|
||||||
package_.root,
|
|
||||||
path.relative(packageName, realModuleName)
|
|
||||||
);
|
|
||||||
return tryResolveSync(
|
|
||||||
() => this._loadAsFile(
|
|
||||||
potentialModulePath,
|
|
||||||
fromModule,
|
|
||||||
toModuleName,
|
|
||||||
),
|
|
||||||
() => this._loadAsDir(potentialModulePath, fromModule, toModuleName),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
packageName = path.dirname(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
throw new UnableToResolveError(
|
if (packagePath != null) {
|
||||||
fromModule,
|
|
||||||
toModuleName,
|
const package_ = this._moduleCache.getPackage(packagePath);
|
||||||
'Unable to resolve dependency',
|
/* temporary until we strengthen the typing */
|
||||||
|
invariant(package_.type === 'Package', 'expected Package type');
|
||||||
|
|
||||||
|
const potentialModulePath = path.join(
|
||||||
|
package_.root,
|
||||||
|
path.relative(packageName, realModuleName)
|
||||||
);
|
);
|
||||||
});
|
return tryResolveSync(
|
||||||
|
() => this._loadAsFile(
|
||||||
|
potentialModulePath,
|
||||||
|
fromModule,
|
||||||
|
toModuleName,
|
||||||
|
),
|
||||||
|
() => this._loadAsDir(potentialModulePath, fromModule, toModuleName),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnableToResolveError(
|
||||||
|
fromModule,
|
||||||
|
toModuleName,
|
||||||
|
'Unable to resolve dependency',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_redirectRequire(fromModule: Module, modulePath: string): string | false {
|
_redirectRequire(fromModule: Module, modulePath: string): string | false {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user