Skip to content

Commit

Permalink
Allow passing depth 'all' for detailedReport option
Browse files Browse the repository at this point in the history
  • Loading branch information
garthenweb committed Jan 2, 2019
1 parent f054ef9 commit cfe442d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 1 addition & 5 deletions packages/core/parcel-bundler/src/cli.js
Expand Up @@ -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 <level>',
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 11 additions & 7 deletions packages/core/parcel-bundler/src/utils/bundleReport.js
Expand Up @@ -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
Expand All @@ -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([
Expand Down

0 comments on commit cfe442d

Please sign in to comment.