knownGood
uses node:path
The known-good tcm's package (the build the last passing pnpm verify tested), to deploy: its directory and the
tarball in it, checked to be the install verify tested.
import { repository, sh } from "#codebase/tcmts/dev"; import fs from "node:fs"; import path from "node:path"; export function knownGood(): { good: string; tgz: string } { const good = path.join(repository(), "dist", "known-good"); const tgz = fs.existsSync(good) ? fs.readdirSync(good).find((f) => f.endsWith(".tgz")) : undefined; if (!tgz) throw new Error("no known-good tcm to deploy: `pnpm verify` makes one"); // the tarball must be the install verify tested (a stale one was shipped once): the same modules const listed = sh("tar", ["-tzf", path.join(good, tgz)], good); const inTarball = listed.out .split("\n") .filter((l) => l.startsWith("package/modules/")) .map((l) => l.slice("package/modules/".length)) .sort(); const installedModules = fs .readdirSync(path.join(good, "node_modules", "tcm-ts", "modules")) .sort(); if (!listed.ok || inTarball.join() !== installedModules.join()) throw new Error( `${tgz} isn't the known-good tcm verify tested: \`pnpm verify\` packs it again`, ); return { good, tgz }; }