mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
RN local-cli: fix the reporter creation code
Reviewed By: mjesun Differential Revision: D5766153 fbshipit-source-id: 4416e331a7170e49236bcd09555040fd7b5b61b5
This commit is contained in:
parent
5e4f286f48
commit
1de6ec46f8
@ -85,8 +85,14 @@ function runServer(
|
||||
) {
|
||||
var wsProxy = null;
|
||||
var ms = null;
|
||||
const packagerServer = getPackagerServer(args, config);
|
||||
startedCallback(packagerServer._reporter);
|
||||
|
||||
/* $FlowFixMe: Flow is wrong, Node.js docs specify that process.stdout is an
|
||||
* instance of a net.Socket (a local socket, not network). */
|
||||
const terminal = new Terminal(process.stdout);
|
||||
const ReporterImpl = getReporterImpl(args.customLogReporterPath || null);
|
||||
const reporter = new ReporterImpl(terminal);
|
||||
const packagerServer = getPackagerServer(args, config, reporter);
|
||||
startedCallback(reporter);
|
||||
|
||||
const app = connect()
|
||||
.use(loadRawBodyMiddleware)
|
||||
@ -129,7 +135,7 @@ function runServer(
|
||||
|
||||
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
|
||||
ms = messageSocket.attachToServer(serverInstance, '/message');
|
||||
readyCallback(packagerServer._reporter);
|
||||
readyCallback(reporter);
|
||||
});
|
||||
// Disable any kind of automatic timeout behavior for incoming
|
||||
// requests in case it takes the packager more than the default
|
||||
@ -137,7 +143,27 @@ function runServer(
|
||||
serverInstance.timeout = 0;
|
||||
}
|
||||
|
||||
function getPackagerServer(args, config) {
|
||||
function getReporterImpl(customLogReporterPath: ?string) {
|
||||
if (customLogReporterPath == null) {
|
||||
return require('metro-bundler/src/lib/TerminalReporter');
|
||||
}
|
||||
try {
|
||||
// First we let require resolve it, so we can require packages in node_modules
|
||||
// as expected. eg: require('my-package/reporter');
|
||||
/* $FlowFixMe: can't type dynamic require */
|
||||
return require(customLogReporterPath);
|
||||
} catch (e) {
|
||||
if (e.code !== 'MODULE_NOT_FOUND') {
|
||||
throw e;
|
||||
}
|
||||
// If that doesn't work, then we next try relative to the cwd, eg:
|
||||
// require('./reporter');
|
||||
/* $FlowFixMe: can't type dynamic require */
|
||||
return require(path.resolve(customLogReporterPath));
|
||||
}
|
||||
}
|
||||
|
||||
function getPackagerServer(args, config, reporter) {
|
||||
const transformModulePath = args.transformer
|
||||
? path.resolve(args.transformer)
|
||||
: config.getTransformModulePath();
|
||||
@ -145,30 +171,6 @@ function getPackagerServer(args, config) {
|
||||
const providesModuleNodeModules =
|
||||
args.providesModuleNodeModules || defaultProvidesModuleNodeModules;
|
||||
|
||||
let LogReporter;
|
||||
if (args.customLogReporterPath) {
|
||||
try {
|
||||
// First we let require resolve it, so we can require packages in node_modules
|
||||
// as expected. eg: require('my-package/reporter');
|
||||
/* $FlowFixMe: can't type dynamic require */
|
||||
LogReporter = require(args.customLogReporterPath);
|
||||
} catch (e) {
|
||||
// If that doesn't work, then we next try relative to the cwd, eg:
|
||||
// require('./reporter');
|
||||
/* $FlowFixMe: can't type dynamic require */
|
||||
LogReporter = require(path.resolve(args.customLogReporterPath));
|
||||
}
|
||||
} else {
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
|
||||
* error found when Flow v0.54 was deployed. To see the error delete this
|
||||
* comment and run Flow. */
|
||||
LogReporter = require('metro-bundler/src/lib/TerminalReporter');
|
||||
}
|
||||
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This comment
|
||||
* suppresses an error found when Flow v0.54 was deployed. To see the error
|
||||
* delete this comment and run Flow. */
|
||||
const terminal = new Terminal(process.stdout);
|
||||
return ReactPackager.createServer({
|
||||
assetExts: defaultAssetExts.concat(args.assetExts),
|
||||
assetRegistryPath: ASSET_REGISTRY_PATH,
|
||||
@ -188,7 +190,7 @@ function getPackagerServer(args, config) {
|
||||
postProcessModules: config.postProcessModules,
|
||||
projectRoots: args.projectRoots,
|
||||
providesModuleNodeModules: providesModuleNodeModules,
|
||||
reporter: new LogReporter(terminal),
|
||||
reporter,
|
||||
resetCache: args.resetCache,
|
||||
sourceExts: defaultSourceExts.concat(args.sourceExts),
|
||||
transformModulePath: transformModulePath,
|
||||
|
Loading…
x
Reference in New Issue
Block a user