// src/actions/package-lint-specs.ts
import { readdirSync, statSync } from "node:fs";
import PATH from "node:path";
function emptyResult() {
  return {
    errors: [],
    fixable: [],
    warnings: []
  };
}
function collectSpecFiles(dir, out) {
  for (const entry of readdirSync(dir)) {
    const fullPath = PATH.join(dir, entry);
    const stats = statSync(fullPath);
    if (stats.isDirectory()) {
      if (entry === "node_modules" || entry === "dist") {
        continue;
      }
      collectSpecFiles(fullPath, out);
      continue;
    }
    if (entry.endsWith(".spec.ts")) {
      out.push(fullPath);
    }
  }
}
function checkSpecFileLayout(cwd, workspaces) {
  const result = emptyResult();
  for (const { location, name } of workspaces) {
    if (location === ".") {
      continue;
    }
    const srcDir = PATH.resolve(cwd, location, "src");
    const specFiles = [];
    try {
      collectSpecFiles(srcDir, specFiles);
    } catch {
      continue;
    }
    for (const specPath of specFiles) {
      const relativeToSrc = PATH.relative(srcDir, specPath).replaceAll("\\", "/");
      if (!relativeToSrc.startsWith("spec/")) {
        const relativeToRepo = PATH.relative(cwd, specPath).replaceAll("\\", "/");
        result.errors.push(`${name}: spec file must live under src/spec/ \u2014 ${relativeToRepo}`);
      }
    }
  }
  return result;
}
export {
  checkSpecFileLayout
};
//# sourceMappingURL=package-lint-specs.mjs.map
