chore: display bundle size table at end of build-all-examples script#1037
Conversation
Add --help option, Markdown table and CSV output of bundle sizes for easy copy-paste into PR descriptions and release notes. The example list is inferred dynamically by detecting which packages produce JS bundles in their dist/ directory.
WalkthroughReworked example build script to add usage/help and robust option parsing, discover built JS examples under Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
scripts/build-all-examples.bash (4)
8-16: Consider adding an explicit return statement.SonarCloud flags the missing explicit return. While
echoreturns 0 on success, addingreturn 0improves clarity.Proposed fix
usage() { echo "Usage: $0 [OPTIONS]" echo echo "Build all examples and display bundle sizes." echo echo "Options:" echo " --list-size-only Skip building, only display bundle sizes from existing dist/ directories" echo " --help Show this help message" + return 0 }
46-52: Use[[instead of[for conditional tests.SonarCloud flags this at line 49. The
[[construct is safer (handles word splitting and glob expansion automatically) and more feature-rich in bash.Proposed fix
# Infer examples that produce JS bundles (frontend applications only) EXAMPLES_FOR_TABLE=() for dir in packages/js-example* packages/ts-example*; do - if [ -d "$dir/dist" ] && find "$dir/dist" -name "*.js" -type f -print -quit | grep -q .; then + if [[ -d "$dir/dist" ]] && find "$dir/dist" -name "*.js" -type f -print -quit | grep -q .; then EXAMPLES_FOR_TABLE+=("$(basename "$dir")") fi done
75-85: Use[[instead of[for conditional tests.SonarCloud flags this at line 79. Apply the same fix as suggested for line 49.
Proposed fix
# Collect bundle sizes (largest JS file per example = the one containing maxGraph) declare -A BUNDLE_SIZES for example in "${EXAMPLES_FOR_TABLE[@]}"; do dir="packages/$example" - if [ -d "$dir/dist" ]; then + if [[ -d "$dir/dist" ]]; then BUNDLE_SIZES[$example]=$(find "$dir/dist" -name "*.js" -type f -exec ls -l {} \; | LC_NUMERIC=C awk ' { if ($5 > max) max = $5 } END { printf "%.2f", max / 1000 } ') fi done
87-102: Use[[instead of[for conditional tests.SonarCloud flags this at line 97. Apply the same fix for consistency.
Proposed fix
for example in "${EXAMPLES_FOR_TABLE[@]}"; do size="${BUNDLE_SIZES[$example]:-}" - if [ -n "$size" ]; then + if [[ -n "$size" ]]; then echo "| $example | kB | $size kB |" else echo "| $example | kB | N/A |" fi done
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 289df1c6-d12a-4775-a10f-0fba52fd8f26
📒 Files selected for processing (1)
scripts/build-all-examples.bash
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/build-all-examples.bash (1)
33-40:⚠️ Potential issue | 🟠 MajorBuild loop exits on first failure, preventing the final size table from being printed.
With
set -euo pipefail, a failingnpm run buildaborts the script immediately, skipping all subsequent output (lines 47–122), including the Markdown table and CSV summary that are core to the script's stated purpose.Capture build failures and continue processing to ensure the end-of-run output is always produced:
Proposed fix
+BUILD_FAILED=false for dir in packages/ts-example* packages/js-example*; do if [[ -d "$dir" ]]; then echo echo "##################################################" echo "Building $dir" echo "##################################################" - (cd "$dir" && npm run build) + if ! (cd "$dir" && npm run build); then + echo "Build failed for $dir; continuing with next example." >&2 + BUILD_FAILED=true + fi fi done - echo "All examples built successfully." + if [[ "$BUILD_FAILED" = true ]]; then + echo "One or more example builds failed." >&2 + else + echo "All examples built successfully." + fi fi # Infer examples that produce JS bundles (frontend applications only) @@ -120,3 +130,7 @@ for i in "${!EXAMPLES_FOR_TABLE[@]}"; do done echo "$csv_header" echo "$csv_values" + +if [[ "${BUILD_FAILED:-false}" = true ]]; then + exit 1 +fi
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 248a4237-33f8-442f-b002-cc8c42a84768
📒 Files selected for processing (2)
.github/workflows/build.ymlscripts/build-all-examples.bash
🚧 Files skipped from review as they are similar to previous changes (1)
- .github/workflows/build.yml



Add --help option, Markdown table and CSV output of bundle sizes for easy copy-paste into PR descriptions and release notes.
The example list is inferred dynamically by detecting which packages produce JS bundles in their dist/ directory.
Summary by CodeRabbit
New Features
Chores