import { toConfigPackage } from './config-name-helpers' ; import { DEPENDENCIES } from './constants' ; import { MeaningfulDependency , Config } from './shared-types' ; import { toMap } from './util/to-map' ; interface Params { installedDependencies : string [ ] ; finalConfigs ? : Config [ ] ; hasAliases ? : boolean ; useTs : boolean ; } export function getRequiredDependencies ( { installedDependencies , finalConfigs , hasAliases = false , useTs , } ) { const dependenciesSet = new Set ( ) ; function add ( deps ) { for ( const dep of deps ) { dependenciesSet . add ( dep ) ; } } function remove ( deps ) { for ( const dep of deps ) { dependenciesSet . delete ( dep ) ; } } if ( finalConfigs ) { const configsMap = toMap ( finalConfigs ) ; add ( [ 'eslint' ] ) ; const configDependencies = Array . from ( configsMap . keys ( ) , toConfigPackage ) ; add ( configDependencies ) ; if ( configsMap . has ( 'prettier' ) ) { add ( [ 'prettier' ] ) ; } if ( configsMap . has ( 'typescript' ) ) { add ( [ DEPENDENCIES . TS_PARSER ] ) ; } else if ( ! useTs ) { add ( [ DEPENDENCIES . BABEL_PARSER ] ) ; } } if ( hasAliases ) { if ( useTs ) { add ( [ 'eslint-import-resolver-typescript' ] ) ; } else { add ( [ 'eslint-import-resolver-alias' ] ) ; } } if ( installedDependencies . includes ( 'react-scripts' ) ) { if ( ! installedDependencies . includes ( 'eslint' ) ) { remove ( [ 'eslint' ] ) ; } if ( ! installedDependencies . includes ( 'babel-eslint' ) ) { remove ( [ 'babel-eslint' ] ) ; } } return Array . from ( dependenciesSet ) ; }