-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
fix: enable use of NODE_OPTIONS env var #15158
Conversation
0733acd
to
00d87f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codebytere
We should remove NODE_WITHOUT_NODE_OPTIONS
define from the e/node
's BUILD.gn:
https://github.com/electron/node/blob/f14ddf9d7e07739dc1dc0cbe2f7a5ba8b44906d1/BUILD.gn#L155
Can we add a test that |
@alexeykuzmin they do locally, will try to add a spec; also, your requested changes are a PR that was already linked in the PR body. |
What was the initial reason to remove support for NODE_OPTIONS? |
@nornagon it was never removed, it was always broken from the very beginning since we passed |
ahh, gotcha! |
The changes LGTM, also needs to update for standalone node mode in Just need some clarification, what is the benefit of enabling this for electron ? This actually removes the control of node argument parsing away from us, now some of the node options are parsed and enabled from an environment variable, which seems to bypass the blacklist we maintain when the executable is invoked through a protocol handler. |
ed6b88f
to
d3efc52
Compare
@nornagon @alexeykuzmin @deepak1556 @nitsakh in addition to the advisory warnings above, what are your thoughts on my also explicitly disallowing all |
atom/common/node_bindings.cc
Outdated
int exec_argc = 0; | ||
const char** argv = nullptr; | ||
const char* prog_name = "electron"; | ||
const char** argv = {&prog_name}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the brackets for here?
atom/common/node_bindings.cc
Outdated
|
||
// parse passed options for unsupported options | ||
// and remove them from the options list | ||
for (std::string part : parts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to create a new temporary; can use std::string& part
atom/common/node_bindings.cc
Outdated
std::size_t found = disallow.find(part); | ||
if (found != std::string::npos) { | ||
LOG(WARNING) << "This NODE_OPTION is not supported in Electron"; | ||
parts.erase(std::remove(parts.begin(), parts.end(), part), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You _really _ don't want to be modifying the parts
vector while iterating through it in the outermost loop here.
I'd suggest you do something more like
std::vector<std::string> tmp;
for (const auto& part : parts) {
if (disallow.count(part)) {
warning...
} else {
tmp.push_back(part);
}
}
std::swap(parts, tmp);
atom/common/node_bindings.cc
Outdated
if (!is_first_round) | ||
new_options << " "; | ||
new_options << part; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might try something like this:
std::copy(
parts.begin(), parts.end(),
std::ostream_iterator<std::string>(new_options," "));
If we are disabling them completely for packaged apps and allowing otherwise, the current options parsing and warning in this PR won't be required, only a simplified warning in packaged mode would be needed to state |
9e9f89a
to
7af2eff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of suggestions inline, but nothing major. LGTM!
atom/common/node_bindings.cc
Outdated
std::transform(path.begin(), path.end(), path.begin(), ::tolower); | ||
|
||
#if defined(OS_WIN) | ||
is_packaged_app = path == "electron.exe"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) the advance declaration above could be removed and these two lines could be
#if defined(OS_WIN)
const bool is_packaged_app = path == "electron.exe";
#else
const bool is_packaged_app = path == "electron";
#endif
atom/common/node_bindings.cc
Outdated
if (is_packaged_app) { | ||
env->SetVar("NODE_OPTIONS", ""); | ||
} else { | ||
std::vector<std::string> disallowed = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) this can be const std::vector<std::string>
7af2eff
to
3bf4072
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this final-draft revision on a C++ level. This code LGTM and I'd be fine with it landing.
I don't have any opinion on how to NODE_OPTIONS
wrt packaging. If someone feels strongly about that, please weigh in before this merges. 😐
Release Notes Persisted
|
We have automatically backported this PR to "4-0-x", please check out #15259 |
Description of Change
Enables use of
NODE_OPTIONS
environment variable in Electron.Depends on electron/node#76.
Potential concerns: options relating to V8 that may cause collisions should they misalign with Blink's V8 usage.
/cc @deepak1556
Checklist
npm test
passesRelease Notes
Notes: Enable use of NODE_OPTIONS env var