import { readdirSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "@suaveplan/testing/runner"; const PKG_ROOT = join(__dirname, ".."); const packageJson = JSON.parse( readFileSync(join(PKG_ROOT, "package.json"), "utf-8") ) as { sideEffects: unknown; bin: Record; exports: Record; }; const DOCUMENTED_SUBPATHS = [ "error-codes", "telemetry", "types", "schemas", "fs", "runner", "config", "templates", "icons", "generator", "prompts", "cli", ] as const; describe("package shape", () => { it("package.json declares the documented subpath exports", { timeout: 5000, }, () => { const subpathKeys = Object.keys(packageJson.exports) .filter((k) => k.startsWith("./") && k !== "./package.json") .map((k) => k.replace(/^\.\//, "")); for (const sub of DOCUMENTED_SUBPATHS) { expect(subpathKeys).toContain(sub); } }); it("bin entry resolves to the published binary", { timeout: 5000 }, () => { expect(packageJson.bin["suaveplan-electrobun"]).toBe( "./dist/bin/suaveplan-electrobun.js" ); }); it("sideEffects is false", { timeout: 5000 }, () => { expect(packageJson.sideEffects).toBe(false); }); it("every feature folder has a matching subpath export", { timeout: 5000, }, () => { const srcDir = join(PKG_ROOT, "src"); const featureFolders = readdirSync(srcDir, { withFileTypes: true, }) .filter((e) => e.isDirectory() && e.name !== "bin") .map((e) => e.name) .sort(); const subpathKeys = Object.keys(packageJson.exports) .filter((k) => k.startsWith("./") && k !== "./package.json") .map((k) => k.replace(/^\.\//, "")); for (const folder of featureFolders) { expect(subpathKeys).toContain(folder); } }); });