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:
# 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| Flag | Description |
|---|---|
--dry-run / -n | Show what would be done without making changes |
--fix-resolution / -r | Add resolution: workspace to packages missing it (default: on) |
--force / -f | Force rescan all packages |
What it does
The setup command performs three operations:
Scan: Finds all Dart/Flutter packages in the monorepo by looking for
pubspec.yamlfiles inapps/,shared/,infrastructure/,features/,packages/,utilities/, anddevtools/directories.Update workspace list: Adds new packages to the
workspacefield in the rootpubspec.yamland 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 packagesFix resolution: Ensures each package's
pubspec.yamlincludesresolution: 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 getat 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
melos run workspace:setup # Set up workspace configuration