-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
util: add loadEnvFile
utility
#59125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: add loadEnvFile
utility
#59125
Conversation
Review requested:
|
fcc6903
to
08e836c
Compare
}); | ||
|
||
it('loadEnvFile does not mutate --env-file output', async () => { | ||
it('loadEnvFile overrides env vars loaded with --env-file', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change, but I hope it's fine given that dotenv is experimental (and I don't imagine many developers relying on this behavior? 🤔)
I am also not sure about the rational, personally if a new env file is loaded onto process.env
I would expect that it would override whatever else is there 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a problem I can keep the existing behavior.
Since I am thinking of making more changes in this space, to avoid churn and I would prefer this PR not to be a semver-major one if possible.
const loaded = util.loadEnvFile(path); | ||
ObjectAssign(process.env, loaded); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how trivial it is to load a .env file onto process.env
I even wonder if we could deprecate/remove process.loadEnvFile
.
To me personally it feels much clearer to have this sort of operation more manual and have the user load their .env files withloadEnvFile
and then use the values to populate process.env
themselves if and how they want (with any overriding, filtering, etc. logic).
08e836c
to
6d075c6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #59125 +/- ##
==========================================
+ Coverage 90.03% 90.05% +0.02%
==========================================
Files 648 648
Lines 190967 190984 +17
Branches 37425 37443 +18
==========================================
+ Hits 171931 171988 +57
+ Misses 11665 11625 -40
Partials 7371 7371
🚀 New features to boost your workflow:
|
I don't get it, how is |
Sorry, yeah my wording there is misleading, yes, of course Basically |
My idea here was related on having a counterpart for I was also thinking of maybe trying to take this even a step further and have a |
It seems redundant when you can basically do the same with |
Mh... under that argument I'd also say that Object.assign(process.env, util.parseEnv(fs.readFileSync('.env', 'utf8'))) no? 🤔 |
Wasn't |
I don't know to be honest... I just saw that they were introduced together (#51476) |
See #51476 (comment) |
Closing since I don't think we're going to go with this API due to the conversation above ( 🥹 ) |
We already have this logic in place for
process.loadEnvFile
so I figured that it could make sense to just repurpose it also provide a user facing function.This function is the analogous of
util.parseEnv
but for files.