Documentation
¶
Overview ¶
Package pkgmanager detects which package manager (npm, pnpm, Bun, or yarn) a TypeScript project declares, from the worktree or a committed revision, probes the version on PATH, and rejects configuration that would redirect package resolution.
Index ¶
- Constants
- Variables
- func AtRevision(ctx context.Context, dir, revision string, roots []string) (kind, version, origin string)
- func Check(dir string, roots []string, policyPassed bool) projectreadiness.Check
- func Contexts(worktreeRoot string, roots []string) (contexts []string, fellBack bool)
- func DetectPackageManagerHazard(root, kind string) string
- func ProbeVersion(ctx context.Context, kind string) (string, bool)
Constants ¶
const ( KindNPM = "npm" KindPNPM = "pnpm" KindBun = "bun" KindYarn = "yarn" )
Variables ¶
var LockfileBasenames = map[string]string{ "package-lock.json": KindNPM, "pnpm-lock.yaml": KindPNPM, "bun.lock": KindBun, "bun.lockb": KindBun, "yarn.lock": KindYarn, }
LockfileBasenames maps each matrix-recognized lockfile basename to the manager kind it identifies (SA-280-012). Bun has two recognized lockfile variants: the binary bun.lockb and the newer text bun.lock.
Functions ¶
func AtRevision ¶
func AtRevision(ctx context.Context, dir, revision string, roots []string) (kind, version, origin string)
AtRevision detects the package manager from the committed snapshot at revision, reading package.json's packageManager field and recognized lockfile basenames via git-based reads (never from the live worktree). Only npm, pnpm, and bun are reported; yarn is omitted. kind is "" when no supported manager is identifiable. version is probed from the PATH binary when detectable, and is "" when unverifiable.
func Check ¶
func Check(dir string, roots []string, policyPassed bool) projectreadiness.Check
Check detects and classifies the package manager of every selected root against the frozen adapter support matrix (SA-280-012), reading worktree state at the same per-root context tstoolchain.ResolveCompiler resolves a compiler against. No install is ever executed here -- an ambiguous, unverifiable, or hazardous finding fails closed with a distinct gap code (SA-280-015) instead.
The version that classifies the row is probed from the manager binary that would actually run (ProbeVersion), never taken from package.json's packageManager pin. The frozen adapter rows invoke the bare executable name and Coach never installs or switches to a pinned release, so a pin describes an intention while the probe describes what will run; classifying by the pin would clear a row for a binary that is not there. The pin is still recorded, and BuildSetupPreview discloses it whenever it disagrees with the probe.
A manifest that Contexts actually resolves -- whether under a validated root or, absent one, the default "." context's own nearest package.json -- is real evidence and is classified regardless of policyPassed, the same way checkProjectShape trusts a root-level package.json unconditionally. But when no context resolves any manifest at all, Contexts falls back to classifying whatever bare metadata sits at the worktree root, a directory a genuine monorepo's policy may never actually select. Without a validated policy that fallback is unjustified, so policyPassed false skips it and reports not_checked instead of a package_manager_* gap this check has no real root context to justify (R1, mirroring checkProjectShape's own gate).
func Contexts ¶
Contexts resolves the directories Check reads manager metadata from: each selected root's nearest package.json, which is exactly the context tstoolchain.ResolveCompiler resolves that root's compiler against (resolveProjectRoot). A root with no manifest at or above it contributes no context; when no root contributes one, the worktree root stands in, so a repository whose only metadata is a top-level lockfile beside no package.json is still classified rather than silently unchecked -- fellBack reports when that stand-in fired, so a caller without a validated policy can tell that classification apart from one tstoolchain.ResolveCompiler actually found a manifest for (Check's own R1 gate).
func DetectPackageManagerHazard ¶
DetectPackageManagerHazard reports a non-empty detail describing a repository-controlled configuration hazard from kind's Hazards column (SA-280-012), or "" if none. The lockfile-readability precondition itself is kind-agnostic; see requireReadableLockfile.
func ProbeVersion ¶
ProbeVersion reports the version of the manager binary that would actually run for kind. ok is false whenever the probe could not be confined, the manager is absent from PATH, it exited non-zero, or it printed nothing parseable -- every one of those is "undetectable", never "unsupported".
Types ¶
This section is empty.