mirror of https://github.com/status-im/metro.git
Add option to throw/not throw when module can't resolve
Reviewed By: martinbigio Differential Revision: D2808973 fb-gh-sync-id: 2e06355d1e0dd3c1ea297273c44858ec4ed574ee
This commit is contained in:
parent
db91ff81fd
commit
a62f260680
|
@ -25,6 +25,7 @@ class ResolutionRequest {
|
|||
helpers,
|
||||
moduleCache,
|
||||
fastfs,
|
||||
shouldThrowOnUnresolvedErrors,
|
||||
}) {
|
||||
this._platform = platform;
|
||||
this._preferNativePlatform = preferNativePlatform;
|
||||
|
@ -34,6 +35,7 @@ class ResolutionRequest {
|
|||
this._helpers = helpers;
|
||||
this._moduleCache = moduleCache;
|
||||
this._fastfs = fastfs;
|
||||
this._shouldThrowOnUnresolvedErrors = shouldThrowOnUnresolvedErrors;
|
||||
this._resetResolutionCache();
|
||||
}
|
||||
|
||||
|
@ -67,8 +69,10 @@ class ResolutionRequest {
|
|||
};
|
||||
|
||||
const forgive = (error) => {
|
||||
if (error.type !== 'UnableToResolveError' ||
|
||||
this._platform === 'ios') {
|
||||
if (
|
||||
error.type !== 'UnableToResolveError' ||
|
||||
this._shouldThrowOnUnresolvedErrors(this._entryPath, this._platform)
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ describe('DependencyGraph', function() {
|
|||
'parse',
|
||||
],
|
||||
platforms: ['ios', 'android'],
|
||||
shouldThrowOnUnresolvedErrors: () => false,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class DependencyGraph {
|
|||
extensions,
|
||||
mocksPattern,
|
||||
extractRequires,
|
||||
shouldThrowOnUnresolvedErrors = () => true,
|
||||
}) {
|
||||
this._opts = {
|
||||
activity: activity || defaultActivity,
|
||||
|
@ -57,6 +58,7 @@ class DependencyGraph {
|
|||
extensions: extensions || ['js', 'json'],
|
||||
mocksPattern,
|
||||
extractRequires,
|
||||
shouldThrowOnUnresolvedErrors,
|
||||
};
|
||||
this._cache = this._opts.cache;
|
||||
this._helpers = new DependencyGraphHelpers(this._opts);
|
||||
|
@ -163,6 +165,7 @@ class DependencyGraph {
|
|||
helpers: this._helpers,
|
||||
moduleCache: this._moduleCache,
|
||||
fastfs: this._fastfs,
|
||||
shouldThrowOnUnresolvedErrors: this._opts.shouldThrowOnUnresolvedErrors,
|
||||
});
|
||||
|
||||
const response = new ResolutionResponse();
|
||||
|
|
|
@ -95,6 +95,7 @@ class Resolver {
|
|||
preferNativePlatform: true,
|
||||
fileWatcher: opts.fileWatcher,
|
||||
cache: opts.cache,
|
||||
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
|
||||
});
|
||||
|
||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||
|
|
Loading…
Reference in New Issue