import { readdir, readFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const packageDirectory = path.dirname(path.dirname(fileURLToPath(import.meta.url))); async function sourceFiles(): Promise { const directory = path.join(packageDirectory, "src"); const entries = await readdir(directory); return entries .filter((entry) => entry.endsWith(".ts")) .map((entry) => path.join(directory, entry)); } /** * The design contract is imported by the Dashboard shell, by module UI artifacts, and by contributed * renderers. It inherits exactly the rule ADR 0024 established for `@ekklesia/module-ui-sdk`: it * must not be able to pull a backend type graph — and with it Node's global declarations — into a * browser program. */ describe("the design token package stays browser-safe", () => { it("declares no runtime dependency at all", async () => { const manifest = JSON.parse( await readFile(path.join(packageDirectory, "package.json"), "utf8"), ) as { dependencies?: Record; peerDependencies?: Record }; expect(manifest.dependencies).toBeUndefined(); expect(manifest.peerDependencies).toBeUndefined(); }); it("imports nothing outside its own source", async () => { for (const file of await sourceFiles()) { const source = await readFile(file, "utf8"); const specifiers = [...source.matchAll(/from\s+"([^"]+)"/gmu)].map(([, specifier]) => String(specifier), ); expect(specifiers.every((specifier) => specifier.startsWith("."))).toBe(true); } }); it("never names a Node built-in or reads the environment", async () => { for (const file of await sourceFiles()) { const source = await readFile(file, "utf8"); expect(source).not.toContain('"node:'); expect(source).not.toContain("process.env"); expect(source).not.toContain("globalThis.process"); } }); });