1#!/usr/bin/env bash
2set -euo pipefail
3
4# Runs the CI bundle-size comparison locally (see the Bundle job in
5# .github/workflows/check.yml): builds the current checkout, builds the base
6# ref in a cached git worktree under tmp/, then compares fixture bundle sizes.
7#
8# Usage: scripts/bundle-compare.sh [base-ref] (default: main)
9#
10# The base worktree is reused across runs while it points at the same commit.
11# Remove it with: git worktree remove --force tmp/bundle-base
12
13BASE_REF="${1:-main}"
14ROOT="$(git rev-parse --show-toplevel)"
15BASE_DIR="$ROOT/tmp/bundle-base"
16OUTPUT_PATH="$ROOT/tmp/bundle-stats.txt"
17
18cd "$ROOT"
19
20echo "Building current checkout..."
21pnpm build
22
23BASE_COMMIT="$(git rev-parse "$BASE_REF")"
24
25if [ -d "$BASE_DIR/packages/effect/dist" ] && [ "$(git -C "$BASE_DIR" rev-parse HEAD)" = "$BASE_COMMIT" ]; then
26 echo "Reusing built base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
27else
28 if [ -d "$BASE_DIR" ]; then
29 git worktree remove --force "$BASE_DIR"
30 fi
31 echo "Creating base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
32 git worktree add --detach "$BASE_DIR" "$BASE_COMMIT"
33 echo "Building base checkout..."
34 (cd "$BASE_DIR" && pnpm install && pnpm build)
35fi
36
37node packages/tools/bundle/src/bin.ts compare \
38 --base-dir "$BASE_DIR/packages/tools/bundle/fixtures" \
39 --output-path "$OUTPUT_PATH"
40
41echo
42cat "$OUTPUT_PATH"