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',
outdated_modules: outdated.size,
}));
this._reporter.update({
type: 'bundle_update_existing',
entryFilePath: options.entryFile,
outdatedModuleCount: outdated.size,
});
debug('Attempt to update existing bundle');

View File

@ -27,6 +27,7 @@ type BundleProgress = {
transformedFileCount: number,
totalFileCount: number,
ratio: number,
outdatedModuleCount: number,
};
const DARK_BLOCK_CHAR = '\u2593';
@ -82,14 +83,22 @@ class TerminalReporter {
*
*/
_getFileTransformMessage(
{totalFileCount, transformedFileCount, ratio}: BundleProgress,
{totalFileCount, transformedFileCount, ratio, outdatedModuleCount}: BundleProgress,
build: 'in_progress' | 'done',
): string {
if (build === 'done' && totalFileCount === 0) {
return 'All files are already up-to-date.';
if (outdatedModuleCount > 0) {
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(
'Transforming files %s%s% (%s/%s)%s',
'Transforming modules %s%s% (%s/%s)%s',
build === 'done' ? '' : getProgressBar(ratio, 30) + ' ',
(100 * ratio).toFixed(1),
transformedFileCount,
@ -174,9 +183,23 @@ class TerminalReporter {
ratio,
transformedFileCount,
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.
* No logging or status updates should be done at this point.
@ -188,14 +211,23 @@ class TerminalReporter {
transformedFileCount: 0,
totalFileCount: 0,
ratio: 0,
outdatedModuleCount: 0,
});
break;
case 'bundle_transform_progressed':
if (event.totalFileCount === event.transformedFileCount) {
this._scheduleUpdateBundleProgress.cancel();
this._updateBundleProgress(event);
} else {
this._scheduleUpdateBundleProgress(event);
}
break;
case 'bundle_transform_progressed_throttled':
this._updateBundleProgress(event);
break;
case 'bundle_update_existing':
this._updateBundleOutdatedModuleCount(event);
break;
case 'bundle_built':
this._activeBundles.delete(event.entryFilePath);
break;

View File

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