import fs from "node:fs/promises";
import path from "node:path";

const ROOT = process.cwd();
const pkgPath = path.join(ROOT, "packages", "domain", "package.json");

const pkg = JSON.parse(await fs.readFile(pkgPath, "utf8"));

const exportsField = pkg.exports;
if (!exportsField || typeof exportsField !== "object") {
  console.error("[domain] ERROR: package.json exports field is missing or invalid.");
  process.exit(1);
}

const keys = Object.keys(exportsField);
const wildcardKeys = keys.filter(k => k.includes("*"));

if (wildcardKeys.length > 0) {
  console.error("[domain] ERROR: wildcard subpath exports are not allowed:");
  for (const k of wildcardKeys) console.error(`- ${k}`);
  process.exit(1);
}

console.log("[domain] OK: package.json exports contains no wildcard keys.");
