import { existsSync , PathLike , readdirSync , readFileSync } from 'fs' ; import { resolve } from 'path' ; import { createLogger } from './logger' ; const logger = createLogger ( { package : 'util' , messageContext : 'fs' } ) ; export function findProjectRoot ( path , lastPath = path ) { if ( ! path ) { return lastPath ; } const inProject = readdirSync ( path ) . includes ( 'package.json' ) || readdirSync ( path ) . includes ( 'node_modules' ) || path . includes ( 'node_modules' ) ; if ( ! inProject ) { return lastPath ; } return findProjectRoot ( resolve ( path , '..' ) , path ) ; } param path returns export function readJSON ( path ) { if ( existsSync ( path ) ) { return JSON . parse ( readFileSync ( path , 'utf8' ) ) ; } logger . warn ( `File "${ path }" does not exist, return empty object.` ) ; return { } ; }