From a14d323340ac493f83ceb209a945e27e324bac51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=86=A0=E8=BE=B0?= Date: Thu, 21 May 2026 08:45:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(discover):=20rewrite=20bunx=20prisma=20?= =?UTF-8?q?=E2=86=92=20rtk=20prisma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bun is now the primary JS runtime on a growing share of Prisma projects. `bunx prisma ` is semantically equivalent to `npx prisma ` — same CLI, same output format, same subcommands — but the hook didn't recognise it, so 45+ monthly invocations per reporter were flowing through the Bash hook completely unfiltered. Add `bunx` to the existing Prisma `RtkRule`: - Regex pattern: insert `|bunx` into the runner alternation so `bunx prisma …` classifies as `Supported(rtk prisma)`. - `rewrite_prefixes`: add `"bunx prisma"` so the rewrite path produces `rtk prisma …` and main.rs's filter dispatch picks up the existing `src/cmds/js/prisma_cmd.rs` handler unchanged. No new output-filtering logic is needed — the entire Bun-Prisma stack goes through the same code path as npx/pnpm/npm; only the rewrite recognition was missing. Tests: - Extend `test_classify_prisma` and `test_rewrite_prisma` with `bunx prisma` so the same per-runner invariant fence guards bun. - Add `test_rewrite_bunx_prisma_subcommands` covering the six surface shapes the reporter calls out (`migrate dev`, `migrate dev --name …`, `migrate deploy`, `migrate status`, `generate`, `db seed`, `studio`). Pins the regex against a future tweak that silently drops one shape. cargo fmt / clippy --all-targets / test --bin rtk: 1910 passed, 0 warnings. Fixes #1401 --- src/discover/registry.rs | 30 ++++++++++++++++++++++++++++++ src/discover/rules.rs | 7 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/discover/registry.rs b/src/discover/registry.rs index bb7b11f2a..9a14d718e 100644 --- a/src/discover/registry.rs +++ b/src/discover/registry.rs @@ -2851,6 +2851,7 @@ mod tests { "npx prisma", "pnpm prisma", "pnpx prisma", + "bunx prisma", "prisma", ]; for command in commands { @@ -2885,6 +2886,7 @@ mod tests { "npx prisma", "pnpm prisma", "pnpx prisma", + "bunx prisma", "prisma", ]; for command in commands { @@ -2897,6 +2899,34 @@ mod tests { } } + #[test] + fn test_rewrite_bunx_prisma_subcommands() { + // #1401: exercise the full Prisma surface that the reporter said hits + // unfiltered with bun. The classify_command/rewrite tests above already + // cover `migrate dev` for every runner; this nails down each subcommand + // shape verbatim so a future regex tweak doesn't silently drop one. + let cases = [ + ("bunx prisma migrate dev", "rtk prisma migrate dev"), + ( + "bunx prisma migrate dev --name add_col", + "rtk prisma migrate dev --name add_col", + ), + ("bunx prisma migrate deploy", "rtk prisma migrate deploy"), + ("bunx prisma migrate status", "rtk prisma migrate status"), + ("bunx prisma generate", "rtk prisma generate"), + ("bunx prisma db seed", "rtk prisma db seed"), + ("bunx prisma studio", "rtk prisma studio"), + ]; + for (input, expected) in cases { + assert_eq!( + rewrite_command_no_prefixes(input, &[]), + Some(expected.into()), + "Failed for input: {}", + input + ); + } + } + #[test] fn test_rewrite_prettier() { let commands = vec![ diff --git a/src/discover/rules.rs b/src/discover/rules.rs index df7c72d03..ce3b20165 100644 --- a/src/discover/rules.rs +++ b/src/discover/rules.rs @@ -346,10 +346,15 @@ pub const RULES: &[RtkRule] = &[ subcmd_savings: &[], subcmd_status: &[], }, + // #1401: Bun is now the primary JS runtime on a growing share of Prisma + // projects. `bunx prisma ` is semantically equivalent to + // `npx prisma ` (same CLI, same output format), so it routes through + // the same `rtk prisma` filter — no new output-handling logic required. RtkRule { - pattern: r"^((p?np(m|x)|p?npm\s+(exec|run|run-script)|npm\s+(rum|urn|x)|pnpm\s+dlx)\s+)?prisma", + pattern: r"^((p?np(m|x)|p?npm\s+(exec|run|run-script)|npm\s+(rum|urn|x)|pnpm\s+dlx|bunx)\s+)?prisma", rtk_cmd: "rtk prisma", rewrite_prefixes: &[ + "bunx prisma", "npm exec prisma", "npm prisma", "npm rum prisma",