Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement depth option for detaild report #2466

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/parcel-bundler/src/cli.js
Expand Up @@ -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]+|all)$/
)
.option(
'--log-level <level>',
Expand Down Expand Up @@ -214,6 +215,7 @@ async function bundle(main, command) {

command.throwErrors = false;
command.scopeHoist = command.experimentalScopeHoisting || false;

const bundler = new Bundler(main, command);

command.target = command.target || 'browser';
Expand Down
15 changes: 11 additions & 4 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,13 +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, NUM_LARGE_ASSETS);
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