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
4f9086f0e7
commit
6579b705e9
|
@ -25,6 +25,7 @@ class ResolutionRequest {
|
||||||
helpers,
|
helpers,
|
||||||
moduleCache,
|
moduleCache,
|
||||||
fastfs,
|
fastfs,
|
||||||
|
shouldThrowOnUnresolvedErrors,
|
||||||
}) {
|
}) {
|
||||||
this._platform = platform;
|
this._platform = platform;
|
||||||
this._preferNativePlatform = preferNativePlatform;
|
this._preferNativePlatform = preferNativePlatform;
|
||||||
|
@ -34,6 +35,7 @@ class ResolutionRequest {
|
||||||
this._helpers = helpers;
|
this._helpers = helpers;
|
||||||
this._moduleCache = moduleCache;
|
this._moduleCache = moduleCache;
|
||||||
this._fastfs = fastfs;
|
this._fastfs = fastfs;
|
||||||
|
this._shouldThrowOnUnresolvedErrors = shouldThrowOnUnresolvedErrors;
|
||||||
this._resetResolutionCache();
|
this._resetResolutionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +69,10 @@ class ResolutionRequest {
|
||||||
};
|
};
|
||||||
|
|
||||||
const forgive = (error) => {
|
const forgive = (error) => {
|
||||||
if (error.type !== 'UnableToResolveError' ||
|
if (
|
||||||
this._platform === 'ios') {
|
error.type !== 'UnableToResolveError' ||
|
||||||
|
this._shouldThrowOnUnresolvedErrors(this._entryPath, this._platform)
|
||||||
|
) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ describe('DependencyGraph', function() {
|
||||||
'parse',
|
'parse',
|
||||||
],
|
],
|
||||||
platforms: ['ios', 'android'],
|
platforms: ['ios', 'android'],
|
||||||
|
shouldThrowOnUnresolvedErrors: () => false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class DependencyGraph {
|
||||||
extensions,
|
extensions,
|
||||||
mocksPattern,
|
mocksPattern,
|
||||||
extractRequires,
|
extractRequires,
|
||||||
|
shouldThrowOnUnresolvedErrors = () => true,
|
||||||
}) {
|
}) {
|
||||||
this._opts = {
|
this._opts = {
|
||||||
activity: activity || defaultActivity,
|
activity: activity || defaultActivity,
|
||||||
|
@ -57,6 +58,7 @@ class DependencyGraph {
|
||||||
extensions: extensions || ['js', 'json'],
|
extensions: extensions || ['js', 'json'],
|
||||||
mocksPattern,
|
mocksPattern,
|
||||||
extractRequires,
|
extractRequires,
|
||||||
|
shouldThrowOnUnresolvedErrors,
|
||||||
};
|
};
|
||||||
this._cache = this._opts.cache;
|
this._cache = this._opts.cache;
|
||||||
this._helpers = new DependencyGraphHelpers(this._opts);
|
this._helpers = new DependencyGraphHelpers(this._opts);
|
||||||
|
@ -163,6 +165,7 @@ class DependencyGraph {
|
||||||
helpers: this._helpers,
|
helpers: this._helpers,
|
||||||
moduleCache: this._moduleCache,
|
moduleCache: this._moduleCache,
|
||||||
fastfs: this._fastfs,
|
fastfs: this._fastfs,
|
||||||
|
shouldThrowOnUnresolvedErrors: this._opts.shouldThrowOnUnresolvedErrors,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = new ResolutionResponse();
|
const response = new ResolutionResponse();
|
||||||
|
|
|
@ -95,6 +95,7 @@ class Resolver {
|
||||||
preferNativePlatform: true,
|
preferNativePlatform: true,
|
||||||
fileWatcher: opts.fileWatcher,
|
fileWatcher: opts.fileWatcher,
|
||||||
cache: opts.cache,
|
cache: opts.cache,
|
||||||
|
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
|
||||||
});
|
});
|
||||||
|
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||||
|
|
Loading…
Reference in New Issue