Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ concurrency:
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: latest
- run: npm ci
- name: Build and summarize bundle size
run: npm run build -- --summary

test:
runs-on: ubuntu-latest
steps:
Expand Down
35 changes: 34 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

const path = require('node:path');
const { appendFileSync } = require('node:fs');
const { buildSync } = require('esbuild');

buildSync({
const { metafile } = buildSync({
entryPoints: [path.join(__dirname, '..', 'index.js')],
outfile: path.join(__dirname, '..', 'dist', 'microtel.js'),
bundle: true,
metafile: true,
platform: 'node',
format: 'cjs',
// Function and class names stay observable, as in the unbundled source.
Expand All @@ -16,3 +18,34 @@ buildSync({
charset: 'ascii',
logLevel: 'warning',
});

if (process.argv.includes('--summary')) {
const formatSize = (bytes) => {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 ** 2) return `${(bytes / 1024).toFixed(2)} KiB`;
return `${(bytes / 1024 ** 2).toFixed(2)} MiB`;
};
const summary = ['## Build size', ''];
for (const [file, output] of Object.entries(metafile.outputs)) {
summary.push(
`### ${file}: ${formatSize(output.bytes)}`,
'',
'| Input | Size in bundle | Share of bundle |',
'| --- | ---: | ---: |',
);
for (const [input, { bytesInOutput }] of Object.entries(output.inputs).sort(
(a, b) => b[1].bytesInOutput - a[1].bytesInOutput,
)) {
summary.push(
`| ${input} | ${formatSize(bytesInOutput)} | ${((bytesInOutput / output.bytes) * 100).toFixed(2)}% |`,
);
}
summary.push('');
}
const report = summary.join('\n');
if (process.env.GITHUB_STEP_SUMMARY) {
appendFileSync(process.env.GITHUB_STEP_SUMMARY, report);
} else {
process.stdout.write(report);
}
}
Loading