import path from 'path' ; import { Options } from 'jscodeshift' ; const cwd = process . cwd ( ) ; export const requireDynamically = ( p ) => eval ( `require('${ p }');` ) ; export const readConfigWebpack = ( configFilename , defaultConfig ) => { try { const configPath = path . join ( cwd , configFilename ) ; const config = requireDynamically ( configPath ) ; return config ; } catch ( e ) { console . log ( 'Config not found: ' , e ) ; return defaultConfig ; } } ; export const readConfigFile = ( configFilename , defaultConfig ) => { try { const configPath = path . join ( cwd , configFilename ) ; const config = require ( configPath ) ; return config ; } catch ( e ) { console . log ( 'Config not found: ' , e ) ; return defaultConfig ; } } ; export const getConfig = < Config extends object > ( options , defaultConfig = { } ) : Config => { if ( options . testConfig ) { return options . testConfig ; } if ( ! options . config ) { return defaultConfig ; } return readConfigFile ( options . config , defaultConfig ) ; } ;