c12 icon indicating copy to clipboard operation
c12 copied to clipboard

Allow overriding config with environment variables

Open pi0 opened this issue 2 years ago • 2 comments

We can use destr to allow overriding any configuration using process.env.{NAME}_CONFIG_{PATH}.

Let's same NAME is NUXT:

  • NUXT_CONFIG_SSR=false overrides ssr to false
  • NUXT_CONFIG_GENERATE:CRAWLER=true overrides generate.crawler to true
  • NUXT_CONFIG={"ssr": false, "generate": { "crawler": true }} does the same as two above

Notes:

  • defaults option needs to exist in order to enable an env variable to override
  • Same as defu, arrays can be only extended not overridden. We might find a convention for defu to allow this with specific key prefix/suffix.

pi0 avatar May 03 '22 14:05 pi0

@pi0 We have a need for this as well, so happy to provide a PR if desired 🙂

Before diving into anything though, do you have any more in-depth thoughts/specs on how that should work?

Directus' configuration currently does a similar level of "automagic" type casting and nesting by looking at the env var name (so for example THIS_IS__NESTED="true" becomes { "thisIs": { "nested": true }}, so happy to lift some of that logic into c12 and tweak it for the updated syntax. What's your plan for "multipart" names? Like should NUXT_CONFIG_CAMEL_CASE become { "camelCase": x }? Curious to hear your thoughts! Also happy to chat on Discord / Google Meet or whatever else is most convenient for you 🙂

rijkvanzanten avatar May 16 '23 20:05 rijkvanzanten

@pi0 Any update on this issue, or on @rijkvanzanten's proposal ?

AlbanCrepel avatar Mar 16 '24 14:03 AlbanCrepel