printDependents
uses process
Dependents re-hashed by an update: a line each when there are a few, else by namespace, with how many and the
first of them (tcm diff lists them all). Brief (TCM_BRIEF=1), just how many.
import { listed } from "#codebase/tcmts/cli/main"; import { bold, dim, yellow } from "#codebase/tcmts/cli/style"; export function printDependents(paths: string[]) { if (!paths.length) return; if (process.env.TCM_BRIEF === "1" && paths.length > 6) return console.log( `${yellow(" ~ updated ")} ${paths.length} dependents ${dim("(re-hashed: what they use changed; `tcm diff` lists them)")}`, ); if (paths.length <= 6) { for (const p of paths) console.log(`${yellow(" ~ updated ")} ${bold(p)} ${dim("(dependent)")}`); return; } const byNs = new Map<string, string[]>(); for (const p of paths) { const ns = p.slice(0, Math.max(0, p.lastIndexOf("."))); byNs.set(ns, [...(byNs.get(ns) ?? []), p.slice(ns ? ns.length + 1 : 0)]); } console.log( `${yellow(" ~ updated ")} ${paths.length} dependents ${dim("(re-hashed: what they use changed; `tcm diff` lists them)")}`, ); for (const [ns, leaves] of [...byNs].sort((a, b) => b[1].length - a[1].length)) console.log(` ${bold(ns || "(root)")} ${dim(`${leaves.length}: ${listed(leaves, 5)}`)}`); }