Skip to content

feat: enable passing Node.js cli flags#21110

Merged
codebytere merged 2 commits intomasterfrom
enable-node-cli-flags
Feb 7, 2020
Merged

feat: enable passing Node.js cli flags#21110
codebytere merged 2 commits intomasterfrom
enable-node-cli-flags

Conversation

@codebytere
Copy link
Copy Markdown
Member

@codebytere codebytere commented Nov 13, 2019

Description of Change

This PR enables passing safelisted cli flags to Node.js to allow doing useful things like enabling experimental Node.js features.

For reasons outlined below, it seems safer to make different allowances for Electron itself vs Electron in ELECTRON_RUN_AS_NODE mode. As such, this PR only allows passing DebugOptions via cli for prototypical Electron, and allows all options in ELECTRON_RUN_AS_NODE mode.

I've upstreamed the patch necessary to enable this at nodejs/node#30466.

cc @nornagon @MarshallOfSound @ckerr

Checklist

Release Notes

Notes: Enable native Electron handling and passing of Node.js cli options.

@codebytere codebytere requested a review from a team as a code owner November 13, 2019 16:05
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Nov 13, 2019
@codebytere codebytere force-pushed the enable-node-cli-flags branch 9 times, most recently from a04ea40 to 7da7ab8 Compare November 13, 2019 22:33
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Nov 14, 2019
@codebytere
Copy link
Copy Markdown
Member Author

codebytere commented Nov 15, 2019

Current issue/consideration:

Node.js will spit back a non-zero exit code (9) if any non-node switches are appended to the command line, which is the case by default for some switches like --allow-file-access-from-files and --enable-avfoundation set in atom_main_delegate.

The Node.js flags passed will still work and be correctly set, but this makes me think that a more robust approach might instead be to safelist allowed flags instead of skipping a preset list of disallowed flags, which would ameliorate this issue entirely. What do you all think?

@deepak1556
Copy link
Copy Markdown
Member

deepak1556 commented Nov 15, 2019

What is the difference between this and the NODE_OPTIONS support we already provide ? AFAIU you can pass these command line params through options https://nodejs.org/api/cli.html#cli_node_options_options ?

I am slightly not okay with maintaining any kind of blacklist for volatile structures, we tried to do that for chromium in the past but quickly proved inefficient #13039.

Also any reason apps want this for production environments ? It would also simply not maintaining a list if its just for dev environment.

@codebytere
Copy link
Copy Markdown
Member Author

codebytere commented Nov 15, 2019

At the moment, we introduce a lot of extra patch surface by exposing DebugOptions, as we do currently do a small amount of parsing cli flags in this manner for InspectorAgent initialization. As ux goes - passing flags in this manner is a lot more user-friendly and is most likely what users expect, and this will, more importantly allow us to remove a notable amount of patch surface (Node.js will not extern DebugOptions, whereas the patch in this PR has already been approved upstream) and simplify the way we're passing settings to node for the InspectorAgent, a process i've already started here.

I would also be in favor of moving away from a blacklist approach and into a whitelist approach based on concerns you outlined above from a general safety perspective.

@deepak1556
Copy link
Copy Markdown
Member

deepak1556 commented Nov 15, 2019

What is the difference between this and the NODE_OPTIONS support we already provide ? AFAIU you can pass these command line params through options https://nodejs.org/api/cli.html#cli_node_options_options ?

I still don't understand why this is needed over NODE_OPTIONS.

I think we can agree inspector related flags are special case and it wouldn't be hard to handle them separately. But I don't see why we have to bring in parsing the whole set of node cli switches support when there is already another way to achieve it NODE_OPTIONS ? if there are flags that aren't allowed in this mode users should get that fixed in Node.js and not through us.

@deepak1556
Copy link
Copy Markdown
Member

Node.js will not extern DebugOptions, whereas the patch in this PR has already been approved upstream

If the aim is to reduce the patch around DebugOptions, we can handle only the cli arguments related to inspector through this new method. I am still -1 on handling all node cli options through this new method.

