#!/usr/bin/env node import { readdirSync, readFileSync } from "node:fs"; import { join, relative } from "node:path"; const root = join(import.meta.dirname, ".."); const allow = new Set([ "packages/everything-dev/src/services/framework-home.ts", "scripts/train-invariant.mjs", ]); const offenders = []; function* walk(dir) { for (const entry of readdirSync(dir, { withFileTypes: true })) { const path = join(dir, entry.name); if (entry.isDirectory()) { if (entry.name === "node_modules" || entry.name === "dist") continue; yield* walk(path); } else if (/\.(ts|tsx|mjs|mts)$/.test(entry.name)) { yield path; } } } for (const base of ["packages", "scripts"]) { const baseDir = join(root, base); for (const path of walk(baseDir)) { const rel = relative(root, path); if (allow.has(rel)) continue; if (rel.includes("/tests/") || rel.includes("__tests__") || rel.includes(".test.")) continue; if (rel.includes("/fixtures/")) continue; if ( /nearbuilders\/everything-dev|everything-project\/everything-dev/i.test( readFileSync(path, "utf-8"), ) ) { offenders.push(rel); } } } if (offenders.length > 0) { console.error("framework-home guard: home slug found outside the single source (#1256) —"); for (const path of offenders) console.error(` ${path}`); console.error("Derive from services/framework-home.ts instead of hardcoding the slug."); process.exit(1); } console.log("framework-home guard: identity single-sourced");