Repository navigation
run: add npm's --workspace flag and use it for a script's npm run -w
#46401
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,7 +222,12 @@ pub fn replace_package_manager_run( | |
| } | ||
| b'p' => { | ||
| if delimiter > 0 { | ||
| if strings::has_prefix_comptime(&script[start..], b"pnpm run ") { | ||
| // pnpm's `-w` is `--workspace-root`. `bun run` has npm's `-w`, which takes a value. | ||
| if strings::has_prefix_comptime(&script[start..], b"pnpm run ") | ||
| && !strings::tokenize_any(&script[start + b"pnpm run ".len()..], b" \t") | ||
| .take_while(|word| word[0] == b'-') | ||
| .any(|word| word == b"-w") | ||
| { | ||
|
Comment on lines
+225
to
+230
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟣 pre-existing, not blocking: nit, pre-existing: a script line Why this was flaggedA package.json script reads Verification: pre-existing. Triggering condition: a package.json script that reads |
||
| append_bun_run(copy_script); | ||
| copy_script.push(b' '); | ||
| entry_i += b"pnpm run ".len(); | ||
|
|
@@ -269,8 +274,9 @@ fn append_npm_run_in_workspaces(out: &mut Vec<u8>, args: &[u8]) -> usize { | |
| let mut selects_workspaces = false; | ||
| let mut tokens = strings::tokenize_any(command, b" \t"); | ||
| while let Some(token) = tokens.next() { | ||
| let workspace = match token { | ||
| b"-w" | b"--workspace" => tokens.next(), | ||
| // The `=` stays: a shell expands `-w={a,b}` to two flags, and `-w {a,b}` to a value and a script name. | ||
| let (workspace, separator): (Option<&[u8]>, &[u8]) = match token { | ||
| b"-w" | b"--workspace" => (tokens.next(), b" "), | ||
| b"--workspaces" | b"--ws" => { | ||
|
Comment on lines
+278
to
280
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟣 pre-existing, not blocking: pre-existing: a script line Why this was flaggedA package.json script such as "start": "npm run build -ws" (npm documents -ws as the alias of --workspaces) is run with Verification: pre-existing — triggered when a package.json script contains |
||
| selects_workspaces = true; | ||
| flags.extend_from_slice(b" --workspaces"); | ||
|
|
@@ -291,7 +297,7 @@ fn append_npm_run_in_workspaces(out: &mut Vec<u8>, args: &[u8]) -> usize { | |
| .strip_prefix(b"--workspace=") | ||
| .or_else(|| token.strip_prefix(b"-w=")) | ||
| { | ||
| Some(workspace) => Some(workspace), | ||
| Some(workspace) => (Some(workspace), b"="), | ||
| None => { | ||
| rest.push(b' '); | ||
| rest.extend_from_slice(token); | ||
|
|
@@ -308,12 +314,9 @@ fn append_npm_run_in_workspaces(out: &mut Vec<u8>, args: &[u8]) -> usize { | |
| return 0; | ||
| }; | ||
| selects_workspaces = true; | ||
| flags.extend_from_slice(b" --filter="); | ||
| // npm also accepts the workspace's folder. `--filter` tells a path from a name by the | ||
| // leading dot. | ||
| if strings::contains_char(workspace, b'/') && !matches!(workspace[0], b'@' | b'.' | b'/') { | ||
| flags.extend_from_slice(b"./"); | ||
| } | ||
| // The short flag: a `bun` in `PATH` from before the flag refuses `-w`, but skips `--workspace` and runs this package's script. | ||
| flags.extend_from_slice(b" -w"); | ||
|
Comment on lines
+317
to
+318
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Scripts containing Why this was flaggedA package.json script reads Verification: src/install/lifecycle_script_runner.rs:318-320 now emits |
||
| flags.extend_from_slice(separator); | ||
| flags.extend_from_slice(workspace); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep
pnpm run --workspace-rootunchanged.If a script uses
pnpm run --workspace-root build, this check misses pnpm’s long form of-w. The command becomesbun run --workspace-root build, although Bun does not provide pnpm’s workspace-root option. Check both spellings before rewriting. Add the long form to the passthrough test. (pnpm.io)🤖 Prompt for AI Agents