Use dotenv's `silent` option rather than using your own exists checking
@devinus can you add more information? Unclear what you mean by exists checking.
I would like some of my env vars to be optional. In config/environment.js I'm providing default values for non-existing variables.
Yet, whenever I run any ember command in the terminal, I see this:
[ember-cli-dotenv]: Required environment variable 'COR_DEPLOY_TARGET' is missing.
[ember-cli-dotenv]: Required environment variable 'COR_ROOT_URL' is missing.
It is very annoying.
To work around this, I have to provide empty env vars in every .env-* file that I have (I'm using per-target env files: local, staging, production) and add logic to treat empty strings as false. :weary:
Related piece of code: https://github.com/fivetanley/ember-cli-dotenv/blob/a3c1b289c5918348a29e860cc1d567654de71267/index.js#L47-L58
@lolmaus unsure when I'll get around to it, but will happily review any PRs related to solving this.
I agree with @lolmaus that it would be nice to have optional keys. I may have a bit of time to work on this, but there are a few ways this could maybe work:
-
Add a
clientRequiredKeysproperty. Keys inclientRequiredKeyswould be required (fail automatically if missing). Keys inclientAllowedKeyswould remain optional with a change to no missing key warnings. At this point, I thinkfailOnMissingKeycould be deprecated because you'd have finer-grained settings. -
Do option 1, but also add a
warnOnMissingKeyproperty with a default oftrue. This would give a heads up on a missing key inclientAllowedKeys(similar to current behavior), but the warnings could then be suppressed by setting it tofalse. This would basically keep the current behavior ofclientAllowedKeys(optional, with suppressible warning), and give us required keys also. -
Just add a
suppressMissingKeyWarningsproperty which defaults tofalse. If true, it'd just skip theconsole.warnand all other logic would remain the same. Feels a bit like a bolt-on though.
Maybe someone else has a better idea though.
It would be nice to be able to specify required vs optional keys in different environments. I have some keys that are required in production but not in dev/test.