import { existsSync, readFileSync, statSync } from "node:fs"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "@suaveplan/testing/runner"; const here = dirname(fileURLToPath(import.meta.url)); const pkgRoot = resolve(here, ".."); const pkg = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf8")) as { exports: Record; sideEffects: boolean; }; describe("dep-graph", () => { it("declares 14 tree-shakeable subpath exports", { timeout: 5000 }, () => { const sub = Object.keys(pkg.exports).filter( (k) => k.startsWith("./") && k !== "./package.json" ); // 13 subpaths + the root "." = 14. expect(sub.length + 1).toBe(14); }); it("sideEffects is false", { timeout: 5000 }, () => { expect(pkg.sideEffects).toBe(false); }); it("every implementation .ts has a sibling .md", { timeout: 5000 }, () => { const missing: string[] = []; walk(join(pkgRoot, "src"), (path) => { if (!path.endsWith(".ts")) return; if (path.endsWith(".test.ts")) return; if (path.endsWith(".types.ts")) return; if (path.endsWith("/index.ts")) return; if (path.endsWith(".spec-conformance.test.ts")) return; const md = path.replace(/\.ts$/, ".md"); if (!existsSync(md)) missing.push(md); }); expect(missing).toEqual([]); }); }); function walk(dir: string, visit: (path: string) => void): void { for (const entry of readdirSyncSafe(dir)) { const full = join(dir, entry); const st = statSync(full); if (st.isDirectory()) walk(full, visit); else visit(full); } } function readdirSyncSafe(dir: string): string[] { try { const { readdirSync } = require("node:fs") as typeof import("node:fs"); return readdirSync(dir); } catch { return []; } }