-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
base: main
Are you sure you want to change the base?
util: add loadEnvFile
utility
#59125
Conversation
Review requested:
|
fcc6903
to
08e836c
Compare
@@ -95,10 +95,10 @@ describe('process.loadEnvFile()', () => { | |||
assert.strictEqual(child.code, 1); | |||
}); | |||
|
|||
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 ReportAttention: 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:
|
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.