import type Config from '../../types/config/Config' ; import type DependencyRule from '../../types/config/DependencyRule' ; import type ExportRule from '../../types/config/ExportRule' ; const isSameExport = ( exportA , exportB ) => { return exportA . accessibleTo === exportB . accessibleTo && exportA . modules === exportB . modules ; } ; const isSameDependencyRule = ( dependencyA , dependencyB ) => { return ( dependencyA . accessibleTo === dependencyB . accessibleTo && dependencyA . dependency === dependencyB . dependency ) ; } ; export type FenceDiff = { tags : DiffList < string > | null ; exports : DiffList < ExportRule > | null ; imports : DiffList < string > | null ; dependencies : DiffList < DependencyRule > | null ; } ; type DiffList < T > = { /**
     * The list of new entries in the new version of the list.
     *
     * If there is no new version of the list (e.g. the list was
     * deleted in this change), this will be null.
     */ added : T [ ] | null ; /**
     * The list of old entries in the old version of the list.
     *
     * If there was no old version of the list (e.g. the list was
     * introduced in this change), this will be null.
     */ removed : T [ ] | null ; } ; param oldList param newList param checkIsSame returns export function diffList < T > ( oldList , newList , checkIsSame ) { if ( newList && ! oldList ) { return { added : [ ... newList ] , removed : null , } ; } else if ( oldList && ! newList ) { return { added : null , removed : [ ... oldList ] , } ; } else if ( ! oldList && ! newList ) { return null ; } else { let listDiff = { added : [ ] , removed : [ ] , } ; for ( let oldListEntry of oldList ) { if ( ! newList . some ( checkIsSame . bind ( null , oldListEntry ) ) ) { listDiff . removed . push ( oldListEntry ) ; } } for ( let newListEntry of newList ) { if ( ! oldList . some ( checkIsSame . bind ( null , newListEntry ) ) ) { listDiff . added . push ( newListEntry ) ; } } return listDiff . added . length || listDiff . removed . length ? listDiff : null ; } } see DiffList export function getFenceDiff ( oldFence , newFence ) { let diff = { tags : diffList ( oldFence . tags , newFence . tags , ( a , b ) => a === b ) , exports : diffList ( oldFence . exports , newFence . exports , isSameExport ) , imports : diffList ( oldFence . imports , newFence . imports , ( a , b ) => a === b ) , dependencies : diffList ( oldFence . dependencies , newFence . dependencies , isSameDependencyRule ) , } ; if ( diff . exports === null && diff . imports === null && diff . dependencies === null ) { return null ; } return diff ; }