New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bun run --workspace
#2232
Comments
Thanks for reporting, we were talking about implementing this the other day. We'll do it |
Is this planned for the near future? this might be the one thing preventing us from migrating from pnpm to bun as without it we would have to do the Really I want support for the |
For bun as a drop-in replacement, it would really help to have |
As a an alternative workaround,
Would be nice to be able to reference a workspace based on the package name, ie: On top of this it'd be great to have wildcards: |
bun run
does not support --workspace
argbun run --workspace
and bun run --workspaces
bun run --workspace
and bun run --workspaces
bun run --workspace
any updates on this? |
It will be great if
|
Bump, it's a bummer that such a great tool doesn't have this feature. |
+1 on this. Would be useful to be able to do something like this. I'm actually currently using the What I'm doingThere's a Root package.json and an apps/server/package.json (a Workspace).
{
// ./package.json (In Root of monorepo) | NOTICE HOW IT JUST RUNS PACKAGE.JSON SCRIPTS WITH BUN
"scripts": {
"server:dev": "bun run --cwd apps/server dev",
"db:start": "bun run --cwd apps/server db:start",
"db:stop": "bun run --cwd apps/server db:stop",
"migrate:status": "bun run --cwd apps/server migrate:status",
"migrate:create": "bun run --cwd apps/server migrate:create",
"migrate:up": "bun run --cwd apps/server migrate:up",
"migrate:down": "bun run --cwd apps/server migrate:down"
},
} {
// apps/server/package.json
"name": "server",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "bun run --watch src/index.ts",
"db:start": "docker-compose up -d --build",
"db:stop": "docker-compose stop",
"migrate:create": "sh scripts/migrate-create.sh src/database/migrations",
"migrate:status": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL status",
"migrate:up": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL up",
"migrate:down": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL down",
"seed": "bun run scripts/seed.ts"
}
} 1 thing to watch out for:When you have migration scripts that use
Why? I'm actually not completely sure why. But it does come up when I use the "root" version of the script. It works properly when I use the "apps/server" (workspace) version of the script. I almost ruled it out as a Bun workspace issue. But actually the culprit is dotenv-cli. Solution for this
"migrate:create": "sh scripts/migrate-create.sh src/database/migrations",
- "migrate:status": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL status",
- "migrate:up": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL up",
- "migrate:down": "dotenv -- goose -dir src/database/migrations postgres $DATABASE_URL down", Changed to: "migrate:create": "sh scripts/migrate-create.sh src/database/migrations",
+ "_migrate:status": "goose -dir src/database/migrations postgres $DATABASE_URL status",
+ "migrate:status": "dotenv -- bun run _migrate:status",
+ "_migrate:up": "goose -dir src/database/migrations postgres $DATABASE_URL up",
+ "migrate:up": "dotenv -- bun run _migrate:up",
+ "_migrate:down": "goose -dir src/database/migrations postgres $DATABASE_URL down",
"migrate:down": "dotenv -- bun run _migrate:down", I'll just leave these comments here for anyone attempting to do the same thing with Bun. |
Is there complexity involved in shipping this feature out? |
For now we are using moonrepo with full bun integration to be the task runner. |
I'd like to propose additional helpers for bun workspaces:
|
For those like me stumbling into this nowadays, I'm following this recommendation by @cs-clarence on #5350 to use Thinkmill/manypkg by adding it and this script to my root {
"name": "my-project",
"private": true,
"scripts": {
"pkg": "manypkg run"
},
"workspaces": [
"apps/*",
"packages/*"
],
"devDependencies": {
"@manypkg/cli": "^0.21.3"
}
} With this we can just |
Bun v1.1.4 adds support for The equivalent of bun --filter="my-workspace-pkg" my-script-name To run the bun run --filter="*util*" build We'll have a page for this in bun.sh/docs later today Fixed in #8185 |
Bro, it's literally a drop-in replacement for running commands in a workspace, if you want to do just that you can. But it also has so much more potential. |
@johnnybenson this is not a new api, anyone that used workspaces with pnpm will be familiar with |
The exit code for this features seems to always be 0. Should it exit 1 if any of the commands returns an error? |
I've tried to test this today using canary ( I've took a look to the docs and the Could anyone confirm if this is already available on canary? |
@wesleycoder , I'm on 1.1.4 as well, and this message ( The filter feature supports calling a script within the workspace. I needed to execute a command in a workspace but it's not supported yet so I opened a new issue. |
I've tested with a Github Codespaces machine on this minimal repository Neither of these works: curl -fsSL https://bun.sh/install | bash
source /home/codespace/.bashrc
bun --version # 1.1.4
bun run --filter 'a' test
# error: No packages matched the filter
bun --filter 'a' test
# >>> Installed to the root package instead of installing to `packages/a`
bun upgrade --canary
bun --version # 1.1.4
bun run --filter 'a' test # same results
bun --filter 'a' test # same results Now I believe it's not an issue on my machine and it's definitely broken, so I've open another issue: #10367 |
What version of Bun is running?
0.5.7
What platform is your computer?
Darwin 22.3.0 arm64 arm
What steps can reproduce the bug?
In a monorepo with npm workspaces, scripts defined in a specific package's
package.json
can be run withWhat is the expected behavior?
Bun should allow me to run the package's script via the
--workspace
arg.A possible workaround is:
(cd packages/my-package && bun run my-script)
What do you see instead?
error: missing script "my-script"
Additional information
No response
The text was updated successfully, but these errors were encountered: