usersOf
Named, live definitions that use name (at range, or any), with the ranges they use.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { pinnedRange } from "#codebase/tcmts/core/types"; import { parseModule } from "#codebase/tcmts/loader/packages"; export function usersOf(cb: Codebase, name: string, range?: string, namespace?: string): Map<string, string> { const out = new Map<string, string>(); const live = cb.liveHashes(); for (const n of cb.store.names()) { if (namespace && n.path !== namespace && !n.path.startsWith(`${namespace}.`)) continue; if (!live.has(n.hash)) continue; const rec = cb.store.getDef(n.hash); for (const d of rec?.deps ?? []) { const r = pinnedRange(d.ref, name); if (r && (!range || r === range)) out.set(n.hash, r); } if (rec?.jsx?.startsWith(`npm:${name}@`) && (!range || rec.jsx === `npm:${name}@${range}`)) out.set(n.hash, parseModule(rec.jsx).version); } return out; }