import { dirname, resolve } from "node:path";
import { existsSync, readFileSync } from "node:fs";

//#region ../@intlayer/cli/dist/esm/utils/getParentPackageJSON.mjs
const getParentPackageJSON = (startDir) => {
	let currentDir = startDir;
	while (currentDir !== dirname(currentDir)) {
		const packageJsonPath = resolve(currentDir, "package.json");
		if (existsSync(packageJsonPath)) return JSON.parse(readFileSync(packageJsonPath, "utf8"));
		currentDir = dirname(currentDir);
	}
	const rootPackageJsonPath = resolve(currentDir, "package.json");
	if (existsSync(rootPackageJsonPath)) return JSON.parse(readFileSync(rootPackageJsonPath, "utf8"));
	throw new Error(`No package.json found in any parent directory of ${startDir}`);
};

//#endregion
export { getParentPackageJSON };
//# sourceMappingURL=getParentPackageJSON.mjs.map