1import { statSync } from 'fs'; 2import { join } from 'path'; 3 4import { ConfigError } from './Errors'; 5 6function fileExists(file: string): boolean { 7 try { 8 return statSync(file).isFile(); 9 } catch { 10 return false; 11 } 12} 13 14export function getRootPackageJsonPath(projectRoot: string): string { 15 const packageJsonPath = join(projectRoot, 'package.json'); 16 if (!fileExists(packageJsonPath)) { 17 throw new ConfigError( 18 `The expected package.json path: ${packageJsonPath} does not exist`, 19 'MODULE_NOT_FOUND' 20 ); 21 } 22 return packageJsonPath; 23} 24