const require_rolldown_runtime = require('../../../../../../../../../../_virtual/rolldown_runtime.cjs');
const require_cache = require('./cache.cjs');
let node_path = require("node:path");
let node_fs = require("node:fs");

//#region ../chokidar/dist/esm/unmerged-dictionaries-entry/dist/esm/config/dist/esm/utils/getPackageJsonPath.mjs
require("url").pathToFileURL(__filename).href;
const MAX_LEVELS = 15;
const getPackageJsonPath = (startDir = process.cwd()) => {
	const checkedCache = require_cache.cache.get("packageJsonPath", startDir);
	if (checkedCache) return checkedCache;
	let currentDir = startDir;
	for (let level = 0; level < MAX_LEVELS; level++) {
		const packageJsonPath = (0, node_path.join)(currentDir, "package.json");
		if ((0, node_fs.existsSync)(packageJsonPath)) {
			require_cache.cache.set("packageJsonPath", startDir, {
				packageJsonPath,
				baseDir: currentDir
			});
			return {
				packageJsonPath,
				baseDir: currentDir
			};
		}
		const parentDir = (0, node_path.dirname)(currentDir);
		if (parentDir === currentDir) break;
		currentDir = parentDir;
	}
	throw new Error(`Could not find package.json in current directory or any of the ${MAX_LEVELS} parent directories. Searched from: ${startDir}`);
};

//#endregion
exports.getPackageJsonPath = getPackageJsonPath;
//# sourceMappingURL=getPackageJsonPath.cjs.map