outsideUses
What a package's code uses from outside it: definitions of the codebase that aren't the package's own (by their
names here, or #hash for ones with none), its tests' included (they come with its namespace), not its manifest's.
A tcm library (npm: false) mustn't use any: a codebase that adds it mounts its names, and what it uses outside
them would arrive unnamed.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { owns } from "#codebase/tcmts/cli/manifests"; import type { Pkg } from "#codebase/tcmts/cli/manifests"; import type { NameRow } from "#codebase/tcmts/store"; export function outsideUses(cb: Codebase, pkg: Pkg, all: Pkg[], rows: NameRow[]): string[] { const own = rows.filter( (r) => owns(pkg, all, r.path) && !r.path.endsWith(".manifest") && r.path !== "manifest", ); const mine = new Set(own.map((r) => r.hash)); const outside = new Set<string>(); const seen = new Set<string>(); for (const r of own) { const rec = cb.store.getDef(r.hash); if (!rec || seen.has(rec.componentHash)) continue; seen.add(rec.componentHash); for (const m of cb.store.componentMembers(rec.componentHash)) for (const d of m.deps) if (d.ref.startsWith("#") && !mine.has(d.ref.slice(1))) outside.add(d.ref.slice(1)); } return [...outside] .map((h) => rows.find((r) => r.hash === h)?.path ?? `#${h.slice(0, 8)}`) .sort(); }