Pass bundle options to the reporter to provide additional information

Reviewed By: jeanlauliac

Differential Revision: D5172384

fbshipit-source-id: f2e4cf677f8113060b257ddec6b585870786a336
This commit is contained in:
Miguel Jiménez Esún 2017-06-12 10:50:53 -07:00 committed by Facebook Github Bot
parent 573d9edfd0
commit b559412a08
4 changed files with 19 additions and 12 deletions

View File

@ -50,7 +50,7 @@ class BundleBase {
this._mainModuleId = moduleId; this._mainModuleId = moduleId;
} }
addModule(module: ModuleTransport) { addModule(module: ModuleTransport): number {
if (!(module instanceof ModuleTransport)) { if (!(module instanceof ModuleTransport)) {
throw new Error('Expected a ModuleTransport object'); throw new Error('Expected a ModuleTransport object');
} }

View File

@ -268,7 +268,6 @@ class Server {
dependencyPairs: new Map( dependencyPairs: new Map(
nonVirtual nonVirtual
.filter(({meta}) => meta && meta.dependencyPairs) .filter(({meta}) => meta && meta.dependencyPairs)
/* $FlowFixMe: the filter above ensures `dependencyPairs` is not null. */
.map(m => [m.sourcePath, m.meta.dependencyPairs]) .map(m => [m.sourcePath, m.meta.dependencyPairs])
), ),
outdated: new Set(), outdated: new Set(),
@ -496,12 +495,12 @@ class Server {
*/ */
_reportBundlePromise( _reportBundlePromise(
buildID: string, buildID: string,
options: {entryFile: string}, options: BundleOptions,
bundlePromise: Promise<Bundle>, bundlePromise: Promise<Bundle>,
): Promise<Bundle> { ): Promise<Bundle> {
this._reporter.update({ this._reporter.update({
buildID, buildID,
entryFilePath: options.entryFile, bundleOptions: options,
type: 'bundle_build_started', type: 'bundle_build_started',
}); });
return bundlePromise.then(bundle => { return bundlePromise.then(bundle => {
@ -586,7 +585,6 @@ class Server {
const moduleTransport = newModules[i]; const moduleTransport = newModules[i];
const {meta, sourcePath} = moduleTransport; const {meta, sourcePath} = moduleTransport;
if (outdated.has(sourcePath)) { if (outdated.has(sourcePath)) {
/* $FlowFixMe: `meta` could be empty */
if (!contentsEqual(meta.dependencies, new Set(files.get(sourcePath)))) { if (!contentsEqual(meta.dependencies, new Set(files.get(sourcePath)))) {
// bail out if any dependencies changed // bail out if any dependencies changed
return Promise.reject(Error( return Promise.reject(Error(
@ -594,7 +592,6 @@ class Server {
/* $FlowFixMe: `get` can return empty */ /* $FlowFixMe: `get` can return empty */
files.get(sourcePath).join(', ') files.get(sourcePath).join(', ')
}] to [${ }] to [${
/* $FlowFixMe: `meta` could be empty */
meta.dependencies.join(', ') meta.dependencies.join(', ')
}]` }]`
)); ));

View File

@ -18,6 +18,7 @@ const reporting = require('./reporting');
const throttle = require('lodash/throttle'); const throttle = require('lodash/throttle');
const util = require('util'); const util = require('util');
import type {BundleOptions} from '../Server';
import type Terminal from './Terminal'; import type Terminal from './Terminal';
import type {ReportableEvent, GlobalCacheDisabledReason} from './reporting'; import type {ReportableEvent, GlobalCacheDisabledReason} from './reporting';
@ -26,7 +27,7 @@ const GLOBAL_CACHE_DISABLED_MESSAGE_FORMAT =
'The global cache is now disabled because %s'; 'The global cache is now disabled because %s';
type BundleProgress = { type BundleProgress = {
entryFilePath: string, bundleOptions: BundleOptions,
transformedFileCount: number, transformedFileCount: number,
totalFileCount: number, totalFileCount: number,
ratio: number, ratio: number,
@ -90,18 +91,26 @@ class TerminalReporter {
* Bunding `foo.js` |#### | 34.2% (324/945) * Bunding `foo.js` |#### | 34.2% (324/945)
*/ */
_getBundleStatusMessage( _getBundleStatusMessage(
{entryFilePath, totalFileCount, transformedFileCount, ratio}: BundleProgress, {
bundleOptions,
transformedFileCount,
totalFileCount,
ratio,
}: BundleProgress,
phase: BuildPhase, phase: BuildPhase,
): string { ): string {
const localPath = path.relative('.', entryFilePath); const localPath = path.relative('.', bundleOptions.entryFile);
return util.format( return util.format(
'Bundling `%s` %s%s% (%s/%s)%s', 'Bundling `%s` %s%s% (%s/%s)%s %s, %s, %s',
localPath, localPath,
phase === 'in_progress' ? getProgressBar(ratio, 16) + ' ' : '', phase === 'in_progress' ? getProgressBar(ratio, 16) + ' ' : '',
(100 * ratio).toFixed(1), (100 * ratio).toFixed(1),
transformedFileCount, transformedFileCount,
totalFileCount, totalFileCount,
phase === 'done' ? ', done.' : (phase === 'failed' ? ', failed.' : ''), 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; break;
case 'bundle_build_started': case 'bundle_build_started':
this._activeBundles.set(event.buildID, { this._activeBundles.set(event.buildID, {
entryFilePath: event.entryFilePath, bundleOptions: event.bundleOptions,
transformedFileCount: 0, transformedFileCount: 0,
totalFileCount: 1, totalFileCount: 1,
ratio: 0, ratio: 0,

View File

@ -14,6 +14,7 @@
const chalk = require('chalk'); const chalk = require('chalk');
const util = require('util'); const util = require('util');
import type {BundleOptions} from '../Server';
import type Terminal from './Terminal'; import type Terminal from './Terminal';
export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses'; export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses';
@ -40,7 +41,7 @@ export type ReportableEvent = {
type: 'bundle_build_failed', type: 'bundle_build_failed',
} | { } | {
buildID: string, buildID: string,
entryFilePath: string, bundleOptions: BundleOptions,
type: 'bundle_build_started', type: 'bundle_build_started',
} | { } | {
error: Error, error: Error,