mirror of
https://github.com/status-im/metro.git
synced 2025-01-21 00:19:31 +00:00
metro: ModuleResolution: move tryResolveSync 1 level up
Reviewed By: davidaurelio Differential Revision: D6610856 fbshipit-source-id: cc9c0e0d09785882e3b977dea5e8bc072099be71
This commit is contained in:
parent
78802d7a42
commit
9ff46c13e3
@ -121,22 +121,6 @@ type FileResolution =
|
||||
| {|+type: 'sourceFile', +filePath: string|}
|
||||
| {|+type: 'assetFiles', +filePaths: AssetFileResolution|};
|
||||
|
||||
/**
|
||||
* It may not be a great pattern to leverage exception just for "trying" things
|
||||
* out, notably for performance. We should consider replacing these functions
|
||||
* to be nullable-returning, or being better stucture to the algorithm.
|
||||
*/
|
||||
function tryResolveSync<T>(action: () => T, secondaryAction: () => T): T {
|
||||
try {
|
||||
return action();
|
||||
} catch (error) {
|
||||
if (!(error instanceof UnableToResolveError)) {
|
||||
throw error;
|
||||
}
|
||||
return secondaryAction();
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
||||
_options: Options<TModule, TPackage>;
|
||||
|
||||
@ -742,5 +726,4 @@ module.exports = {
|
||||
UnableToResolveError,
|
||||
ModuleResolver,
|
||||
isRelativeImport,
|
||||
tryResolveSync,
|
||||
};
|
||||
|
@ -100,7 +100,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
||||
}
|
||||
|
||||
return cacheResult(
|
||||
ModuleResolution.tryResolveSync(
|
||||
tryResolveSync(
|
||||
() => this._resolveHasteDependency(fromModule, toModuleName, platform),
|
||||
() =>
|
||||
resolver.resolveNodeDependency(fromModule, toModuleName, platform),
|
||||
@ -137,6 +137,22 @@ function getResolutionCacheKey(modulePath, depName) {
|
||||
return `${path.resolve(modulePath)}:${depName}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* It may not be a great pattern to leverage exception just for "trying" things
|
||||
* out, notably for performance. We should consider replacing these functions
|
||||
* to be nullable-returning, or being better stucture to the algorithm.
|
||||
*/
|
||||
function tryResolveSync<T>(action: () => T, secondaryAction: () => T): T {
|
||||
try {
|
||||
return action();
|
||||
} catch (error) {
|
||||
if (!(error instanceof ModuleResolution.UnableToResolveError)) {
|
||||
throw error;
|
||||
}
|
||||
return secondaryAction();
|
||||
}
|
||||
}
|
||||
|
||||
class AmbiguousModuleResolutionError extends Error {
|
||||
fromModulePath: string;
|
||||
hasteError: DuplicateHasteCandidatesError;
|
||||
|
Loading…
x
Reference in New Issue
Block a user