findPackage
One package of these, by name; with no name, the only one there is.
import type { Pkg } from "#codebase/tcmts/cli/manifests"; export function findPackage(pkgs: Pkg[], name: string | undefined): Pkg { if (!pkgs.length) throw new Error("no packages here: a definition named `manifest` makes its namespace one (see docs/publishing.md)"); if (name === undefined) { if (pkgs.length === 1) return pkgs[0]!; throw new Error(`which package? ${pkgs.map((p) => p.name).join(", ")}`); } const p = pkgs.find((x) => x.name === name); if (!p) throw new Error(`no package ${name} (there's ${pkgs.map((x) => x.name).join(", ")})`); return p; }