packager: TerminalReporter: properly reporting bundle updates

Reviewed By: cpojer

Differential Revision: D4357298

fbshipit-source-id: 89c70bb4bee103ad5a6301ac2b0c8712f190ba73
This commit is contained in:
Jean Lauliac 2016-12-21 05:52:15 -08:00 committed by Facebook Github Bot
parent 04fdf40c61
commit 3d12ddb1db
3 changed files with 46 additions and 5 deletions

View File

@ -577,6 +577,11 @@ class Server {
action_name: 'Updating existing bundle', action_name: 'Updating existing bundle',
outdated_modules: outdated.size, outdated_modules: outdated.size,
})); }));
this._reporter.update({
type: 'bundle_update_existing',
entryFilePath: options.entryFile,
outdatedModuleCount: outdated.size,
});
debug('Attempt to update existing bundle'); debug('Attempt to update existing bundle');

View File

@ -27,6 +27,7 @@ type BundleProgress = {
transformedFileCount: number, transformedFileCount: number,
totalFileCount: number, totalFileCount: number,
ratio: number, ratio: number,
outdatedModuleCount: number,
}; };
const DARK_BLOCK_CHAR = '\u2593'; const DARK_BLOCK_CHAR = '\u2593';
@ -82,14 +83,22 @@ class TerminalReporter {
* *
*/ */
_getFileTransformMessage( _getFileTransformMessage(
{totalFileCount, transformedFileCount, ratio}: BundleProgress, {totalFileCount, transformedFileCount, ratio, outdatedModuleCount}: BundleProgress,
build: 'in_progress' | 'done', build: 'in_progress' | 'done',
): string { ): string {
if (build === 'done' && totalFileCount === 0) { if (outdatedModuleCount > 0) {
return 'All files are already up-to-date.'; const plural = outdatedModuleCount > 1;
return `Updating ${outdatedModuleCount} ` +
`module${plural ? 's' : ''} in place` +
(build === 'done' ? ', done' : '...');
}
if (totalFileCount === 0) {
return build === 'done'
? 'No module changed.'
: 'Analysing...';
} }
return util.format( return util.format(
'Transforming files %s%s% (%s/%s)%s', 'Transforming modules %s%s% (%s/%s)%s',
build === 'done' ? '' : getProgressBar(ratio, 30) + ' ', build === 'done' ? '' : getProgressBar(ratio, 30) + ' ',
(100 * ratio).toFixed(1), (100 * ratio).toFixed(1),
transformedFileCount, transformedFileCount,
@ -174,9 +183,23 @@ class TerminalReporter {
ratio, ratio,
transformedFileCount, transformedFileCount,
totalFileCount, totalFileCount,
outdatedModuleCount: 0,
}); });
} }
_updateBundleOutdatedModuleCount(
{entryFilePath, outdatedModuleCount}: {
entryFilePath: string,
outdatedModuleCount: number,
},
) {
const currentProgress = this._activeBundles.get(entryFilePath);
if (currentProgress == null) {
return;
}
currentProgress.outdatedModuleCount = outdatedModuleCount;
}
/** /**
* This function is exclusively concerned with updating the internal state. * This function is exclusively concerned with updating the internal state.
* No logging or status updates should be done at this point. * No logging or status updates should be done at this point.
@ -188,14 +211,23 @@ class TerminalReporter {
transformedFileCount: 0, transformedFileCount: 0,
totalFileCount: 0, totalFileCount: 0,
ratio: 0, ratio: 0,
outdatedModuleCount: 0,
}); });
break; break;
case 'bundle_transform_progressed': case 'bundle_transform_progressed':
if (event.totalFileCount === event.transformedFileCount) {
this._scheduleUpdateBundleProgress.cancel();
this._updateBundleProgress(event);
} else {
this._scheduleUpdateBundleProgress(event); this._scheduleUpdateBundleProgress(event);
}
break; break;
case 'bundle_transform_progressed_throttled': case 'bundle_transform_progressed_throttled':
this._updateBundleProgress(event); this._updateBundleProgress(event);
break; break;
case 'bundle_update_existing':
this._updateBundleOutdatedModuleCount(event);
break;
case 'bundle_built': case 'bundle_built':
this._activeBundles.delete(event.entryFilePath); this._activeBundles.delete(event.entryFilePath);
break; break;

View File

@ -34,6 +34,10 @@ export type ReportableEvent = {
entryFilePath: string, entryFilePath: string,
transformedFileCount: number, transformedFileCount: number,
totalFileCount: number, totalFileCount: number,
} | {
entryFilePath: string,
outdatedModuleCount: number,
type: 'bundle_update_existing',
} | { } | {
type: 'bundle_built', type: 'bundle_built',
entryFilePath: string, entryFilePath: string,