-
Notifications
You must be signed in to change notification settings - Fork 510
Description
I changed the intentation level of the code which made CR feel entitled to talk smack about the code.
Code Rabbit pointed out that this code will match on env='test' and filename = 'contest.json':
load.options.nodeEnv.forEach(function (env) {
// Throw an exception if there's no explicit config file for NODE_ENV
const anyFilesMatchEnv = sourceFilenames.some(function (filename) {
return filename.match(env);
});
// development is special-cased because it's the default value
if (env && (env !== 'development') && !anyFilesMatchEnv) {
_warnOrThrow(`${load.getEnv("nodeEnv")} value of '${env}' did not match any deployment config file names.`);
}
It suggested the following edit, which seems pretty close to me.
load.options.nodeEnv.forEach(function (env) {
// Throw an exception if there's no explicit config file for NODE_ENV
const anyFilesMatchEnv = sourceFilenames.some(function (filename) {
return filename.match(new RegExp(`(^|[.-])${env}([.-]|$)`));
});
// development is special-cased because it's the default value
if (env && (env !== 'development') && !anyFilesMatchEnv) {
_warnOrThrow(`${load.getEnv("nodeEnv")} value of '${env}' did not match any deployment config file names.`);
}
Except that it should probably be:
return filename.match(new RegExp(`^${env}[.-]`));
At the very least CodeRabbit failed to match correctly on the file extension. And the groupings are pointless since we're ignoring the return value of match()
Because we do, I think, want to declare that 'a test config file was found' when NODE_ENV=test and APP_INSTANCE=1 and we find '/config/test-1.json', but APP_INSTANCE=2 should fail if neither 'test-2.json' nor 'test.json' exist.
But I wanted a sanity check from @markstos or @lorenwest about whether I'm reading this right.