@codebytere
Copy link
Copy Markdown
Member Author

I'd be happy to adapt this PR to just allow the set of DebugOptions-specific options and then we could perhaps open the wider conversation of what we want to eventually enable for users, be it flags, NODE_OPTIONS, or both?

I would say that i personally feel NODE_OPTIONS was added as a shortest-path approach to enable handling these options at all, but is less ergonomic/usable an approach in contrast to being able to pass those selfsame options via bespoke flags

@deepak1556
Copy link
Copy Markdown
Member

I'd be happy to adapt this PR to just allow the set of DebugOptions-specific options and then we could perhaps open the wider conversation of what we want to eventually enable for users, be it flags, NODE_OPTIONS, or both?

Yup that would be great, thanks!

I would say that i personally feel NODE_OPTIONS was added as a shortest-path approach to enable handling these options at all, but is less ergonomic/usable an approach in contrast to being able to pass those selfsame options via bespoke flags

True I agree with that as well but that comes to our personal choice, what I am trying to avoid is double parsing stuff, we already maintain a code path with blacklisted options for NODE_OPTIONS which I am not so happy about, I am declined to add another layer on top of that. Also node gave this feature support despite cli because its easier to pass across environments to child processes, so I think its sufficient.

The primary goal here is to eliminate the patches around DebugOptions for which maintaining a whitelist of node inspector related flags are much easier and solves the issue at hand rather than maintaining an ever growing list of all node cli options.

@codebytere codebytere force-pushed the enable-node-cli-flags branch from 7da7ab8 to 6cf2a51 Compare November 16, 2019 04:19
@codebytere codebytere force-pushed the enable-node-cli-flags branch 5 times, most recently from e02d010 to a0752dd Compare November 18, 2019 18:28
@codebytere codebytere changed the title feat: enable passing Node.js cli flags [wip] feat: enable passing Node.js cli flags Nov 18, 2019
@codebytere codebytere force-pushed the enable-node-cli-flags branch 4 times, most recently from e46e659 to 4aa3e1e Compare November 22, 2019 18:58
Copy link
Copy Markdown
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

LGTM with clarification.

Comment thread shell/app/node_main.cc
@codebytere codebytere force-pushed the enable-node-cli-flags branch from 4aa3e1e to 385971a Compare December 6, 2019 18:53
@codebytere
Copy link
Copy Markdown
Member Author

I'll take a look at these test failures soon but as soon as that's handled this should be g2g.

@zcbenz zcbenz added the wip ⚒ label Jan 21, 2020
@zcbenz
Copy link
Copy Markdown
Contributor

zcbenz commented Jan 21, 2020

I'm adding wip tag since there are pending works (fixing tests) in this PR.

@codebytere
Copy link
Copy Markdown
Member Author

@zcbenz thanks - i should be able to get back to this soon!

@codebytere codebytere force-pushed the enable-node-cli-flags branch 6 times, most recently from b5d5ac4 to e2ddab2 Compare February 3, 2020 22:08
Copy link
Copy Markdown
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Failing tests are unrelated, LGTM. Thanks!

Can you fix the conflicts for merge.

@codebytere codebytere force-pushed the enable-node-cli-flags branch from e2ddab2 to 13e1d59 Compare February 4, 2020 19:14
@codebytere codebytere force-pushed the enable-node-cli-flags branch from 13e1d59 to 81992fd Compare February 5, 2020 03:11
@jkleinsc
Copy link
Copy Markdown
Member

jkleinsc commented Feb 6, 2020

@codebytere rebasing this against master should resolve the linux failures

@codebytere codebytere force-pushed the enable-node-cli-flags branch from 81992fd to 4fe4b89 Compare February 6, 2020 16:16
@codebytere codebytere merged commit 8312488 into master Feb 7, 2020
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Feb 7, 2020

Release Notes Persisted

Enable native Electron handling and passing of Node.js cli options.

@codebytere codebytere deleted the enable-node-cli-flags branch February 7, 2020 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants