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:
Christoph Pojer 2016-01-07 06:13:14 -08:00 committed by facebook-github-bot-3
parent db91ff81fd
commit a62f260680
4 changed files with 11 additions and 2 deletions

View File

@ -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;
}

View File

@ -70,6 +70,7 @@ describe('DependencyGraph', function() {
'parse',
],
platforms: ['ios', 'android'],
shouldThrowOnUnresolvedErrors: () => false,
};
});

View File

@ -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();

View File

@ -95,6 +95,7 @@ class Resolver {
preferNativePlatform: true,
fileWatcher: opts.fileWatcher,
cache: opts.cache,
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
});
this._polyfillModuleNames = opts.polyfillModuleNames || [];