diff --git a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index 66d02729..09a44543 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -1189,22 +1189,14 @@ describe('DependencyGraph', function() { }, }); - const _exit = process.exit; - const _error = console.error; - - process.exit = jest.genMockFn(); - console.error = jest.genMockFn(); - var dgraph = new DependencyGraph({ ...defaults, roots: [root], }); - return dgraph.load().catch(() => { - expect(process.exit).toBeCalledWith(1); - expect(console.error).toBeCalled(); - process.exit = _exit; - console.error = _error; + return dgraph.load().catch(err => { + expect(err.message).toEqual('Failed to build DependencyGraph: Naming collision detected: /root/b.js collides with /root/index.js'); + expect(err.type).toEqual('DependencyGraphError'); }); }); diff --git a/react-packager/src/DependencyResolver/DependencyGraph/index.js b/react-packager/src/DependencyResolver/DependencyGraph/index.js index bc5d85d7..3c5ade66 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/index.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/index.js @@ -22,6 +22,8 @@ const ResolutionResponse = require('./ResolutionResponse'); const HasteMap = require('./HasteMap'); const DeprecatedAssetMap = require('./DeprecatedAssetMap'); +const ERROR_BUILDING_DEP_GRAPH = 'DependencyGraphError'; + const defaultActivity = { startEvent: () => {}, endEvent: () => {}, @@ -63,11 +65,7 @@ class DependencyGraph { }; this._cache = cache; this._helpers = new DependencyGraphHelpers(this._opts); - this.load().catch((err) => { - // This only happens at initialization. Live errors are easier to recover from. - console.error('Error building DependencyGraph:\n', err.stack); - process.exit(1); - }); + this.load(); } load() { @@ -134,7 +132,14 @@ class DependencyGraph { this._deprecatedAssetMap.build(), ]).then(() => activity.endEvent(depGraphActivity) - ); + ).catch(err => { + const error = new Error( + `Failed to build DependencyGraph: ${err.message}` + ); + error.type = ERROR_BUILDING_DEP_GRAPH; + error.stack = err.stack; + throw error; + }); return this._loading; } diff --git a/react-packager/src/Resolver/__tests__/Resolver-test.js b/react-packager/src/Resolver/__tests__/Resolver-test.js index 962bba96..7ef335d9 100644 --- a/react-packager/src/Resolver/__tests__/Resolver-test.js +++ b/react-packager/src/Resolver/__tests__/Resolver-test.js @@ -10,7 +10,6 @@ jest.dontMock('../') .dontMock('underscore') - .dontMock('PixelRatio') .dontMock('../../DependencyResolver/lib/extractRequires') .dontMock('../../DependencyResolver/lib/replacePatterns'); @@ -33,6 +32,8 @@ describe('Resolver', function() { path.join.mockImpl(function(a, b) { return b; }); + + DependencyGraph.prototype.load.mockImpl(() => Promise.resolve()); }); class ResolutionResponseMock { diff --git a/react-packager/src/Resolver/index.js b/react-packager/src/Resolver/index.js index 1822eb99..4c6e3efb 100644 --- a/react-packager/src/Resolver/index.js +++ b/react-packager/src/Resolver/index.js @@ -103,6 +103,11 @@ class Resolver { }); this._polyfillModuleNames = opts.polyfillModuleNames || []; + + this._depGraph.load().catch(err => { + console.error(err.message + '\n' + err.stack); + process.exit(1); + }); } getShallowDependencies(entryFile) {