Repository navigation
src: read env files only from Node.js options - #67642
ShogunPanda wants to merge 1 commit into
Conversation
|
Review requested:
|
65a1557 to
20d5f8e
Compare
|
The
notable-change
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 Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67642 +/- ##
==========================================
- Coverage 90.71% 90.58% -0.14%
==========================================
Files 801 802 +1
Lines 280906 286942 +6036
Branches 54246 55403 +1157
==========================================
+ Hits 254834 259922 +5088
- Misses 16251 17115 +864
- Partials 9821 9905 +84
🚀 New features to boost your workflow:
|
| in the file, the value from the environment takes precedence. | ||
|
|
||
| The flag is only recognized before the script. Arguments after the script name | ||
| or after `--` are passed to the script and are not read as Node.js options. |
There was a problem hiding this comment.
does this make this semver-major?
There was a problem hiding this comment.
I don't think this needs to be semver-major. The documented CLI contract is node [options] … [<program-entry-point>] [--] [arguments]: flags after the script are script arguments, not Node options. That's also what we told users in #58338.
What's actually changing is an inconsistency in the current implementation. GetDataFromArgs still opens --env-file after the script — so a missing file exits 9, and NODE_OPTIONS from the file is applied — but has_env_file_string stays false, so those variables never show up on process.env and the flag never appears in process.execArgv. --config-file was already fixed the same way in #66431 without a semver-major label.
I'll treat it as a bug fix. If we'd rather be conservative I can add the label, but I don't think a deprecation cycle is warranted.
`--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>
20d5f8e to
25abed7
Compare
--env-fileand--env-file-if-existswere 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 theirNODE_OPTIONSapplied.Find where the options of Node.js end with a throwaway parse, the same way
--config-fileis handled, and only look for env file flags before that point.Testing: added
test/parallel/test-dotenv-args-after-script.js. Thetest-dotenv*,test-cli-*andtest-config-file*suites pass, as do eslint and cpplint.