import { Project , Workspace , Manifest } from "@yarnpkg/core" ; import RunSupervisor from "./index" ; const getWorkspaceChildrenRecursive = ( rootWorkspace , project ) : Array < Workspace > => { const workspaceList = [ ] ; for ( const childWorkspaceCwd of rootWorkspace . workspacesCwds ) { const childWorkspace = project . workspacesByCwd . get ( childWorkspaceCwd ) ; if ( childWorkspace ) { workspaceList . push ( childWorkspace , ... getWorkspaceChildrenRecursive ( childWorkspace , project ) ) ; } } return workspaceList ; } ; const addTargets = async ( { targetWorkspace , project , supervisor , } ) : Promise < void > => { if ( targetWorkspace . workspacesCwds . size !== 0 ) { const workspaceList = getWorkspaceChildrenRecursive ( targetWorkspace , project ) ; for ( const workspace of workspaceList ) { for ( const dependencyType of Manifest . hardDependencies ) { for ( const descriptor of workspace . manifest . getForScope ( dependencyType ) . values ( ) ) { const matchingWorkspace = project . tryWorkspaceByDescriptor ( descriptor ) ; if ( matchingWorkspace === null ) continue ; await supervisor . addRunTarget ( matchingWorkspace ) ; } } await supervisor . addRunTarget ( workspace ) ; } await supervisor . addRunTarget ( targetWorkspace ) ; } else { await supervisor . addRunTarget ( targetWorkspace ) ; } } ; export { getWorkspaceChildrenRecursive , addTargets } ;