Skip to content

src: support override option in process.loadEnvFile#63197

Open
Han5991 wants to merge 2 commits intonodejs:mainfrom
Han5991:feat/process-loadenvfile-override
Open

src: support override option in process.loadEnvFile#63197
Han5991 wants to merge 2 commits intonodejs:mainfrom
Han5991:feat/process-loadenvfile-override

Conversation

@Han5991
Copy link
Copy Markdown
Contributor

@Han5991 Han5991 commented May 8, 2026

Adds an opt-in override option to process.loadEnvFile() and a matching --env-file-override-local CLI flag, so callers can swap env-file contexts within one process lifetime (integration tests, monorepo configs).

process.loadEnvFile('.env.test', { override: true });
node --env-file=.env --env-file-override-local index.js

Default behavior — existing env vars take precedence — is unchanged (the contract from #49424).

Based on prior work in #52531 (rebased onto current main, with Maybe<void> return type, lazy getValidatedPath, options-only overload detection, 7 new test cases).

Refs: #63027
Refs: #52531

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels May 8, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.03%. Comparing base (bbf51ad) to head (8443aa9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63197      +/-   ##
==========================================
- Coverage   90.03%   90.03%   -0.01%     
==========================================
  Files         713      713              
  Lines      224950   224973      +23     
  Branches    42532    42534       +2     
==========================================
+ Hits       202542   202562      +20     
- Misses      14175    14187      +12     
+ Partials     8233     8224       -9     
Files with missing lines Coverage Δ
lib/internal/process/per_thread.js 99.47% <100.00%> (-0.35%) ⬇️
src/node.cc 76.19% <100.00%> (+0.03%) ⬆️
src/node_dotenv.cc 84.72% <100.00%> (ø)
src/node_dotenv.h 100.00% <ø> (ø)
src/node_options.cc 76.65% <100.00%> (+0.04%) ⬆️
src/node_options.h 98.00% <100.00%> (+0.01%) ⬆️
src/node_process_methods.cc 88.55% <100.00%> (+0.02%) ⬆️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Han5991 and others added 2 commits May 9, 2026 08:09
Add an opt-in `override` option to `process.loadEnvFile()` and a
matching `--env-file-override-local` CLI flag, allowing values from
`.env` files to replace existing variables in `process.env`.

By default, existing environment variables continue to take
precedence; callers must opt in explicitly. This lets a single
process swap env-file contexts at runtime (integration tests,
monorepo configurations) without manually parsing files via
`util.parseEnv()`.

Co-authored-by: Ilyas Shabi <[email protected]>
Signed-off-by: sangwook <[email protected]>
Signed-off-by: sangwook <[email protected]>
@Han5991 Han5991 force-pushed the feat/process-loadenvfile-override branch from c298987 to 8443aa9 Compare May 8, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants