const setEnvConfig = env => {
if (env) {
currentEnvironment = env;
return Object.assign(currentConfig, require(`./${env}/`));
}
return Object.assign(currentConfig, require(`./${currentEnvironment}`));
};
A quick and easy solution to this is to not use the dynamic requires statements, even if it means adding a small amount of code duplication.
const setEnvConfig = env => {
if (env) {
currentEnvironment = env;
if (env === 'eval') {
return Object.assign(currentConfig, require('./eval'));
}
if (env === 'prod') {
return Object.assign(currentConfig, require('./prod'));
}
}
return Object.assign(currentConfig, require(`./${currentEnvironment}`));
};
There may be a nicer way of writing this to remove the additional level of indentation from the added if
s of course but the point is we aren't using variables in the require()
.