clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/prf-provision-custody
lofi / package / astro / vendored_manifest_test.ts
vendored_manifest_test.ts 2.2K
1// Repo contract test: the static `.lofi/` vendoring manifests must track the2// actual package directories. The lists are static because the published3// package cannot enumerate directories over JSR — this test is what fails4// when a new runtime module lands without being added to the manifest5// (namespace-state.ts and transport-gate.ts shipped exactly that way and6// broke every generated project's build until vendoring caught up).7import { accessFiles, preactFiles, recipeFiles, runtimeFiles, schemaFiles } from "./mod.ts";89function assert(condition: unknown, message: string): asserts condition {10 if (!condition) throw new Error(message);11}1213// Files that live in the source directories but are deliberately not vendored.14const notVendored = new Set([15 "sw.js", // copied by the build command with its revision stamped in16 "test-assert.ts", // package test helper17]);1819async function moduleEntries(directory: string): Promise<string[]> {20 const names: string[] = [];21 for await (const entry of Deno.readDir(new URL(`../${directory}`, import.meta.url))) {22 if (!entry.isFile) continue;23 if (entry.name.endsWith("_test.ts") || entry.name.endsWith("_test.tsx")) continue;24 if (notVendored.has(entry.name)) continue;25 if (!/\.(ts|tsx|d\.ts)$/.test(entry.name)) continue;26 names.push(entry.name);27 }28 return names.sort();29}3031const manifests: ReadonlyArray<[string, readonly string[]]> = [32 ["runtime", runtimeFiles],33 ["access", accessFiles],34 ["preact", preactFiles],35 ["recipes", recipeFiles],36 ["schema", schemaFiles],37];3839Deno.test("the .lofi vendoring manifests match the package directories", async () => {40 for (const [directory, manifest] of manifests) {41 const actual = await moduleEntries(directory);42 const listed = [...manifest].sort();43 const missing = actual.filter((name) => !listed.includes(name));44 const stale = listed.filter((name) => !actual.includes(name));45 assert(46 missing.length === 0,47 `package/${directory} contains modules missing from the vendoring manifest: ${48 missing.join(", ")49 } — generated projects cannot build without them`,50 );51 assert(52 stale.length === 0,53 `the vendoring manifest lists modules absent from package/${directory}: ${stale.join(", ")}`,54 );55 }56});