clone

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

fix/175-template-quality-pass
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 package module lands without being added to the manifest, which5// would otherwise surface only as a broken build in generated projects.6import { accessFiles, preactFiles, recipeFiles, runtimeFiles, schemaFiles } from "./manifest.ts";78function assert(condition: unknown, message: string): asserts condition {9 if (!condition) throw new Error(message);10}1112// Files that live in the source directories but are deliberately not vendored.13const notVendored = new Set([14 "sw.js", // copied by the build command with its revision stamped in15 "test-assert.ts", // package test helper16]);1718async function moduleEntries(directory: string): Promise<string[]> {19 const names: string[] = [];20 for await (const entry of Deno.readDir(new URL(`../${directory}`, import.meta.url))) {21 if (!entry.isFile) continue;22 if (entry.name.endsWith("_test.ts") || entry.name.endsWith("_test.tsx")) continue;23 if (notVendored.has(entry.name)) continue;24 if (!/\.(ts|tsx|d\.ts)$/.test(entry.name)) continue;25 names.push(entry.name);26 }27 return names.sort();28}2930const manifests: ReadonlyArray<[string, readonly string[]]> = [31 ["runtime", runtimeFiles],32 ["access", accessFiles],33 ["preact", preactFiles],34 ["recipes", recipeFiles],35 ["schema", schemaFiles],36];3738Deno.test("the .lofi vendoring manifests match the package directories", async () => {39 for (const [directory, manifest] of manifests) {40 const actual = await moduleEntries(directory);41 const listed = [...manifest].sort();42 const missing = actual.filter((name) => !listed.includes(name));43 const stale = listed.filter((name) => !actual.includes(name));44 assert(45 missing.length === 0,46 `package/${directory} contains modules missing from the vendoring manifest: ${47 missing.join(", ")48 } — generated projects cannot build without them`,49 );50 assert(51 stale.length === 0,52 `the vendoring manifest lists modules absent from package/${directory}: ${stale.join(", ")}`,53 );54 }55});