packager: create the reporter higher in the stack
Reviewed By: davidaurelio Differential Revision: D4392283 fbshipit-source-id: 4cd470ca0cbddcbb515407b5249272a758849b82
This commit is contained in:
parent
618a14b228
commit
ff50420b0f
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
const InspectorProxy = require('./util/inspectorProxy.js');
|
const InspectorProxy = require('./util/inspectorProxy.js');
|
||||||
const ReactPackager = require('../../packager/react-packager');
|
const ReactPackager = require('../../packager/react-packager');
|
||||||
|
const TerminalReporter = require('../../packager/react-packager/src/lib/TerminalReporter');
|
||||||
|
|
||||||
const attachHMRServer = require('./util/attachHMRServer');
|
const attachHMRServer = require('./util/attachHMRServer');
|
||||||
const connect = require('connect');
|
const connect = require('connect');
|
||||||
|
@ -94,6 +95,7 @@ function getPackagerServer(args, config) {
|
||||||
getTransformOptions: config.getTransformOptions,
|
getTransformOptions: config.getTransformOptions,
|
||||||
platforms: defaultPlatforms.concat(args.platforms),
|
platforms: defaultPlatforms.concat(args.platforms),
|
||||||
projectRoots: args.projectRoots,
|
projectRoots: args.projectRoots,
|
||||||
|
reporter: new TerminalReporter(),
|
||||||
resetCache: args.resetCache,
|
resetCache: args.resetCache,
|
||||||
transformModulePath: transformModulePath,
|
transformModulePath: transformModulePath,
|
||||||
verbose: args.verbose,
|
verbose: args.verbose,
|
||||||
|
|
|
@ -112,6 +112,8 @@ Builds a bundle according to the provided options.
|
||||||
itself
|
itself
|
||||||
* `getTransformOptions` function: A function that acts as a middleware for
|
* `getTransformOptions` function: A function that acts as a middleware for
|
||||||
generating options to pass to the transformer based on the bundle being built.
|
generating options to pass to the transformer based on the bundle being built.
|
||||||
|
* `reporter` object (required): An object with a single function `update` that
|
||||||
|
is called when events are happening: build updates, warnings, errors.
|
||||||
|
|
||||||
#### `bundleOptions`
|
#### `bundleOptions`
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
const Logger = require('./src/Logger');
|
const Logger = require('./src/Logger');
|
||||||
|
|
||||||
const debug = require('debug');
|
const debug = require('debug');
|
||||||
|
const invariant = require('invariant');
|
||||||
|
|
||||||
import type {Reporter} from './src/lib/reporting';
|
import type {Reporter} from './src/lib/reporting';
|
||||||
|
|
||||||
|
@ -27,6 +28,13 @@ type Options = {
|
||||||
watch?: boolean,
|
watch?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type StrictOptions = {
|
||||||
|
nonPersistent: boolean,
|
||||||
|
projectRoots: Array<string>,
|
||||||
|
reporter: Reporter,
|
||||||
|
watch?: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
exports.buildBundle = function(options: Options, bundleOptions: {}) {
|
exports.buildBundle = function(options: Options, bundleOptions: {}) {
|
||||||
var server = createNonPersistentServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
return server.buildBundle(bundleOptions)
|
return server.buildBundle(bundleOptions)
|
||||||
|
@ -59,21 +67,17 @@ function enableDebug() {
|
||||||
debug.enable(debugPattern);
|
debug.enable(debugPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createServer(options: Options) {
|
function createServer(options: StrictOptions) {
|
||||||
// the debug module is configured globally, we need to enable debugging
|
// the debug module is configured globally, we need to enable debugging
|
||||||
// *before* requiring any packages that use `debug` for logging
|
// *before* requiring any packages that use `debug` for logging
|
||||||
if (options.verbose) {
|
if (options.verbose) {
|
||||||
enableDebug();
|
enableDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some callsites may not be Flowified yet.
|
||||||
|
invariant(options.reporter != null, 'createServer() requires reporter');
|
||||||
const serverOptions = Object.assign({}, options);
|
const serverOptions = Object.assign({}, options);
|
||||||
delete serverOptions.verbose;
|
delete serverOptions.verbose;
|
||||||
if (serverOptions.reporter == null) {
|
|
||||||
// It's unsound to set-up the reporter here, but this allows backward
|
|
||||||
// compatibility.
|
|
||||||
var TerminalReporter = require('./src/lib/TerminalReporter');
|
|
||||||
serverOptions.reporter = new TerminalReporter();
|
|
||||||
}
|
|
||||||
var Server = require('./src/Server');
|
var Server = require('./src/Server');
|
||||||
return new Server(serverOptions);
|
return new Server(serverOptions);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue