Skip to content

src: read env files only from Node.js options - #67642

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:cli-env-file-before-script
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:cli-env-file-before-script

Conversation

@ShogunPanda

Copy link
Copy Markdown
Contributor

--env-file and --env-file-if-exists were looked up in every argument up to a literal --, including the ones after the script name. Those arguments belong to the script, but the files they named were still opened and their NODE_OPTIONS applied.

Find where the options of Node.js end with a throwaway parse, the same way --config-file is handled, and only look for env file flags before that point.

Testing: added test/parallel/test-dotenv-args-after-script.js. The test-dotenv*, test-cli-* and test-config-file* suites pass, as do eslint and cpplint.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues and PRs related to Node.js configuration and feature settings. needs-ci PRs that need a full CI run. labels Nov 20, 2026
`--env-file` and `--env-file-if-exists` were looked up in every
argument up to a literal `--`, including the ones that follow the script
name. Those belong to the script, but the files they named were still
opened and their `NODE_OPTIONS` applied.

Find where the options of Node.js end with a throwaway parse and only
look for env file flags before that point. The parse is shared with the
config file reader and only runs when an env file flag is present.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@ShogunPanda
ShogunPanda force-pushed the cli-env-file-before-script branch from 65a1557 to 20d5f8e Compare November 20, 2026 09:01
@ShogunPanda ShogunPanda added the notable-change PRs with changes that should be highlighted in changelogs. label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @ShogunPanda.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (50ba1ec) to head (20d5f8e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/node_dotenv.cc 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67642   +/-   ##
=======================================
  Coverage   90.71%   90.72%           
=======================================
  Files         801      801           
  Lines      280906   280913    +7     
  Branches    54246    54249    +3     
=======================================
+ Hits       254834   254856   +22     
+ Misses      16251    16249    -2     
+ Partials     9821     9808   -13     
Files with missing lines Coverage Δ
src/node_config_file.cc 84.24% <100.00%> (-0.82%) ⬇️
src/node_options.cc 88.34% <100.00%> (+0.10%) ⬆️
src/node_options.h 95.86% <100.00%> (+0.10%) ⬆️
src/node_dotenv.cc 85.25% <85.71%> (+0.49%) ⬆️

... and 34 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.

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++. config Issues and PRs related to Node.js configuration and feature settings. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants