-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (77 loc) · 3.06 KB
/
size.yml
File metadata and controls
92 lines (77 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Bundle Size Check
on:
pull_request:
branches: [main]
jobs:
size:
name: Check Bundle Size
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build library
run: npm run build
- name: Check bundle size
run: |
echo "## Bundle Size Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| File | Size | Gzipped |" >> $GITHUB_STEP_SUMMARY
echo "|------|------|---------|" >> $GITHUB_STEP_SUMMARY
for file in dist/*.js dist/*.cjs; do
if [ -f "$file" ]; then
name=$(basename "$file")
size=$(wc -c < "$file" | awk '{printf "%.2f KB", $1/1024}')
gzip_size=$(gzip -c "$file" | wc -c | awk '{printf "%.2f KB", $1/1024}')
echo "| $name | $size | $gzip_size |" >> $GITHUB_STEP_SUMMARY
fi
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Size Limits" >> $GITHUB_STEP_SUMMARY
echo "- ✅ ESM bundle should be < 50KB (gzipped < 15KB)" >> $GITHUB_STEP_SUMMARY
echo "- ✅ CJS bundle should be < 50KB (gzipped < 15KB)" >> $GITHUB_STEP_SUMMARY
# Check if any file is too large (50KB uncompressed)
for file in dist/index.js dist/index.cjs; do
if [ -f "$file" ]; then
size=$(wc -c < "$file")
if [ $size -gt 51200 ]; then
name=$(basename "$file")
echo "::error::$name is too large: $(($size / 1024)) KB (max 50 KB)"
exit 1
fi
fi
done
- name: Comment PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const fs = require('fs');
const files = ['dist/index.js', 'dist/index.cjs'];
let comment = '## 📦 Bundle Size Report\n\n';
comment += '| File | Size | Gzipped |\n';
comment += '|------|------|---------|\\n';
for (const file of files) {
if (fs.existsSync(file)) {
const stats = fs.statSync(file);
const sizeKB = (stats.size / 1024).toFixed(2);
const { execSync } = require('child_process');
const gzipSize = execSync(`gzip -c ${file} | wc -c`).toString().trim();
const gzipKB = (parseInt(gzipSize) / 1024).toFixed(2);
const name = file.split('/').pop();
comment += `| ${name} | ${sizeKB} KB | ${gzipKB} KB |\\n`;
}
}
comment += '\n✅ All bundles are within size limits!';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});