reachesShort
What a release reaches outside itself, said in a line, its names in backticks: "reaches nothing outside itself",
"only fetchTiles reaches the network", "Pages, Stylesheet and createRouter reach the environment, the
clock and 2 more, through react" (what they reach is the package's doing). Facts worked out before effects were
kept say it as they did.
import type { Effect } from "#codebase/tcmts/core/effects"; import type { ReleaseFacts } from "#codebase/tcmts/registry"; export function reachesShort(f: Pick<ReleaseFacts, "reaches" | "effects" | "unknown">): string { if (!f.effects) return f.reaches; const and = (xs: string[]) => xs.length < 2 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs.at(-1)}`; const cant = f.unknown?.length ? `; can't tell for ${and(f.unknown)}` : ""; const order: [Effect, string][] = [ ["network", "the network"], ["files", "files"], ["processes", "other processes"], ["environment", "the environment"], ["clock", "the clock"], ["random", "randomness"], ["output", "the console"], ]; const has = order.filter(([e]) => f.effects![e]?.length); if (!has.length) return `reaches nothing outside itself${cant}`; // (a definition reaching through a package is named `Pages (react)`) const all = has.flatMap(([e]) => f.effects![e]!); const via = (x: string) => / \(([^()]+)\)$/.exec(x)?.[1]; const names = [...new Set(all.map((x) => x.replace(/ \([^()]+\)$/, "")))]; const through = [...new Set(all.map(via).filter((p): p is string => p !== undefined))]; const words = has.map(([, w]) => w); const what = words.length <= 3 ? and(words) : `${words.slice(0, 2).join(", ")} and ${words.length - 2} more`; const who = names.length === 1 ? `only \`${names[0]}\` reaches` : names.length <= 3 ? `${and(names.map((n) => `\`${n}\``))} reach` : `${names.length} definitions reach`; const theirs = all.every((x) => via(x) !== undefined) ? `, through ${and(through)}` : ""; return `${who} ${what}${theirs}${cant}`; }