@intlayer/config
Version:
Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.
34 lines (32 loc) • 1.32 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_utils_cacheMemory = require('./cacheMemory.cjs');
let node_fs = require("node:fs");
let node_path = require("node:path");
//#region src/utils/getPackageJsonPath.ts
const MAX_LEVELS = 15;
const getPackageJsonPath = (startDir = process.cwd()) => {
const checkedCache = require_utils_cacheMemory.cacheMemory.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_utils_cacheMemory.cacheMemory.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