Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: updates functionality for .env files #51130

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

atomicwrite
Copy link

@atomicwrite atomicwrite commented Dec 12, 2023

Updated

.env parser

Notable Changes

  • heredocs
  • variable interpolation
  • control codes

All previous features including backtick quotes work the same. It passes all previous tests and I've add quite a few more. Runs quickly as I minimalized the amount of allocations by reusing a string buffer and only copying when I need to. I avoided string split and trim as well to avoid more allocs. On average in debug mode on my machine it took about 14ms to run. Mileage may vary and I know I can squeeze a little more out of it if needed.

note Because of my love of granular checkpoint commits and a misunderstanding of the docs when it came to messages (subsystems vs update,fix) I deleted my original fork and just created a new one instead of wrestling with a huge rebase that could unlink me from the upstream. This is the same code as before.

Link to new tests

Context: The current env parser doesn't have full .env compatibility. It lacks heredocs and interpolation. After a conversation with @anonrig I decided to pursue adding this to node.

Adds heredocs, string interpolation, triple quotes,
control codes. Updates for backticks, single and
double quotes.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Dec 12, 2023
@anonrig
Copy link
Member

anonrig commented Dec 15, 2023

@tniessen Blocked the original PR: #50835. I recommend resolving the block first.

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the PR description to include what features we are adding with 1600 lines of code? Depending on the cost of implementation that feature we should trim these lines.

IMHO: 1600 lines for an env file parser is too much.

};
class EnvStream {
size_t index_ = 0;
std::string* data_ = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a string pointer, but not std::string_view?

@@ -32,6 +35,170 @@ class Dotenv {

} // namespace node

namespace cppnv {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this inside node namespace.

return own_buffer != nullptr;
}

void set_own_buffer(std::string* buff) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of documentation on these functions make it really hard to review/approve this PR

return ret;
}

bool cppnv::EnvStream::good() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming convention makes it really hard to understand what this function does.

return end_of_stream_key;
}

int EnvReader::get_white_space_offset_left(const std::string* value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use std::string_view instead of std::string* in everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants