ember-cli-dotenv icon indicating copy to clipboard operation
ember-cli-dotenv copied to clipboard

Use dotenv's `silent` option rather than using your own exists checking

Open devinus opened this issue 10 years ago • 5 comments

devinus avatar Oct 12 '15 07:10 devinus

@devinus can you add more information? Unclear what you mean by exists checking.

jasonmit avatar Nov 16 '17 05:11 jasonmit

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 avatar Mar 23 '18 06:03 lolmaus

@lolmaus unsure when I'll get around to it, but will happily review any PRs related to solving this.

jasonmit avatar Mar 23 '18 07:03 jasonmit

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:

  1. Add a clientRequiredKeys property. Keys in clientRequiredKeys would be required (fail automatically if missing). Keys in clientAllowedKeys would remain optional with a change to no missing key warnings. At this point, I think failOnMissingKey could be deprecated because you'd have finer-grained settings.

  2. Do option 1, but also add a warnOnMissingKey property with a default of true. This would give a heads up on a missing key in clientAllowedKeys (similar to current behavior), but the warnings could then be suppressed by setting it to false. This would basically keep the current behavior of clientAllowedKeys (optional, with suppressible warning), and give us required keys also.

  3. Just add a suppressMissingKeyWarnings property which defaults to false. If true, it'd just skip the console.warn and all other logic would remain the same. Feels a bit like a bolt-on though.

Maybe someone else has a better idea though.

ntodd avatar Apr 24 '18 22:04 ntodd

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.

xtagon avatar Mar 24 '20 16:03 xtagon