Skip to content

fix(npx): execute unknown targets via npx, not npm (#1495)#1527

Closed
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1495
Closed

fix(npx): execute unknown targets via npx, not npm (#1495)#1527
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1495

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Problem

rtk npx <unknown_binary> (e.g. npx oxlint) failed with npm ERR! Missing script: \"<binary>\" instead of running the binary.

Root cause

src/main.rs Commands::Npx fallback called npm_cmd::run(&args, ...). npm_cmd::run invokes npm and (when args don't match a known npm subcommand) injects run, turning rtk npx oxlint into npm run oxlint. Any binary not declared as a package.json script broke.

Fix

Replace the npm_cmd::run fallback with a proper npx passthrough — the same pattern already used a few lines above for npx prisma <unknown>:

let timer = core::tracking::TimedExecution::start();
let mut cmd = core::utils::resolved_command(\"npx\");
for arg in &args { cmd.arg(arg); }
let status = cmd.status().context(\"Failed to run npx\")?;
let args_str = args.join(\" \");
timer.track_passthrough(
    &format!(\"npx {}\", args_str),
    &format!(\"rtk npx {} (passthrough)\", args_str),
);
core::utils::exit_code_from_status(&status, \"npx\")

This restores correct binary-lookup semantics (npx) instead of script-lookup (npm), keeps tracking visible in rtk gain --history, and propagates the child exit code.

Test plan

  • Added regression test `test_try_parse_npx_oxlint_routes_to_npx_command` confirming the dispatcher entrypoint stays correct.
  • `cargo test --all` → 1682 passed, 0 failed.
  • `cargo fmt --all` clean.
  • Manually verified post-fix: `rtk npx oxlint --version` → `Version: 1.61.0` (npx auto-installed and ran the binary). Pre-fix it produced `npm ERR! Missing script: "oxlint"`.
  • No behavior change for specialized targets (`npx tsc`, `npx eslint`, `npx prisma`, `npx next`, `npx prettier`, `npx playwright`) — only the catch-all fallback changed.

Closes #1495

The `Commands::Npx` fallback in main.rs delegated to `npm_cmd::run`, which
runs the binary through `npm`. For any target without a matching
`package.json` script entry (e.g. `oxlint`, third-party CLIs), `npm` injects
`run` and fails with "Missing script: <target>". Users invoking
`npx oxlint --fix` saw their lint runs broken because the rewrite
turned a binary-lookup into a script-lookup.

Fix: replace the `npm_cmd::run` fallback with a proper `npx` passthrough
that mirrors the existing `npx prisma` fallback at the same call site —
spawn `npx` directly, propagate the exit code, and record the invocation
via `track_passthrough` so it still appears in `rtk gain --history`.

Also add a parser-level regression test ensuring `npx oxlint --fix src/`
routes through `Commands::Npx` (the dispatcher entrypoint that now leads
to the corrected fallback).

Closes rtk-ai#1495

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Apr 25, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes the rtk npx <unknown_binary> command which was incorrectly routing unknown targets through npm_cmd::run (script lookup) instead of npx (binary lookup), causing errors like "Missing script" for binaries not declared in package.json. The fix replaces the fallback with a direct npx passthrough, matching the pattern already used for specialized targets like npx prisma.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1495


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@KuSh
Copy link
Copy Markdown
Collaborator

KuSh commented Apr 26, 2026

Closing as #1458 already took care of the problem

@KuSh KuSh closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants