mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## Summary This PR implements the `--workspaces` flag for the `bun run` command, allowing scripts to be run in all workspace packages as defined in the `"workspaces"` field in package.json. Fixes the infinite loop issue reported in https://github.com/threepointone/bun-workspace-bug-repro ## Changes - Added `--workspaces` flag to run scripts in all workspace packages - Added `--if-present` flag to gracefully skip packages without the script - Root package is excluded when using `--workspaces` to prevent infinite recursion - Added comprehensive tests for the new functionality ## Usage ```bash # Run "test" script in all workspace packages bun run --workspaces test # Skip packages that don't have the script bun run --workspaces --if-present build # Combine with filters bun run --filter="@scope/*" test ``` ## Behavior The `--workspaces` flag must come **before** the script name (matching npm's behavior): - ✅ `bun run --workspaces test` - ❌ `bun run test --workspaces` (treated as passthrough to script) ## Test Plan - [x] Added test cases in `test/cli/run/workspaces.test.ts` - [x] Verified fix for infinite loop issue in https://github.com/threepointone/bun-workspace-bug-repro - [x] Tested with `--if-present` flag - [x] All tests pass locally 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>