packageFileName
The name a package's manifest means by one of its files: a name in its namespace, or a path from the codebase's
root (../README.md), read as the file kept under the namespace it would be written from.
import { absolute } from "#codebase/tcmts/cli/manifests"; import type { NameRow } from "#codebase/tcmts/store"; export function packageFileName(rows: NameRow[], ns: string, file: string): string | undefined { const has = (n: string) => rows.some((r) => r.path === n || r.path.startsWith(`${n}.`)); const up = ns.split(".").filter(Boolean); let rest = file.replace(/^\.\//, ""); while (rest.startsWith("../")) { up.pop(); rest = rest.slice(3); } const named = rest.replace(/\.[^./]+$/, "").replaceAll("/", "."); return [absolute(ns, file), [...up, named].filter(Boolean).join("."), absolute(ns, named)].find( has, ); }