Skip to content

Size Guard Pro

The size-guard command scans the workspace for files that exceed a configurable size threshold. This prevents accidentally committing large binary assets (images, fonts, videos) that bloat the repository.

Usage

bash
# Check with default 500KB threshold
dart run monorepo_toolkit size-guard check

# Custom threshold
dart run monorepo_toolkit size-guard check --threshold 1MB

# Show detailed scan statistics
dart run monorepo_toolkit size-guard check --stats

# Add extra file extensions to scan
dart run monorepo_toolkit size-guard check -e psd -e ai

# Ignore specific paths
dart run monorepo_toolkit size-guard check -i "assets/legacy"

Flags

FlagAbbrDefaultDescription
--threshold-t500KBSize threshold (e.g., 500KB, 1MB, 2GB)
--extension-esee belowAdditional file extensions to check
--ignore-isee belowAdditional paths to ignore
--config-csize_guard.yamlPath to YAML config file
--stats-sfalseShow detailed statistics (total files scanned, total bytes)

The command exits with code 1 if any files exceed the threshold, making it suitable for CI gate checks.

Default extensions

The following extensions are scanned by default: png, jpg, jpeg, gif, webp, bmp, ico, svg, ttf, otf, woff, woff2, mp3, mp4, wav, avi, mov, webm, pdf, zip, tar, gz, rar, json, db, sqlite.

Default ignore paths

These directories are skipped: .git, .dart_tool, .idea, .vscode, build, node_modules, .fvm, .pub-cache, .gradle, ios/Pods, android/.gradle, coverage.

Configuration

Create a size_guard.yaml at the workspace root:

yaml
size_guard:
  threshold: "1MB"

  extensions:
    - png
    - jpg
    - svg
    - ttf
    - mp4

  ignore_paths:
    - .git
    - build
    - node_modules

  ignore_patterns:
    - "**/test/fixtures/**"
    - "**/golden/**"

Command-line flags are merged with (not replacing) the config file values for extensions and ignore paths.

CI integration

yaml
steps:
  - name: Check asset sizes
    run: dart run monorepo_toolkit size-guard check --stats

When to use this

Use size-guard in CI to prevent large assets from being committed. Common scenarios:

  • A designer adds an unoptimized 5MB PNG to the assets folder
  • A test fixture contains a large video file that should be in external storage
  • Font files exceed expected sizes after a design system update

Built by Banua Coder