// src/actions/deplint/getRequiredPeerDependencies.ts
import fs from "fs";
import path from "path";
function findDepPackageJson(location, dep) {
  let dir = location;
  while (true) {
    const candidate = path.join(dir, "node_modules", dep, "package.json");
    if (fs.existsSync(candidate)) return candidate;
    const parent = path.dirname(dir);
    if (parent === dir) return void 0;
    dir = parent;
  }
}
function getRequiredPeerDependencies(location, allDeps) {
  const required = /* @__PURE__ */ new Set();
  for (const dep of allDeps) {
    const depPkgPath = findDepPackageJson(location, dep);
    if (!depPkgPath) continue;
    try {
      const raw = fs.readFileSync(depPkgPath, "utf8");
      const pkg = JSON.parse(raw);
      const peerDeps = pkg.peerDependencies;
      const meta = pkg.peerDependenciesMeta;
      if (peerDeps) {
        for (const peer of Object.keys(peerDeps)) {
          if (meta?.[peer]?.optional) continue;
          required.add(peer);
        }
      }
    } catch {
    }
  }
  return required;
}
export {
  findDepPackageJson,
  getRequiredPeerDependencies
};
//# sourceMappingURL=getRequiredPeerDependencies.mjs.map