src: parse dotenv with the rest of the options#54913
src: parse dotenv with the rest of the options#54913avivkeller wants to merge 2 commits intonodejs:mainfrom avivkeller:dotenv-fix-1
Conversation
|
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54913 +/- ##
==========================================
+ Coverage 88.39% 88.40% +0.01%
==========================================
Files 652 654 +2
Lines 186777 187649 +872
Branches 36039 36093 +54
==========================================
+ Hits 165109 165899 +790
- Misses 14917 14994 +77
- Partials 6751 6756 +5
🚀 New features to boost your workflow:
|
|
If it fixes a lot of things, shouldn't it add a lot of tests? |
|
Tests have been added + rebased. |
targos
left a comment
There was a problem hiding this comment.
The way the test is done is not very robust: if the error message changes in the future, it will be wrong but still pass. It would be better to assert the actual error
|
The failed GitHub tests are flakes, could someone start a CI? I don't have the permissions to start one without approvals |
|
I have to incorporate #53060 |
anonrig
left a comment
There was a problem hiding this comment.
Can you rebase your branch with main, with the recent changes, it is extremely hard to review.
|
I'm currently facing the problem of: The files aren't parsed in the same order they were supplied. It's loading all of the optionals, then all of the normals. Any ideas? |
Well you are grabbing them all by creating vectors and referencing those via You're likely respecting argument order inside each vector, it's just you're segregating them by optionality first |
Exactly... I just don't know how to fix that. |
It's one thing that e.g. |
|
I fixed the issue by iterating over the arguments. It's kind of a mix between what was done previously. |
|
I'm not a expert CPP developer, so LMK if I made a mistake. |
|
As shocking as it may seem, all Github failures are unrelated flakes. @anonrig is this better to what you had in mind? |
|
First of all, thanks a lot for still working on a proper fix for the env file option issues, @redyetidev.
I saw that you already fixed it, but maybe it could be solved much easier: From my understanding, the order of My proposed solution is, first reading all the "required" env files in the order they appear in the option list, then all "optional" ones, and adding a note about the env file processing order to the documentation. |
|
IMHO the current setup makes more sense, that is, parse in the order the options where passed. |
|
I've modified the implementation to use a new |
|
@anonrig are you still blocking? I think I've resolved all your concerns. As for the string copying, I believe it's needed, as other functions are expecting a string. |
|
PTAL @nodejs/cpp-reviewers |
|
Any other concerns, @lemire? |
|
@redyetidev I don't have any concern, but I'd like to hear what @anonrig has to say about this PR. He is still asking for changes which I consider blocking. One thing is certain: this has been opened in September. We should do something with it. |
Closes #54385Fixes #54255
Ref #54232
I don't think this breaks anything. IIUC, the Dotenv parser was setup before everything else so that it triggered before V8 initialized, however, even it's setup after the options are parsed, V8 still hasn't been initialized, so it should be fine.
This fixes all currently known dotenv edge cases, as it doesn't need a custom parser.
Such as:
node script.js --env-file .env node --env-file-ABCD .env node -- --env-file .env node --invalid --env-file .env # this would've errored, but the env file is still parsed