Repository navigation
refactor(vis-core): split resolve.rs and type the package manager - #245
Conversation
resolve.rs held eleven resolvers, their option structs and the shared yarn scoping helpers in one 1800-line file. Move each verb into resolve/<verb>.rs (install, add, remove, exec, dlx, why, outdated, link with unlink, dedupe, pm_command), mirroring src/pm/pm-runner.ts, and keep ResolvedCommand, validate_pm and the yarn workspace/foreach helpers in resolve/mod.rs. The public paths are unchanged (`vis_core::resolve::*`) and each verb's tests moved with it. No behaviour change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every resolver spelled out one `if opts.x { args.push("--x".into()); }`
block per flag and a four-line loop per repeated `--filter`/`--workspace`.
Add `push_flags(&mut args, &[(opts.x, "--x"), ..])` and
`push_each(&mut args, "--filter", &opts.filter)` and use them wherever two
or more flags follow each other. The flag order is unchanged.
No behaviour change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The resolvers took the manager as a string plus a version and re-derived
the same facts on every call: validate_pm up front, a `match pm` with an
`unreachable!()` arm for the names validate_pm had already let through,
and ten copies of `version.starts_with("1.")` to tell yarn classic from
berry. Build a `Manager` (Pnpm, Npm, YarnClassic, YarnBerry, Bun) once
from (pm, version) and match on it, so each arm is a manager and the
classic/berry split is a pair of arms. The `1.` rule is unchanged, so a
yarn.lock-header version of `1.x` still reads as classic and an unknown
version as berry. The public `resolve_*(pm, version, ..)` signatures and
every message are unchanged.
No behaviour change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The resolvers returned `Result<_, String>`, so a caller could not tell an unsupported package manager from a refused flag, and the addon's comment claimed every core error was the former although `yarn workspace` with several filters and the `vis exec` flag refusals also return one. Add `ResolveError` (unsupported package manager, yarn single workspace, dropped exec flags, unsupported --reverse). Its `Display` is the exact message of each old string, which the CLI prints after `vis <command>:` and the addon raises as an `InvalidArg` error, so what users see is unchanged. Correct the comment on the addon's `invalid_arg`. No behaviour change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
OutdatedOptions.format was a String compared against "json" and "list" in two resolvers, with every other value silently meaning "no format flag". Make it an `OutdatedFormat` (Table, Json, List). `OutdatedFormat::parse` keeps the old reading: any value other than `json` and `list` is Table, which adds no flag, so the CLI's default of `table` and an unknown `--format` value resolve as before. The addon's option object still takes a string and parses it. No behaviour change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tion detect.rs matched the four manager names inline in three places although `pm_name` already maps them, walked up the lockfiles and the config files with two copies of the same pop loop (and a third in the pin lookup), and built a DetectedPackageManager literal in five places. Use `pm_name` everywhere, one `walk_up` that returns the directory of the hit, and one `detected` builder. `Path::ancestors` visits the same directories as the old pop loop, including the empty root of a relative path; a test pins it. The core options now take plain bools (`ignore_package_json`, `ignore_lock_file`, `ignore_argv`) instead of the addon's `Option<bool>`, and the addon's wrapper turns an omitted flag into false, so the addon's option object and the detection order are unchanged. No behaviour change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The addon wrapped its progress callback in a Bridge struct holding an Arc<Mutex<Option<ThreadsafeFunction>>> just to implement IngestProgress, which already has a blanket impl for any `FnMut(usize, usize) + Send`. A threadsafe function is Send, so a closure over it does the same without the lock. No behaviour change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoRefactor vis-core resolution into typed, per-verb modules
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent |
|
Thank you for following the naming conventions! 🙏 |
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
ⓘ Qodo did not review this PR because this workspace reached its daily trial limit of 100 reviews. Reviews start again at 00:00 UTC. Choose a plan to continue now. |
What
Splits
vis-core'sresolve.rsinto one module per verb and replaces the string-typed package manager, error and format with types. Based onnext(not on #243: the two PRs touch disjoint files). No behaviour change: argv,bin, warnings and error text are the same for every input I could enumerate (see below). The napi surface is unchanged.Old -> new
core/src/resolve.rs(1806 lines, ten resolvers)core/src/resolve/mod.rs(ResolvedCommand,Manager,ResolveError,push_flags,push_each,yarn_workspace_prefix,yarn_foreach_prefix) plusinstall,add,remove,exec,dlx,why,outdated,link(withunlink),dedupe,pm_command, mirroringsrc/pm/pm-runner.ts. The 41 unit tests moved with their verb. Public paths and theresolve_*(pm, version, ..)signatures are unchanged.if opts.x { args.push("--x".into()) }block per flag, a four-line loop per--filterpush_flags(&mut args, &[(opts.x, "--x"), ..]),push_each(&mut args, "--filter", &opts.filter)pm: &str+validate_pm, ninematch pm { .. _ => unreachable!() }, tenversion.starts_with("1.")enum Manager { Pnpm, Npm, YarnClassic, YarnBerry, Bun }, built once byManager::new(pm, version); each verb matches the five variants. The1.rule is unchanged, so the1.xthat detection reports for a classicyarn.lockheader still reads as classic and an unknown version as berry.Result<_, String>ResolveError(unsupported manager, yarn single workspace, dropped exec flags, unsupported--reverse);Displayis the old text. The addon'sinvalid_argcomment, which said every core error was an unsupported-manager failure, is corrected.OutdatedOptions.format: StringOutdatedFormat { Table, Json, List }with an infallibleparse: anything butjsonandlistisTable, which adds no flag, as beforedetect.rs: the four names matched inline in three places, two copies of the pop loop plus a third in the pin lookup, fiveDetectedPackageManagerliterals,Option<bool>optionspm_nameeverywhere, onewalk_up(returns the directory of the hit), onedetectedbuilder, plainbooloptions (the addon's wrapper turns an omitted flag intofalse)advisories_napi.rs: aBridgestruct overArc<Mutex<Option<ThreadsafeFunction>>>IngestProgressis implemented for anyFnMut(usize, usize) + Send)Differences found
None in behaviour. Things I checked or left on purpose:
pnpm,npm,yarn,bun,denoand an empty name, the versions"",1,1.x,1.22.0,4.0.0,10.1.0,11.0.0,latestand01.2, every combination of the boolean options, and zero, one and two filters plus the package, argument, target, depth, format and subcommand variants of each verb. It compared argv,bin, warnings and the error text, and passed after each commit. It is not committed..to_string()on it; nothing else in the moved tests changed.detect.rsgains one test forwalk_up(the directory of the hit, and the empty root of a relative path, which the oldpoploop also visited).pnpm build:native:debugbefore and after the change produces a byte-identicalindex.d.tsandindex.js; no generated file is committed.next, so not touched: the dead non-bun global arms inresolve_addandresolve_remove,--reverse(mapped for pnpm, refused elsewhere), the inline foreach prefix in yarn berry exec, and the if-chain inresolve_pm_command(already onematch; the fourbun pm <verb>arms stay as they read well). Not done by design: making aube aManagervariant, an optionalnapifeature onvis-core, and theALLOWED_BINSlist inpm_exec.rs.What ran locally
cargo fmt --check,cargo clippy -p vis-core -p vis-cli --all-targets -- -D warningsandcargo clippy -p vis-native -- -D warnings: clean.cargo test -p vis-core -p vis-cli: all pass (63 invis-core, 480 in the binary, 60 cli, 18 hook, 28 node_parity, 3 golden, 1 routing).FORCE_COLOR=3, against a releasevis-native-cli, the rebuilt addon and the built Node entry:route,routing-fixture,native-binding,pm-runner,pm-pin,pm-exec-x,install-native,sbom-parity,optimize-parity,install-parity,add-parity(1 test skipped in the file),info-dlx-parity,advisories-ingest-progressandadvisory-db-schema: 14 files, 3065 passed, 1 skipped.🤖 Generated with Claude Code