From 6579b705e99c925ddaed10ddcdb7ba303ccb771f Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Thu, 7 Jan 2016 06:13:14 -0800 Subject: [PATCH] Add option to throw/not throw when module can't resolve Reviewed By: martinbigio Differential Revision: D2808973 fb-gh-sync-id: 2e06355d1e0dd3c1ea297273c44858ec4ed574ee --- .../DependencyGraph/ResolutionRequest.js | 8 ++++++-- .../DependencyGraph/__tests__/DependencyGraph-test.js | 1 + .../src/DependencyResolver/DependencyGraph/index.js | 3 +++ packager/react-packager/src/Resolver/index.js | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js b/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js index f896de27c..f4b200007 100644 --- a/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js +++ b/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js @@ -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; } diff --git a/packager/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/packager/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index cd434a1d2..184ea71fc 100644 --- a/packager/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/packager/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -70,6 +70,7 @@ describe('DependencyGraph', function() { 'parse', ], platforms: ['ios', 'android'], + shouldThrowOnUnresolvedErrors: () => false, }; }); diff --git a/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js b/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js index ec0d964e0..634cf5dab 100644 --- a/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js +++ b/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js @@ -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(); diff --git a/packager/react-packager/src/Resolver/index.js b/packager/react-packager/src/Resolver/index.js index 8726233e8..b2466dcc1 100644 --- a/packager/react-packager/src/Resolver/index.js +++ b/packager/react-packager/src/Resolver/index.js @@ -95,6 +95,7 @@ class Resolver { preferNativePlatform: true, fileWatcher: opts.fileWatcher, cache: opts.cache, + shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios', }); this._polyfillModuleNames = opts.polyfillModuleNames || [];