// src/actions/barrel/resolveBarrel.ts
import fs from "node:fs";
import { createRequire } from "node:module";
import PATH from "node:path";
var require2 = createRequire(import.meta.url);
function findPackageRoot(entry, pkg) {
  let dir = PATH.dirname(entry);
  for (; ; ) {
    const manifestPath = PATH.join(dir, "package.json");
    if (fs.existsSync(manifestPath)) {
      try {
        const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
        if (manifest.name === pkg) return dir;
      } catch {
      }
    }
    const parent = PATH.dirname(dir);
    if (parent === dir) return void 0;
    dir = parent;
  }
}
function resolvePackageDir(pkg, fromDir) {
  try {
    return PATH.dirname(require2.resolve(`${pkg}/package.json`, { paths: [fromDir] }));
  } catch {
  }
  try {
    const entry = require2.resolve(pkg, { paths: [fromDir] });
    return findPackageRoot(entry, pkg);
  } catch {
    return void 0;
  }
}
export {
  resolvePackageDir
};
//# sourceMappingURL=resolveBarrel.mjs.map
