import { ImportWeight } from '../../types/DiffResults' ; import { EnhancedModuleGraph } from './EnhancedModuleGraph' ; export function getAddedWeight ( moduleName , baseline , comparison , chunkGroupName ) { return getModuleWeight ( moduleName , comparison , baseline , chunkGroupName ) ; } export function getRemovedWeight ( moduleName , baseline , comparison , chunkGroupName ) { return getModuleWeight ( moduleName , baseline , comparison , chunkGroupName ) ; } function getModuleWeight ( moduleName , targetGraph , oppositeGraph , chunkGroupName ) { const visited = new Set < string > ( ) ; const weight = { moduleCount : 0 , size : 0 , modules : [ ] , } ; getImportWeightRecursive ( moduleName , targetGraph , oppositeGraph , chunkGroupName , weight , visited ) ; return weight ; } function getImportWeightRecursive ( moduleName , targetGraph , oppositeGraph , chunkGroupName , weight , visited ) { if ( visited . has ( moduleName ) ) { return ; } else { visited . add ( moduleName ) ; } if ( ! targetGraph . hasModule ( moduleName , chunkGroupName ) ) { return ; } if ( oppositeGraph . hasModule ( moduleName , chunkGroupName ) ) { return ; } const module = targetGraph . getModule ( moduleName ) ; weight . moduleCount ++ ; weight . size += module . size ; weight . modules . push ( moduleName ) ; for ( let child of module . children ) { getImportWeightRecursive ( child , targetGraph , oppositeGraph , chunkGroupName , weight , visited ) ; } }