src: extend --env-file to also accept sections#58782
src: extend --env-file to also accept sections#58782dario-piotrowicz wants to merge 6 commits intonodejs:mainfrom
--env-file to also accept sections#58782Conversation
|
Review requested:
|
ff88ca1 to
c1edd49
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58782 +/- ##
==========================================
- Coverage 90.08% 90.08% -0.01%
==========================================
Files 640 640
Lines 188316 188370 +54
Branches 36922 36936 +14
==========================================
+ Hits 169650 169687 +37
+ Misses 11406 11404 -2
- Partials 7260 7279 +19
🚀 New features to boost your workflow:
|
c1edd49 to
ee7e6c3
Compare
Make sure that `--env-file` can accept sections, also extend the `parseEnv` and `process.loadEnvFile` APIs to accept sections as well
ee7e6c3 to
d6e8866
Compare
|
Based on the issue discussion, I believe we are only short of testing variables with dots in the name: one.two.three = some value
[section]
four.five = another valueAt the moment we only test section names with dots. The rest looks good! 👍 |
| arg.starts_with("--env-file-if-exists="); | ||
| }; | ||
|
|
||
| const auto get_sections = [](const std::string& path) { |
There was a problem hiding this comment.
I recommend always using std::string_view since you'll always know when you'll copy (by calling std::string(val))
| const auto get_sections = [](const std::string& path) { | |
| const auto get_sections = [](std::string_view path) { |
|
|
||
| Dotenv::ParseResult Dotenv::ParsePath(const std::string_view path) { | ||
| Dotenv::ParseResult Dotenv::ParsePath(const std::string_view path, | ||
| const std::set<std::string> sections) { |
There was a problem hiding this comment.
If you don't add &, you'll always copy.
| const std::set<std::string> sections) { | |
| const std::set<std::string>& sections) { |
|
|
||
| struct IterateSectionsData { | ||
| Isolate* isolate; | ||
| std::set<std::string>* sections; |
There was a problem hiding this comment.
This is considered unsafe. Why do you need to have a pointer to a set?
| ToNamespacedPath(env, &path_value); | ||
| auto path = path_value.ToString(); | ||
|
|
||
| CHECK(args[1]->IsArray()); |
There was a problem hiding this comment.
If you make this optional, you don't need to allocate a std::set every time this function is called.
| Dotenv dotenv{}; | ||
|
|
||
| switch (dotenv.ParsePath(path)) { | ||
| switch (dotenv.ParsePath(path, sections)) { |
There was a problem hiding this comment.
This copies the function.
If you want to avoid copy you should make it set&, if you want to move the ownership to the function since you don't need it inside this function, you should set function parameter to set&& and pass the argument as std::move(sections)
validate sections only when present in options object
update jsdoc types for options Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
Thanks 😄
As I mentioned in the discussion I believe that variable key testing is unrelated to the sections support addition (and that more testing is missing not just only around dots) so I don't see a strong need for adding it here and I would much rather do that in its own dedicated PR, do you disagree? 🙂 |
fix comment typo
add code comment explaining the `[` check
fix cpp formatting
|
I agree that dot based variable overriding is unrelated and probably an overkill feature to implement. |
Dots in in the variables names work currently (I tested it in v24.2.0), so it is not a feature, and extra tests would be just to cover that we do not break that. |
|
Closing as the spec for dotenv files has been merged in #59052 and a simpler spec not including INI has been defined |
Fixes: #58729