import { getTransitiveConsumers , getTransitiveDependencies , PackageInfos , } from "workspace-tools" ; import { logger } from "../logger" ; param options export function filterPackages ( options ) { const { scopedPackages , changedPackages , allPackages , deps , includeDependencies , } = options ; let filtered = [ ] ; if ( typeof scopedPackages !== "undefined" && typeof changedPackages !== "undefined" ) { filtered = changedPackages . filter ( ( pkg ) => scopedPackages . includes ( pkg ) ) . concat ( getTransitiveConsumers ( changedPackages , allPackages , scopedPackages ) ) ; logger . verbose ( `filterPackages changed within scope: ${ filtered . join ( "," ) }` ) ; } else if ( typeof changedPackages !== "undefined" ) { filtered = [ ... changedPackages ] ; logger . verbose ( `filterPackages changed: ${ changedPackages . join ( "," ) }` ) ; } else if ( typeof scopedPackages !== "undefined" ) { filtered = [ ... scopedPackages ] ; logger . verbose ( `filterPackages scope: ${ scopedPackages . join ( "," ) }` ) ; } else { filtered = Object . keys ( allPackages ) ; } if ( deps ) { logger . verbose ( `filterPackages running with dependents` ) ; filtered = filtered . concat ( getTransitiveConsumers ( filtered , allPackages ) ) ; } if ( includeDependencies ) { filtered = filtered . concat ( getTransitiveDependencies ( filtered , allPackages ) ) ; } const unique = new Set ( filtered ) ; return [ ... unique ] ; }