toolRange

tcmts.cli.lint.toolRange · #bm6z6kln · term · runs anywhere

The range a tool runs at: the one chosen for it, else the newest the codebase locks (none if it's never run).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { compareVersions } from "#codebase/tcmts/core/semver";

export function toolRange(cb: Codebase, name: string): string | undefined {
  const pad = (r: string) =>
    r.split(".").length === 1 ? `${r}.0.0` : r.split(".").length === 2 ? `${r}.0` : r;
  const locked = cb.store
    .lockedPackages()
    .filter((l) => l.name === name)
    .map((l) => l.range)
    .sort((a, b) => compareVersions(pad(a), pad(b)))
    .at(-1);
  return cb.store.getSetting(`tool.${name}`) ?? locked;
}

uses

used by