Skip to content

Commit

Permalink
CI: no deps bundle size check (commaai#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
signed-long authored Jul 13, 2024
1 parent 84d1b82 commit 95a5fce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ jobs:
- uses: oven-sh/setup-bun@v1

- run: bun install --frozen-lockfile
- run: bun vite-bundle-visualizer -o ./bundle-visualizer.html
- run: bun run build --sourcemap true
- name: Bundle size breakdown
run: node src/ci/dependency_report.cjs dist/ | column -t -s ":"
- run: ./check-bundle-size.sh

- name: Upload Bundle Visualizer
uses: actions/upload-artifact@v4
with:
path: ./bundle-visualizer.html
overwrite: true
retention-days: 1
name: bundle-visualizer-${{ github.run_id }}

- name: Upload built project
uses: actions/upload-artifact@v4
with:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
10 changes: 2 additions & 8 deletions check-bundle-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $DIR

bun vite-bundle-visualizer -t list -o ./bundle.yaml

BUNDLE_SIZE=0
gzip_values=$(yq eval '.[][]["gzip"]' bundle.yaml)
for gzip_value in $gzip_values; do
BUNDLE_SIZE=$((BUNDLE_SIZE + gzip_value / 1024))
done

gzip -r -9 dist
BUNDLE_SIZE=$(du -sk dist | cut -f1)
echo "Bundle size is $BUNDLE_SIZE K"

if [ $BUNDLE_SIZE -gt 500 ]; then
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.0",
"vite": "^5.2.13",
"vite-bundle-visualizer": "^1.2.1",
"vite-plugin-solid": "^2.10.2",
"vitest": "^1.6.0",
"wrangler": "^3.60.2"
Expand Down
22 changes: 22 additions & 0 deletions src/ci/dependency_report.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
const fs = require('fs');

const bundle = process.argv[2];
const dir = bundle + "/assets/";
const extension = ".map";
const mapFiles = fs.readdirSync(dir).filter(fn => fn.endsWith(extension));

report = [];
for (const mapFile of mapFiles) {
var mapFileData = JSON.parse(fs.readFileSync(dir + mapFile, 'utf8'));
assetFile = mapFile.replace(extension, "");
sources = mapFileData.sources.filter(source => source.includes("node_modules")).map(source => source.split("node_modules/")[1]);
report.push({ "asset": assetFile, "size": fs.statSync(dir + assetFile).size, "sources": sources});
fs.unlinkSync(dir + mapFile);
}
report.sort((b, a) => a.size - b.size).forEach(entry => {
console.log(entry.asset + ":" + (entry.size / 1024).toFixed(2) + "KB");
for (const source of entry.sources) {
console.log(" " + source);
}
});

0 comments on commit 95a5fce

Please sign in to comment.