Skip to content

Commit da0c9c0

Browse files
chore: format bundle size report
1 parent f84df64 commit da0c9c0

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

.github/workflows/bundle-size-comment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Bundle Size Comment
22

33
on:
44
workflow_run:
5-
workflows: ["Bundle Size"]
5+
workflows: ['Bundle Size']
66
types: [completed]
77

88
permissions:
@@ -49,7 +49,7 @@ jobs:
4949
id: find
5050
with:
5151
issue-number: ${{ steps.pr.outputs.number }}
52-
body-includes: "<!-- bundle-size-comment -->"
52+
body-includes: '<!-- bundle-size-comment -->'
5353

5454
- name: Create or update comment
5555
uses: peter-evans/create-or-update-comment@v4

scripts/bundle-size-report.mjs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
// Measure: node scripts/bundle-size-report.mjs --output sizes.json [--packages-dir packages]
55
// Compare: node scripts/bundle-size-report.mjs --compare base.json --current current.json --output stats.txt
66

7-
import { readFileSync, writeFileSync, readdirSync, statSync, existsSync } from 'fs';
7+
import {
8+
readFileSync,
9+
writeFileSync,
10+
readdirSync,
11+
statSync,
12+
existsSync,
13+
} from 'fs';
814
import { join, resolve, relative } from 'path';
915
import { gzipSync } from 'zlib';
1016

@@ -88,7 +94,10 @@ function findEsmEntry(pkgDir) {
8894
const dot = pkg.exports['.'];
8995
const importPath = typeof dot === 'string' ? dot : dot.import;
9096
if (importPath) {
91-
const entry = typeof importPath === 'string' ? importPath : importPath.default || importPath;
97+
const entry =
98+
typeof importPath === 'string'
99+
? importPath
100+
: importPath.default || importPath;
92101
if (typeof entry === 'string') {
93102
const resolved = join(pkgDir, entry);
94103
if (existsSync(resolved)) return resolved;
@@ -183,7 +192,10 @@ function measure(packagesDir) {
183192
// ── Compare ──────────────────────────────────────────────────────────────────
184193

185194
function compare(baseData, currentData) {
186-
const allPackages = new Set([...Object.keys(baseData), ...Object.keys(currentData)]);
195+
const allPackages = new Set([
196+
...Object.keys(baseData),
197+
...Object.keys(currentData),
198+
]);
187199
const changed = [];
188200
let unchangedCount = 0;
189201
let totalDistBase = 0;
@@ -219,7 +231,9 @@ function compare(baseData, currentData) {
219231
lines.push('No bundle size changes detected.');
220232
lines.push('');
221233
} else {
222-
lines.push(`${changed.length} package(s) changed, ${unchangedCount} unchanged.`);
234+
lines.push(
235+
`${changed.length} package(s) changed, ${unchangedCount} unchanged.`,
236+
);
223237
lines.push('');
224238
lines.push('| Package | Total dist | Delta | ESM gzip | Delta |');
225239
lines.push('|---------|-----------|-------|----------|-------|');
@@ -242,8 +256,12 @@ function compare(baseData, currentData) {
242256
lines.push('');
243257
}
244258

245-
lines.push(`**Total dist:** ${formatBytes(totalDistCurrent)} (${formatDelta(totalDistCurrent, totalDistBase)})`);
246-
lines.push(`**Total ESM gzip:** ${formatBytes(totalEsmCurrent)} (${formatDelta(totalEsmCurrent, totalEsmBase)})`);
259+
lines.push(
260+
`**Total dist:** ${formatBytes(totalDistCurrent)} (${formatDelta(totalDistCurrent, totalDistBase)})`,
261+
);
262+
lines.push(
263+
`**Total ESM gzip:** ${formatBytes(totalEsmCurrent)} (${formatDelta(totalEsmCurrent, totalEsmBase)})`,
264+
);
247265
lines.push('');
248266

249267
return lines.join('\n');
@@ -294,9 +312,13 @@ function main() {
294312
for (const [name, data] of Object.entries(results)) {
295313
totalDist += data.totalDist;
296314
totalEsm += data.esmGzip;
297-
console.log(` ${name}: dist=${formatBytes(data.totalDist)}, esm-gzip=${formatBytes(data.esmGzip)}`);
315+
console.log(
316+
` ${name}: dist=${formatBytes(data.totalDist)}, esm-gzip=${formatBytes(data.esmGzip)}`,
317+
);
298318
}
299-
console.log(`Total dist: ${formatBytes(totalDist)}, Total ESM gzip: ${formatBytes(totalEsm)}`);
319+
console.log(
320+
`Total dist: ${formatBytes(totalDist)}, Total ESM gzip: ${formatBytes(totalEsm)}`,
321+
);
300322
}
301323
}
302324

0 commit comments

Comments
 (0)