From f054ef9e5865af07a3e6371d9ffa95ca19ef7de3 Mon Sep 17 00:00:00 2001 From: Jannick Garthen Date: Mon, 24 Dec 2018 16:29:04 +0100 Subject: [PATCH 1/2] Allow passing a depth for detailedReport option --- packages/core/parcel-bundler/src/cli.js | 10 ++++++++-- packages/core/parcel-bundler/src/utils/bundleReport.js | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/parcel-bundler/src/cli.js b/packages/core/parcel-bundler/src/cli.js index 6fd3f2eb098..b101ce85c17 100755 --- a/packages/core/parcel-bundler/src/cli.js +++ b/packages/core/parcel-bundler/src/cli.js @@ -152,8 +152,9 @@ program 'force bundling node modules, even on node/electron target' ) .option( - '--detailed-report', - 'print a detailed build report after a completed build' + '--detailed-report [depth]', + 'print a detailed build report after a completed build. If enabled, defaults to depth "10"', + /^([0-9]+)$/ ) .option( '--log-level ', @@ -214,6 +215,11 @@ async function bundle(main, command) { command.throwErrors = false; command.scopeHoist = command.experimentalScopeHoisting || false; + command.detailedReport = + typeof command.detailedReport === 'string' + ? parseInt(command.detailedReport, 10) + : Boolean(command.detailedReport); + const bundler = new Bundler(main, command); command.target = command.target || 'browser'; diff --git a/packages/core/parcel-bundler/src/utils/bundleReport.js b/packages/core/parcel-bundler/src/utils/bundleReport.js index 141eef19043..2dee98ef5d6 100644 --- a/packages/core/parcel-bundler/src/utils/bundleReport.js +++ b/packages/core/parcel-bundler/src/utils/bundleReport.js @@ -34,7 +34,10 @@ function bundleReport(mainBundle, detailed = false) { .filter(a => a.type === bundle.type) .sort((a, b) => b.bundledSize - a.bundledSize); - let largestAssets = assets.slice(0, NUM_LARGE_ASSETS); + let largestAssets = assets.slice( + 0, + isNaN(detailed) ? NUM_LARGE_ASSETS : detailed + ); for (let asset of largestAssets) { // Add a row for the asset. rows.push([ From cfe442d50517be2dcc40ed0e1f4520d1ab5af562 Mon Sep 17 00:00:00 2001 From: Jannick Garthen Date: Tue, 25 Dec 2018 14:55:42 +0100 Subject: [PATCH 2/2] Allow passing depth 'all' for detailedReport option --- packages/core/parcel-bundler/src/cli.js | 6 +----- .../parcel-bundler/src/utils/bundleReport.js | 18 +++++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/core/parcel-bundler/src/cli.js b/packages/core/parcel-bundler/src/cli.js index b101ce85c17..5f4f5f0953e 100755 --- a/packages/core/parcel-bundler/src/cli.js +++ b/packages/core/parcel-bundler/src/cli.js @@ -154,7 +154,7 @@ program .option( '--detailed-report [depth]', 'print a detailed build report after a completed build. If enabled, defaults to depth "10"', - /^([0-9]+)$/ + /^([0-9]+|all)$/ ) .option( '--log-level ', @@ -215,10 +215,6 @@ async function bundle(main, command) { command.throwErrors = false; command.scopeHoist = command.experimentalScopeHoisting || false; - command.detailedReport = - typeof command.detailedReport === 'string' - ? parseInt(command.detailedReport, 10) - : Boolean(command.detailedReport); const bundler = new Bundler(main, command); diff --git a/packages/core/parcel-bundler/src/utils/bundleReport.js b/packages/core/parcel-bundler/src/utils/bundleReport.js index 2dee98ef5d6..c27369dee77 100644 --- a/packages/core/parcel-bundler/src/utils/bundleReport.js +++ b/packages/core/parcel-bundler/src/utils/bundleReport.js @@ -4,7 +4,7 @@ const logger = require('@parcel/logger'); const filesize = require('filesize'); const LARGE_BUNDLE_SIZE = 1024 * 1024; -const NUM_LARGE_ASSETS = 10; +const DEFAULT_NUM_LARGE_ASSETS = 10; const COLUMNS = [ {align: 'left'}, // name {align: 'right'}, // size @@ -28,16 +28,20 @@ function bundleReport(mainBundle, detailed = false) { logger.chalk.green.bold(prettifyTime(bundle.bundleTime)) ]); - // If detailed, generate a list of the top 10 largest assets in the bundle + // If detailed, generate a list of the largest assets in the bundle if (detailed && bundle.assets.size > 1) { let assets = Array.from(bundle.assets) .filter(a => a.type === bundle.type) .sort((a, b) => b.bundledSize - a.bundledSize); - - let largestAssets = assets.slice( - 0, - isNaN(detailed) ? NUM_LARGE_ASSETS : detailed - ); + let largestAssets = (() => { + if (detailed === 'all') { + return assets; + } + return assets.slice( + 0, + isNaN(detailed) ? DEFAULT_NUM_LARGE_ASSETS : parseInt(detailed, 10) + ); + })(); for (let asset of largestAssets) { // Add a row for the asset. rows.push([