veza/tmt/tests/frontend/bundle_size.sh

35 lines
957 B
Bash
Raw Normal View History

#!/bin/bash
set -e
# CONTRACT: docs/BUDGETS.md
# DO NOT CHANGE THESE VALUES WITHOUT UPDATING THE CONTRACT FIRST.
MAX_TOTAL_SIZE_KB=5000 # 5MB
MAX_JS_ENTRY_KB=800 # 800KB
REPO_ROOT=$(git rev-parse --show-toplevel)
WEB_DIR="$REPO_ROOT/apps/web"
DIST_DIR="$WEB_DIR/dist"
echo "📍 Frontend Bundle Size Check (Strict)"
echo "📜 Contract: docs/BUDGETS.md"
if [ ! -d "$DIST_DIR" ]; then
echo "❌ Dist directory not found. Run build first."
exit 1
fi
# Calculate total size
TOTAL_SIZE_KB=$(du -sk "$DIST_DIR" | cut -f1)
echo "📊 Total Bundle Size: ${TOTAL_SIZE_KB}KB"
echo " Invariant Limit: ${MAX_TOTAL_SIZE_KB}KB"
if [ "$TOTAL_SIZE_KB" -gt "$MAX_TOTAL_SIZE_KB" ]; then
echo "❌ FATAL: OBESITY DETECTED."
echo " The bundle exceeds the hard limit set in the Frugality Manifesto."
echo " You must reduce the size or initiate a formal debate to change the limit."
exit 1
fi
echo "✅ Bundle adheres to strict diet."