import { VersionGroupOptions } from '../types/BeachballOptions' ; import path from 'path' ; import { PackageInfos , PackageGroups } from '../types/PackageInfo' ; import { isPathIncluded } from './utils' ; export function getPackageGroups ( packageInfos , root , groups ) { const packageGroups = { } ; const packageNameToGroup = { } ; if ( groups && groups . length ) { for ( const [ pkgName , info ] of Object . entries ( packageInfos ) ) { const packagePath = path . dirname ( info . packageJsonPath ) ; const relativePath = path . relative ( root , packagePath ) ; for ( const groupOption of groups ) { if ( isPathIncluded ( relativePath , groupOption . include , groupOption . exclude ) ) { const groupName = groupOption . name ; if ( packageNameToGroup [ pkgName ] ) { console . error ( `Error: ${ pkgName } cannot belong to multiple groups: [${ groupName }, ${ packageNameToGroup [ pkgName ] }]!` ) ; process . exit ( 1 ) ; } packageNameToGroup [ pkgName ] = groupName ; if ( ! packageGroups [ groupName ] ) { packageGroups [ groupName ] = { packageNames : [ ] , disallowedChangeTypes : groupOption . disallowedChangeTypes , } ; } packageGroups [ groupName ] . packageNames . push ( pkgName ) ; } } } } return packageGroups ; }