Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions scripts/compare-package-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,50 @@ function has_local_origin_main() {
}

function generate_report(files, pr, main) {
let md = `
### 📦 Bundle size comparison
const rows = files.map(file => {
const d = delta(pr[file].no, main[file].no);

| Name | Size | Gzip | Brotli | Δ |
|------|-----:|-----:|-------:|---|
`;
return [
path.basename(file),
format_delta(pr[file].no, main[file].no),
format_delta(pr[file].gz, main[file].gz),
format_delta(pr[file].br, main[file].br),
icon(d)
];
});

const headers = ["Name", "Size", "Gzip", "Brotli", "Δ"];
const all_rows = [headers, ...rows];
const column_widths = headers.map((_, i) => Math.max(...all_rows.map(r => r[i].length)));

function format_separator() {
return `|${column_widths.map(format_column).join("|")}|`;

function format_column(w, i)
{
const width = w + 2;
return i === 0
? ":" + "-".repeat(width - 1)
: "-".repeat(width - 1) + ":";
}
}

for (const file of files) {
const d = delta(pr[file].no, main[file].no);
function format_row(row) {
return `| ${row.map(format_column).join(" | ")} |`;

function format_column(cell, i) {
const width = column_widths[i];
return i === 0 ? cell.padEnd(width) : cell.padStart(width);
}
}

let md = "\n### 📦 Bundle size comparison\n\n";

const no_diff = format_delta(pr[file].no, main[file].no);
const gz_diff = format_delta(pr[file].gz, main[file].gz);
const br_diff = format_delta(pr[file].br, main[file].br);
md += format_row(headers) + "\n";
md += format_separator() + "\n";

md += `| ${path.basename(file)} | ${no_diff} | ${gz_diff} | ${br_diff} | ${icon(d)} |\n`;
for (const row of rows) {
md += format_row(row) + "\n";
}

console.log(md);
Expand Down