-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 code = ` | ||
process.loadEnvFile(${JSON.stringify(basicValidEnvFilePath)}); | ||
require('assert')(process.env.BASIC === 'basic'); | ||
require('node:assert').strictEqual(process.env.BASIC, 'overriden'); | ||
`.trim(); | ||
const child = await common.spawnPromisified( | ||
process.execPath, | ||
|
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/removeprocess.loadEnvFile
.To me personally it feels much clearer to have this sort of operation more manual and have the user load their .env files with
loadEnvFile
and then use the values to populateprocess.env
themselves if and how they want (with any overriding, filtering, etc. logic).