diff --git a/README.md b/README.md index 0493d955..698b7806 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ Builds a bundle according to the provided options. itself * `getTransformOptions` function: A function that acts as a middleware for 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` diff --git a/react-packager/react-packager.js b/react-packager/react-packager.js index 339adfce..9291c540 100644 --- a/react-packager/react-packager.js +++ b/react-packager/react-packager.js @@ -14,6 +14,7 @@ const Logger = require('./src/Logger'); const debug = require('debug'); +const invariant = require('invariant'); import type {Reporter} from './src/lib/reporting'; @@ -27,6 +28,13 @@ type Options = { watch?: boolean, }; +type StrictOptions = { + nonPersistent: boolean, + projectRoots: Array, + reporter: Reporter, + watch?: boolean, +}; + exports.buildBundle = function(options: Options, bundleOptions: {}) { var server = createNonPersistentServer(options); return server.buildBundle(bundleOptions) @@ -59,21 +67,17 @@ function enableDebug() { debug.enable(debugPattern); } -function createServer(options: Options) { +function createServer(options: StrictOptions) { // the debug module is configured globally, we need to enable debugging // *before* requiring any packages that use `debug` for logging if (options.verbose) { enableDebug(); } + // Some callsites may not be Flowified yet. + invariant(options.reporter != null, 'createServer() requires reporter'); const serverOptions = Object.assign({}, options); 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'); return new Server(serverOptions); }