Skip to content

Workspace Setup

The workspace command manages Dart workspace configuration in the monorepo. It scans for all packages, updates the root pubspec.yaml workspace list, and ensures each package has resolution: workspace set.

Subcommands

workspace setup

Scans the monorepo for all Dart/Flutter packages and synchronizes the workspace configuration:

bash
# Full setup
dart run monorepo_toolkit workspace setup

# Preview changes without modifying files
dart run monorepo_toolkit workspace setup --dry-run

# Force rescan all packages
dart run monorepo_toolkit workspace setup --force

# Skip adding resolution: workspace to packages
dart run monorepo_toolkit workspace setup --no-fix-resolution
FlagDescription
--dry-run / -nShow what would be done without making changes
--fix-resolution / -rAdd resolution: workspace to packages missing it (default: on)
--force / -fForce rescan all packages

What it does

The setup command performs three operations:

  1. Scan: Finds all Dart/Flutter packages in the monorepo by looking for pubspec.yaml files in apps/, shared/, infrastructure/, features/, packages/, utilities/, and devtools/ directories.

  2. Update workspace list: Adds new packages to the workspace field in the root pubspec.yaml and removes entries for packages that no longer exist:

    yaml
    # Root pubspec.yaml
    name: template_base
    environment:
      sdk: ^3.7.0
    
    workspace:
      - apps/template_app
      - shared/app_config
      - shared/feature_sdk
      - infrastructure/monitoring_impl
      - features/auth/auth_api
      - features/auth/auth_impl
      # ... all other packages
  3. Fix resolution: Ensures each package's pubspec.yaml includes resolution: workspace, which enables Dart workspace dependency resolution:

    yaml
    # Individual package pubspec.yaml
    name: auth_impl
    resolution: workspace

Dart workspace resolution

Dart workspaces allow all packages in a monorepo to share a single .dart_tool/package_config.json for dependency resolution. This means:

  • A single dart pub get at the root resolves all packages
  • Consistent dependency versions across the entire workspace
  • Faster resolution compared to per-package dart pub get

The resolution: workspace field in each package's pubspec.yaml tells Dart to use the workspace root for resolution instead of resolving independently.

When to run

Run workspace setup when you:

  • Add a new package to the monorepo
  • Remove a package from the monorepo
  • Clone the repository for the first time
  • Notice missing packages in workspace resolution

Melos shortcuts

bash
melos run workspace:setup   # Set up workspace configuration

Built by Banua Coder