Skip to content

fix(npm): leave workspace script invocations with npm - #5276

Open
Aschenbath wants to merge 1 commit into
rtk-ai:developfrom
Aschenbath:fix/oss40-20261124-928f-rtk-npm-workspace
Open

Aschenbath wants to merge 1 commit into
rtk-ai:developfrom
Aschenbath:fix/oss40-20261124-928f-rtk-npm-workspace

Conversation

@Aschenbath

Copy link
Copy Markdown
Contributor

npm run tsc -w backend currently rewrites to rtk tsc -w backend, turning npm's workspace selector into TypeScript's watch flag. Leave workspace script invocations unchanged so npm retains package selection and script execution. Apply the guard before transparent-prefix handling, which otherwise recreates the same problem. Fixes #2098.

Use the shared argument tokenizer for npm's atomic workspace options and run-script aliases, respecting the -- script-argument boundary. Ordinary npm script rewrites remain available. The regression fails on develop with the unwanted rtk tsc -w backend rewrite. It covers all six affected tool families, workspace spellings, aliases, quoting, environment prefixes and configured transparent prefixes.

Validation: root/proxy formatting, clippy and the full test suite passed. Real npm runs in a two-workspace fixture confirmed package selection, quoted paths, aliases and forwarded script arguments. The real Claude hook leaves these workspace commands unchanged and still rewrites ordinary npm run tsc invocations.

Earlier proposal: #2576 (closed). Prepared with Codex assistance.

@itsManeka

Copy link
Copy Markdown

Independent validation of this PR (Windows 11, Git Bash, MSVC toolchain), built from head d7d51293.

Repro on develop (97e68d53): with lint the workspace flag is not dropped, it is forwarded to ESLint. npm run lint -w web rewrites to rtk lint -w web, detect_linter picks ESLint and runs eslint -f json -w web ., so the workspace's lint script never runs. In a two-workspace npm fixture this printed ESLint output (JSON parse failed: EOF while parsing a value at line 1 column 0), while plain npm run lint -w web prints the script output.

With this PR (rtk rewrite, isolated config):

Command develop this PR
npm run lint -w web rtk lint -w web not rewritten
npm run lint -ws rtk lint -ws not rewritten
npm run lint --workspace web rtk lint --workspace web not rewritten
npm run lint --workspace=web rtk lint --workspace=web not rewritten
npm run lint --workspaces rtk lint --workspaces not rewritten
npm run lint -w web -- --fix rtk lint -w web -- --fix not rewritten
npm run-script lint -w web — not rewritten
npm run lint -- -w x — rtk lint -- -w x (script arg, expected)
npm run lint rtk lint rtk lint (unchanged)

In the fixture, npm run lint -w web now runs the workspace script as typed.

Checks on the PR head: cargo fmt --all -- --check and cargo clippy --all-targets -- -D warnings pass. cargo test -p rtk --lib -- --test-threads=1 reports 4861 passed and 1 failed, core::stream::tests::test_read_lines_lossy_preserves_lines_after_invalid_utf8, which also fails on a clean develop on this machine (Windows-specific, unrelated). I did not run proxy/ or tests/.

Minor, optional: test_npm_run_workspace_options_stay_with_npm exercises lint only with -w. The other spellings are covered with tsc, and the guard is script-agnostic, so this is not a behaviour gap.

This also gives #2098 a reproduction for lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook rewrites npm run <script> -w <workspace>, breaking npm's --workspace flag

2 participants