mirror of https://github.com/status-im/metro.git
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:
parent
573d9edfd0
commit
b559412a08
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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<Bundle>,
|
||||
): Promise<Bundle> {
|
||||
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(', ')
|
||||
}]`
|
||||
));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue