import { rollup as lernaAliases } from 'lerna-alias' ; import path from 'path' ; import { findGitRoot } from './findGitRoot' ; export interface PackageJson { name : string ; version : string ; main : string ; types ? : string ; module ? : string ; dependencies ? : { [ key ] : string ; } ; devDependencies ? : { [ key ] : string ; } ; [ key ] : any ; } export interface PackageInfo { /** Package path relative to the project root */ packagePath : string ; /** package.json contents */ packageJson : PackageJson ; } export type AllPackageInfo = { [ packageName ] : PackageInfo ; } ; let packageInfoCache = null ; export function getAllPackageInfo ( ) { if ( packageInfoCache ) { return packageInfoCache ; } const gitRoot = findGitRoot ( ) ; const packagePaths = lernaAliases ( { sourceDirectory : false } ) ; const packageInfo = { } ; for ( const [ packageName , packagePath ] of Object . entries ( packagePaths ) ) { try { packageInfo [ packageName ] = { packagePath : path . relative ( gitRoot , packagePath ) , packageJson : require ( path . join ( packagePath , 'package.json' ) ) , } ; } catch ( ex ) { console . warn ( `Error parsing package.json for ${ packageName }: ${ ex }` ) ; } } packageInfoCache = packageInfo ; return packageInfo ; }