From b559412a081e740e7bc3cc3fcac2e115fa42cdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Jim=C3=A9nez=20Es=C3=BAn?= Date: Mon, 12 Jun 2017 10:50:53 -0700 Subject: [PATCH] Pass bundle options to the reporter to provide additional information Reviewed By: jeanlauliac Differential Revision: D5172384 fbshipit-source-id: f2e4cf677f8113060b257ddec6b585870786a336 --- .../metro-bundler/src/Bundler/BundleBase.js | 2 +- packages/metro-bundler/src/Server/index.js | 7 ++----- .../metro-bundler/src/lib/TerminalReporter.js | 19 ++++++++++++++----- packages/metro-bundler/src/lib/reporting.js | 3 ++- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/metro-bundler/src/Bundler/BundleBase.js b/packages/metro-bundler/src/Bundler/BundleBase.js index 5ddd966d..e99665f3 100644 --- a/packages/metro-bundler/src/Bundler/BundleBase.js +++ b/packages/metro-bundler/src/Bundler/BundleBase.js @@ -50,7 +50,7 @@ class BundleBase { this._mainModuleId = moduleId; } - addModule(module: ModuleTransport) { + addModule(module: ModuleTransport): number { if (!(module instanceof ModuleTransport)) { throw new Error('Expected a ModuleTransport object'); } diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index d06153a5..f086df2c 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -268,7 +268,6 @@ class Server { dependencyPairs: new Map( nonVirtual .filter(({meta}) => meta && meta.dependencyPairs) - /* $FlowFixMe: the filter above ensures `dependencyPairs` is not null. */ .map(m => [m.sourcePath, m.meta.dependencyPairs]) ), outdated: new Set(), @@ -496,12 +495,12 @@ class Server { */ _reportBundlePromise( buildID: string, - options: {entryFile: string}, + options: BundleOptions, bundlePromise: Promise, ): Promise { this._reporter.update({ buildID, - entryFilePath: options.entryFile, + bundleOptions: options, type: 'bundle_build_started', }); return bundlePromise.then(bundle => { @@ -586,7 +585,6 @@ class Server { const moduleTransport = newModules[i]; const {meta, sourcePath} = moduleTransport; if (outdated.has(sourcePath)) { - /* $FlowFixMe: `meta` could be empty */ if (!contentsEqual(meta.dependencies, new Set(files.get(sourcePath)))) { // bail out if any dependencies changed return Promise.reject(Error( @@ -594,7 +592,6 @@ class Server { /* $FlowFixMe: `get` can return empty */ files.get(sourcePath).join(', ') }] to [${ - /* $FlowFixMe: `meta` could be empty */ meta.dependencies.join(', ') }]` )); diff --git a/packages/metro-bundler/src/lib/TerminalReporter.js b/packages/metro-bundler/src/lib/TerminalReporter.js index 987d937f..5dae8054 100644 --- a/packages/metro-bundler/src/lib/TerminalReporter.js +++ b/packages/metro-bundler/src/lib/TerminalReporter.js @@ -18,6 +18,7 @@ const reporting = require('./reporting'); const throttle = require('lodash/throttle'); const util = require('util'); +import type {BundleOptions} from '../Server'; import type Terminal from './Terminal'; import type {ReportableEvent, GlobalCacheDisabledReason} from './reporting'; @@ -26,7 +27,7 @@ const GLOBAL_CACHE_DISABLED_MESSAGE_FORMAT = 'The global cache is now disabled because %s'; type BundleProgress = { - entryFilePath: string, + bundleOptions: BundleOptions, transformedFileCount: number, totalFileCount: number, ratio: number, @@ -90,18 +91,26 @@ class TerminalReporter { * Bunding `foo.js` |#### | 34.2% (324/945) */ _getBundleStatusMessage( - {entryFilePath, totalFileCount, transformedFileCount, ratio}: BundleProgress, + { + bundleOptions, + transformedFileCount, + totalFileCount, + ratio, + }: BundleProgress, phase: BuildPhase, ): string { - const localPath = path.relative('.', entryFilePath); + const localPath = path.relative('.', bundleOptions.entryFile); return util.format( - 'Bundling `%s` %s%s% (%s/%s)%s', + 'Bundling `%s` %s%s% (%s/%s)%s %s, %s, %s', localPath, phase === 'in_progress' ? getProgressBar(ratio, 16) + ' ' : '', (100 * ratio).toFixed(1), transformedFileCount, totalFileCount, phase === 'done' ? ', done.' : (phase === 'failed' ? ', failed.' : ''), + bundleOptions.dev ? 'development' : 'production', + bundleOptions.minify ? 'minified' : 'non-minified', + bundleOptions.hot ? 'hmr enabled' : 'hmr disabled', ); } @@ -292,7 +301,7 @@ class TerminalReporter { break; case 'bundle_build_started': this._activeBundles.set(event.buildID, { - entryFilePath: event.entryFilePath, + bundleOptions: event.bundleOptions, transformedFileCount: 0, totalFileCount: 1, ratio: 0, diff --git a/packages/metro-bundler/src/lib/reporting.js b/packages/metro-bundler/src/lib/reporting.js index 82ff82e0..13135427 100644 --- a/packages/metro-bundler/src/lib/reporting.js +++ b/packages/metro-bundler/src/lib/reporting.js @@ -14,6 +14,7 @@ const chalk = require('chalk'); const util = require('util'); +import type {BundleOptions} from '../Server'; import type Terminal from './Terminal'; export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses'; @@ -40,7 +41,7 @@ export type ReportableEvent = { type: 'bundle_build_failed', } | { buildID: string, - entryFilePath: string, + bundleOptions: BundleOptions, type: 'bundle_build_started', } | { error: Error,