Skip to content

Commit

Permalink
RN local-cli: fix the reporter creation code
Browse files Browse the repository at this point in the history
Reviewed By: mjesun

Differential Revision: D5766153

fbshipit-source-id: 4416e331a7170e49236bcd09555040fd7b5b61b5
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Sep 8, 2017
1 parent 5e4f286 commit 1de6ec4
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -129,46 +135,42 @@ 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
// timeout of 120 seconds to respond to a request.
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();

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,
Expand All @@ -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,
Expand Down

0 comments on commit 1de6ec4

Please sign in to comment.