mirror of https://github.com/status-im/metro.git
Move process.exit outside of DependencyResolver
Summary: node-haste shouldn't ever call process.exit and should leave it up to clients to shut down properly. This change just moves it out into the `Resolver` class – I'll leave it up to David and Martin to improve error handling for the rn packager :) public Reviewed By: davidaurelio Differential Revision: D2889908 fb-gh-sync-id: 6f03162c44d89e268891ef71c8db784a6f2e081d
This commit is contained in:
parent
f2cb2355b2
commit
6d8ccc318b
|
@ -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({
|
var dgraph = new DependencyGraph({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
|
||||||
return dgraph.load().catch(() => {
|
return dgraph.load().catch(err => {
|
||||||
expect(process.exit).toBeCalledWith(1);
|
expect(err.message).toEqual('Failed to build DependencyGraph: Naming collision detected: /root/b.js collides with /root/index.js');
|
||||||
expect(console.error).toBeCalled();
|
expect(err.type).toEqual('DependencyGraphError');
|
||||||
process.exit = _exit;
|
|
||||||
console.error = _error;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ const ResolutionResponse = require('./ResolutionResponse');
|
||||||
const HasteMap = require('./HasteMap');
|
const HasteMap = require('./HasteMap');
|
||||||
const DeprecatedAssetMap = require('./DeprecatedAssetMap');
|
const DeprecatedAssetMap = require('./DeprecatedAssetMap');
|
||||||
|
|
||||||
|
const ERROR_BUILDING_DEP_GRAPH = 'DependencyGraphError';
|
||||||
|
|
||||||
const defaultActivity = {
|
const defaultActivity = {
|
||||||
startEvent: () => {},
|
startEvent: () => {},
|
||||||
endEvent: () => {},
|
endEvent: () => {},
|
||||||
|
@ -63,11 +65,7 @@ class DependencyGraph {
|
||||||
};
|
};
|
||||||
this._cache = cache;
|
this._cache = cache;
|
||||||
this._helpers = new DependencyGraphHelpers(this._opts);
|
this._helpers = new DependencyGraphHelpers(this._opts);
|
||||||
this.load().catch((err) => {
|
this.load();
|
||||||
// This only happens at initialization. Live errors are easier to recover from.
|
|
||||||
console.error('Error building DependencyGraph:\n', err.stack);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
|
@ -134,7 +132,14 @@ class DependencyGraph {
|
||||||
this._deprecatedAssetMap.build(),
|
this._deprecatedAssetMap.build(),
|
||||||
]).then(() =>
|
]).then(() =>
|
||||||
activity.endEvent(depGraphActivity)
|
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;
|
return this._loading;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
jest.dontMock('../')
|
jest.dontMock('../')
|
||||||
.dontMock('underscore')
|
.dontMock('underscore')
|
||||||
.dontMock('PixelRatio')
|
|
||||||
.dontMock('../../DependencyResolver/lib/extractRequires')
|
.dontMock('../../DependencyResolver/lib/extractRequires')
|
||||||
.dontMock('../../DependencyResolver/lib/replacePatterns');
|
.dontMock('../../DependencyResolver/lib/replacePatterns');
|
||||||
|
|
||||||
|
@ -33,6 +32,8 @@ describe('Resolver', function() {
|
||||||
path.join.mockImpl(function(a, b) {
|
path.join.mockImpl(function(a, b) {
|
||||||
return b;
|
return b;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DependencyGraph.prototype.load.mockImpl(() => Promise.resolve());
|
||||||
});
|
});
|
||||||
|
|
||||||
class ResolutionResponseMock {
|
class ResolutionResponseMock {
|
||||||
|
|
|
@ -103,6 +103,11 @@ class Resolver {
|
||||||
});
|
});
|
||||||
|
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||||
|
|
||||||
|
this._depGraph.load().catch(err => {
|
||||||
|
console.error(err.message + '\n' + err.stack);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getShallowDependencies(entryFile) {
|
getShallowDependencies(entryFile) {
|
||||||
|
|
Loading…
Reference in New Issue