import { INodePackageJson } from '@rushstack/node-core-library' ; import { IProjectNode } from '../projects/get-projects' ; const initProjectDependencyAndDependent = ( project , projectsName , projectsMap ) => { const dependencies = ( project . extra . dependencies as INodePackageJson [ 'dependencies' ] ) || { } ; const devDependencies = ( project . extra . devDependencies as INodePackageJson [ 'devDependencies' ] ) || { } ; const optionalDependencies = ( project . extra . optionalDependencies as INodePackageJson [ 'optionalDependencies' ] ) || { } ; const DependencyProjectsName = Object . keys ( { ... dependencies , ... devDependencies , ... optionalDependencies , } ) . filter ( depName => projectsName . includes ( depName ) ) ; project . dependent = project . dependent || [ ] ; project . dependency = DependencyProjectsName . map ( projectName => { const dependencyProject = projectsMap . get ( projectName ) as IProjectNode ; const dependent = dependencyProject ?. dependent || [ ] ; if ( ! dependent . some ( p => p . name === project . name ) ) { dependencyProject . dependent = [ ... dependent , project ] ; dependencyProject . dependentEdge = dependencyProject . dependent . length ; } return dependencyProject ; } ) ; project . dependencyEdge = project . dependency . length ; } ; export const create = ( projects ) => { const projectsName = [ ] ; const projectsMap = new Map ( ) ; for ( const project of projects ) { projectsMap . set ( project . name , project ) ; projectsName . push ( project . name ) ; } for ( const project of projects ) { initProjectDependencyAndDependent ( project , projectsName , projectsMap ) ; } return { projectsMap , projectList : projectsName } ; } ;