Skip to content

Commit

Permalink
Add option to throw/not throw when module can't resolve
Browse files Browse the repository at this point in the history
Reviewed By: martinbigio

Differential Revision: D2808973

fb-gh-sync-id: 2e06355d1e0dd3c1ea297273c44858ec4ed574ee
  • Loading branch information
cpojer authored and facebook-github-bot-3 committed Jan 7, 2016
1 parent 4f9086f commit 6579b70
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Expand Up @@ -25,6 +25,7 @@ class ResolutionRequest {
helpers,
moduleCache,
fastfs,
shouldThrowOnUnresolvedErrors,
}) {
this._platform = platform;
this._preferNativePlatform = preferNativePlatform;
Expand All @@ -34,6 +35,7 @@ class ResolutionRequest {
this._helpers = helpers;
this._moduleCache = moduleCache;
this._fastfs = fastfs;
this._shouldThrowOnUnresolvedErrors = shouldThrowOnUnresolvedErrors;
this._resetResolutionCache();
}

Expand Down Expand Up @@ -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;
}

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

Expand Down
Expand Up @@ -42,6 +42,7 @@ class DependencyGraph {
extensions,
mocksPattern,
extractRequires,
shouldThrowOnUnresolvedErrors = () => true,
}) {
this._opts = {
activity: activity || defaultActivity,
Expand All @@ -57,6 +58,7 @@ class DependencyGraph {
extensions: extensions || ['js', 'json'],
mocksPattern,
extractRequires,
shouldThrowOnUnresolvedErrors,
};
this._cache = this._opts.cache;
this._helpers = new DependencyGraphHelpers(this._opts);
Expand Down Expand Up @@ -163,6 +165,7 @@ class DependencyGraph {
helpers: this._helpers,
moduleCache: this._moduleCache,
fastfs: this._fastfs,
shouldThrowOnUnresolvedErrors: this._opts.shouldThrowOnUnresolvedErrors,
});

const response = new ResolutionResponse();
Expand Down
1 change: 1 addition & 0 deletions packager/react-packager/src/Resolver/index.js
Expand Up @@ -95,6 +95,7 @@ class Resolver {
preferNativePlatform: true,
fileWatcher: opts.fileWatcher,
cache: opts.cache,
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
});

this._polyfillModuleNames = opts.polyfillModuleNames || [];
Expand Down

0 comments on commit 6579b70

Please sign in to comment.