Affected Package Detection Enterprise
The affected command detects which workspace packages are impacted by git changes and runs commands only on those packages. This dramatically speeds up CI pipelines by skipping unchanged packages.
Usage
bash
# List affected packages
dart run monorepo_toolkit affected list
# Run analysis on affected packages only
dart run monorepo_toolkit affected analyze
# Run tests on affected packages only
dart run monorepo_toolkit affected test --coverage
# Run any command on affected packages
dart run monorepo_toolkit affected run -- "dart format --set-exit-if-changed ."Subcommands
affected list
Lists packages affected by git changes compared to a base branch:
bash
dart run monorepo_toolkit affected list --base develop
dart run monorepo_toolkit affected list --format plain # CI-friendly output| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--format | -f | pretty | Output format: pretty or plain |
affected analyze
Runs flutter analyze lib on affected packages:
bash
dart run monorepo_toolkit affected analyze --base develop
dart run monorepo_toolkit affected analyze --no-fail-fast| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--fail-fast | true | Stop on first package failure |
affected test
Runs flutter test on affected packages with optional coverage collection:
bash
dart run monorepo_toolkit affected test --coverage --base develop| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--coverage | false | Collect coverage information | |
--fail-fast | true | Stop on first package failure |
affected run
Runs an arbitrary command on affected packages:
bash
dart run monorepo_toolkit affected run -- "flutter test --coverage"
dart run monorepo_toolkit affected run -- "dart format --set-exit-if-changed ."| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--fail-fast | true | Stop on first package failure |
Configuration
Create an affected.yaml at the workspace root:
yaml
affected:
base_branch: develop
# Predefined commands (merged with defaults: analyze, test, format)
commands:
lint: "dart run custom_lints ."
# Packages always included regardless of changes
always_include:
- template_app
# Glob patterns to ignore when detecting changes
ignore:
- "devtools/**"
- ".github/**"
- ".claude/**"The default ignore patterns are devtools/**, .github/**, and .claude/**. The default predefined commands are analyze (flutter analyze lib), test (flutter test), and format (dart format --set-exit-if-changed .).
CI integration
yaml
steps:
- name: Analyze affected packages
run: dart run monorepo_toolkit affected analyze --base origin/develop
- name: Test affected packages
run: dart run monorepo_toolkit affected test --coverage --base origin/develop