import { getMaxChangeType , MinChangeType } from '../changefile/getPackageChangeTypes' ; import { BumpInfo } from '../types/BumpInfo' ; import { ChangeType } from '../types/ChangeInfo' ; param entryPointPackageName param bumpInfo param bumpDeps returns export function updateRelatedChangeType ( changeFile , bumpInfo , bumpDeps ) { /** [^1]: all the information needed from `bumpInfo` */ const { calculatedChangeTypes , packageGroups , dependents , packageInfos , groupOptions } = bumpInfo ; const changesForFile = bumpInfo . changeFileChangeInfos . filter ( info => info . changeFile === changeFile ) ; for ( const { change : changeFileChangeInfo } of changesForFile ) { const entryPointPackageName = changeFileChangeInfo . packageName ; const dependentChangeType = changeFileChangeInfo . dependentChangeType ; if ( ! packageInfos [ entryPointPackageName ] ) { return ; } let updatedChangeType = getMaxChangeType ( dependentChangeType , MinChangeType , [ ] ) ; const queue = [ { subjectPackage : entryPointPackageName , changeType : MinChangeType } ] ; const visited = new Set < string > ( ) ; while ( queue . length > 0 ) { let { subjectPackage , changeType } = queue . shift ( ) ! ; if ( ! visited . has ( subjectPackage ) ) { visited . add ( subjectPackage ) ; const packageInfo = packageInfos [ subjectPackage ] ; if ( ! packageInfo ) { continue ; } const disallowedChangeTypes = packageInfo . combinedOptions ?. disallowedChangeTypes ?? [ ] ; if ( subjectPackage !== entryPointPackageName ) { updateChangeType ( subjectPackage , changeType , disallowedChangeTypes ) ; } const dependentPackages = dependents [ subjectPackage ] ; if ( bumpDeps && dependentPackages && dependentPackages . length > 0 ) { for ( const dependentPackage of dependentPackages ) { queue . push ( { subjectPackage : dependentPackage , changeType : updatedChangeType , } ) ; } } const groupName = Object . keys ( packageGroups ) . find ( group => packageGroups [ group ] . packageNames . includes ( packageInfo . name ) ) ; if ( groupName ) { for ( const packageNameInGroup of packageGroups [ groupName ] . packageNames ) { if ( ! groupOptions [ groupName ] || ! groupOptions [ groupName ] ?. disallowedChangeTypes ?. includes ( updatedChangeType ) ) { queue . push ( { subjectPackage : packageNameInGroup , changeType : updatedChangeType , } ) ; } } } } } } function updateChangeType ( pkg , changeType , disallowedChangeTypes ) { const newChangeType = getMaxChangeType ( calculatedChangeTypes [ pkg ] , changeType , disallowedChangeTypes ) ; calculatedChangeTypes [ pkg ] = newChangeType ; return newChangeType ; } }