Repository navigation
Conversation
|
Hey @guyoron1 Root-cause concern: the logic injects run for any unrecognized first arg, which makes NPM_SUBCOMMANDS a fail dangerous denylist. Issue is the default "run" prefix. The self-maintaining fix: only inject run when the first arg is an actual script in the nearest package.json (walking up like npm does); otherwise pass through. Should cause no regression keep your list additions: their job becomes builtin-precedence (so a query/sbom script can't shadow the real subcommand). We can merge this but this is just a patch that does not fix the root issue. |
|
Great review, thank you! |
| } | ||
|
|
||
| fn args(strs: &[&str]) -> Vec<String> { | ||
| strs.iter().map(|s| s.to_string()).collect() |
There was a problem hiding this comment.
More idiomatic:
strs.iter().map(String::from).collect()| if is_run_explicit || is_npm_subcommand { | ||
| effective_args.extend_from_slice(args); | ||
| } else { | ||
| // "rtk npm build" → "npm run build" (assume script name) | ||
| effective_args.push("run".to_string()); | ||
| effective_args.extend_from_slice(args); | ||
| } |
There was a problem hiding this comment.
This could be simplified:
if !(is_run_explicit || is_npm_subcommand) {
effective_args.push("run".to_string());
}
effective_args.extend_from_slice(args);|
Heyaaaa :) thanks for the review!! Pushed a fix that addresses both points:
Also refactored the tests to call the actual production function ( |
| // Only inject "run" when args look like a script name, not a known npm subcommand. | ||
| /// Build the effective npm args, injecting "run" when the first arg looks | ||
| /// like a script name rather than a known npm subcommand or flag. | ||
| fn build_effective_npm_args(args: &[String]) -> Vec<String> { |
There was a problem hiding this comment.
But this is still guessing, right?
Not actually walking up to the nearest package.json and extracting script keys like npm does.
Maybe something like this:
let script_names: Vec<String> = env::current_dir()
.ok()
.and_then(|p| p.ancestors().map(|a| a.join("package.json")).find(|f| f.exists()))
.and_then(|f| File::open(f).ok())
.and_then(|f| serde_json::from_reader(f).ok())
.and_then(|v| v.get("scripts")?.as_object().map(|m| m.keys().cloned().collect()))
.unwrap_or_default();There was a problem hiding this comment.
Heyaaaa! Thanks for the review :)
Yes, it's still heuristic-based — the subcommand list covers npm's built-in commands, so anything not in the list gets run injected. Walking package.json for script keys would be more accurate but adds I/O on every invocation and complexity around monorepos / workspaces. Happy to explore that as a follow-up if there's appetite for it.
|
What's the source for NPM_SUBCOMMANDS? When I diff it against All commands
NPM_SUBCOMMANDS
(and i t aliases). |
6c7f526 to
72e3bb7
Compare
|
Hey @guyoron1 same update as for #2776 This is related to issues #2663 and #2094Two related PR that both address a temporary fix :
The issue is at a higher level, and maintaining those hard coded lists is not a correct solution. Proposed fix :
This fixes both issues at the root, removes both lists (no more chasing npm versions or package-manager forms), and keeps every exit code faithful. #2776 currently drops pnpm lint to raw with no filter (0% savings), running it verbatim and filtering the output preserves the gain. |
…tion Fixes rtk-ai#2663 Official npm subcommands like `query`, `sbom`, `completion`, `edit`, `explore`, `find-dupes`, `help-search`, `hook`, `install-ci-test`, `install-test`, `ll`, `org`, `run-script`, `shrinkwrap`, and `unstar` were missing from NPM_SUBCOMMANDS. Running any of these through RTK would incorrectly inject `run`, e.g. `npm query` became `npm run query`. Verified against `npm help` output (npm 10.8.2). Added regression test for hyphenated subcommands which are the most likely to be missed.
- Extract `build_effective_npm_args()` so tests exercise the actual production function instead of reimplementing the logic locally - Add 11 missing npm short aliases (add, x, ln, un, r, s, se, rb, ddp, it, cit) that were causing incorrect `run` injection - Add explicit `npm run` test (no double injection) - Remove redundant `test_hyphenated_subcommands_no_run_injection` (already covered by iterating all NPM_SUBCOMMANDS)
- Add 6 npm 11 commands: approve-scripts, deny-scripts, run, stage, trust, undeprecate - Sort NPM_SUBCOMMANDS alphabetically with clear sections: primary commands, npm-10 aliases kept for compat, short aliases - Add test_npm11_commands_no_run_injection for new commands - Document source as union of `npm help` across npm 10 and 11
72e3bb7 to
c86c241
Compare
|
Closing this in favour of #2860. The 15 subcommands here landed separately in #3087, and the aliases I added afterwards ( Thanks @aeppling and @reneleonhardt for pushing this towards the root cause. |
Summary
Fixes #2663
NPM_SUBCOMMANDSlistrun(e.g.npm query→npm run query→ fails)find-dupes,help-search, etc.)Missing subcommands added:
completion,edit,explore,find-dupes,help-search,hook,install-ci-test,install-test,ll,org,query,run-script,sbom,shrinkwrap,unstarVerified against
npm helpoutput (npm 10.8.2).Test plan
test_hyphenated_subcommands_no_run_injectioncovers compound subcommandscargo fmt && cargo clippy --all-targets && cargo test --allclean