Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 7x 7x 7x 8x 8x 32x 32x 8x 24x | import * as path from 'path';
import * as fs from 'fs';
/**
* Finds the directory containing the package.json file by traversing up the directory tree.
* @returns {string | null} The absolute path to the directory containing package.json, or null if not found.
*/
export function getPackageJsonDir(): string | null {
let currentDir = __dirname;
while (currentDir !== path.parse(currentDir).root) {
const packageJsonPath = path.join(currentDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
return currentDir;
}
currentDir = path.dirname(currentDir);
}
return null;
}
|