Composing environment variables #9458
Replies: 1 comment
-
Good question, and you're thinking about things attentively. I appreciate the thoughtfully worded question(s). The way that I like thinking about it is: When I run my code locally, I'm simulating what happens in production. You don't run packages, you run applications that are composed of packages (which is something you correctly alluded to). With that mental model, you start to realize that a package has no independent runtime. It only runs within the context of an application. So, if I want to model that locally, that would mean I only use There's an exception: If you're running scripts directly in packages that require environment variables, you might be forced to put a |
Beta Was this translation helpful? Give feedback.
-
Summary
I am trying to wrap my head around how environment variables should be handled. I understand that instead of having a single
.env
file in the root of the repository,.env
files should be kept in the packages where they're used:First: is the above usage of "packages" is referring to Application Packages, Internal Packages, or both?
The surrounding context leads me to believe that "packages" is referring to Application Packages:
It makes sense to me that the environment variables would be application-scoped, but please correct me if I'm wrong. To be clear, my understanding is that the repository should look like this:
In the structure above,
app-a
andapp-b
have.env
files, whereaspackage-a
,package-b
, and the repository root do not.In some cases, I feel it would make sense for my
.env
files to be co-located with an Internal Packages. For example, I have aspecific-db
Internal Package which is always looking forSPECIFIC_DB_CONNECTION_URL
. This variable is dependent on the environment; that is,app-a
andapp-b
will pass the sameSPECIFIC_DB_CONNECTION_URL
in production. In addition,specific-db
has code generation scripts that rely onSPECIFIC_DB_CONNECTION_URL
.If I structure my repository such that my
.env
files are co-located withspecific-db
:How would I go about composing the environment variables for
app-a
from the environment variables inspecific-db
? Is there a better way than duplicating the.env
files fromspecific-db
and/or writing codegen to keep them in sync?Unrelated question: what's a use-case in which
globalEnv
makes sense to use over task-specificenv
? Can someone give me an example of an environment variable that should result in alint
task missing cache on change?References
Beta Was this translation helpful? Give feedback.
All reactions