import { Config } from "../types/Config" ; import { filterPackages } from "./filterPackages" ; import { Workspace } from "../types/Workspace" ; import { getScopedPackages , getChangedPackages , getBranchChanges } from "workspace-tools" ; import * as fg from "fast-glob" ; import { logger } from "../logger" ; export function getPipelinePackages ( workspace , config ) { const { scope , since , repoWideChanges , includeDependencies } = config ; const hasScopes = Array . isArray ( scope ) && scope . length > 0 ; let scopedPackages = undefined ; if ( hasScopes ) { scopedPackages = getScopedPackages ( scope ! , workspace . allPackages ) ; } const hasSince = typeof since !== "undefined" ; let changedPackages = undefined ; if ( hasSince && ! hasRepoChanged ( since , workspace . root , repoWideChanges ) ) { try { changedPackages = getChangedPackages ( workspace . root , since , config . ignore ) ; } catch ( e ) { logger . warn ( `An error in the git command has caused this scope run to include every package\n${ e }` ) ; } } return filterPackages ( { allPackages : workspace . allPackages , deps : config . deps , scopedPackages , changedPackages , includeDependencies , } ) ; } function hasRepoChanged ( since , root , environmentGlob ) { try { const changedFiles = getBranchChanges ( since , root ) ; const envFiles = fg . sync ( environmentGlob , { cwd : root } ) ; let repoWideChanged = false ; if ( changedFiles ) { for ( const change of changedFiles ) { if ( envFiles . includes ( change ) ) { repoWideChanged = true ; break ; } } } return repoWideChanged ; } catch ( e ) { logger . warn ( `An error in the git command has caused this to consider the repo has changed\n${ e }` ) ; return true ; } }