Expand description
The shared detection probe: presence + version + provenance.
This generalises bynkc’s old tool_exists (which shelled the POSIX
which and conceded it was Unix-only). Detection is backed by the which
crate, which handles PATHEXT/where on Windows, so a user-facing
environment check tells the truth on every platform (v0.46 portability
decision).
Lookups go through a Toolbox so the capability/exit matrix and the
output goldens can run against a deterministic fake instead of the host.
Structs§
- Detect
Opts - How a detection should look: where to search, and whether
npxfetch-on-demand counts as a (provisionable) fallback.nodeitself is neverallow_npx— you cannotnpxa runtime. - Probe
- One detection result: a tool, its version (if installed and it reports one), and where it came from.
- System
Toolbox - The real host:
which-crate lookups and a--versionshell-out. - Version
- A parsed tool version. Missing components default to zero, so
"v18"parses as18.0.0and compares sensibly against a major-version floor.
Enums§
- Provenance
- Where a tool was found — the provenance half of a probe. The distinction
between
Provenance::Path/Provenance::ProjectLocal(installed) andProvenance::Npx(fetchable on demand) is the whole point:npx --yeswill download a package at first use, so it must never read as a green “ok”.
Traits§
- Toolbox
- Abstraction over the host so detection is testable. The real implementation
is
SystemToolbox; tests supply a deterministic fake.
Functions§
- detect
- Detect a single tool: project-local first (it wins over a global install),
then
PATH, then — only ifallow_npx— annpxprovisionable fallback, else missing.