import merge from 'deepmerge' ; import { Json , AliasesMeta , AliasMapItem } from '../../../lib/shared-types' ; import { CustomMerge } from './types' ; const jsCustomMerge = ( key ) => { if ( key === 'map' ) { return ( a , b ) => { const existingAliasNames = a . map ( ( [ aliasName ] ) => aliasName ) ; const newMapItems = b . filter ( ( mapItem ) => { const [ aliasName ] = mapItem ; return ! existingAliasNames . includes ( aliasName ) ; } ) ; return [ ... a , ... newMapItems ] ; } ; } if ( key === 'extensions' ) { return ( a , b ) => { return Array . from ( new Set ( [ ... a , ... b ] ) ) ; } ; } return undefined ; } ; export const jsAliasesAdder = ( currentConfig , meta ) : Json => merge ( currentConfig , { settings : { 'import/resolver' : { alias : { map : meta . aliasMap , extensions : [ '.js' , '.jsx' , '.json' ] , } , } , } , } , { customMerge : jsCustomMerge } ) ;