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

feat: allow running NPM tools from execroot #2297

Merged
merged 1 commit into from
Dec 18, 2020

Conversation

duarten
Copy link
Contributor

@duarten duarten commented Nov 20, 2020

NPM tools are currently run out of external/{md}/node_modules. If the
tool loads user-provided files in the execroot, which is the common
case, then this can lead to bad interactions.

Two examples of bad interactions are:

  1. A tool that loads React and the user code too,
    hooks becoming unusable.
  2. A tool that calls into a bundler like Webpack,
    potentially bundling duplicate packages.

Signed-off-by: Duarte Nunes duarte@hey.com

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #2286

What is the new behavior?

A user-provided flag controls where the NPM tool is loaded from.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Tests and docs are missing, looking for early feedback.

NPM tools are currently run out of external/{md}/node_modules. If the
tool loads user-provided files in the execroot, which is the common
case, then this can lead to bad interactions.

Two examples of bad interactions are:
  1. A tool that loads React and the user code too,
     hooks becoming unusable.
  2. A tool that calls into a bundler like Webpack,
     potentially bundling duplicate packages.

Signed-off-by: Duarte Nunes <duarte@hey.com>
@google-cla google-cla bot added the cla: yes label Nov 20, 2020
@duarten duarten marked this pull request as ready for review November 23, 2020 17:09
# TODO: after we link-all-bins we should not need this extra lookup
if [[ ! -f "$MAIN" ]]; then
if [ "$FROM_EXECROOT" = true ]; then
MAIN="$EXECROOT/$MAIN"
Copy link
Collaborator

Choose a reason for hiding this comment

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

does something break if we always use FROM_EXECROOT? do you understand what if anything still relies on the old path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests seem to pass except for //internal/node/test:main_test when executed with bazel test; it works fine with bazel run. Maybe this is because paths change when running in the sandbox? The code could probably be adapted to also deal with that case

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay I think we should immediately attempt to get the default flipped in a PR following this one.

reasoning:

  • will have to wait 6mo otherwise
  • long flag flip rollouts are a bummer
  • in the meantime if other users hit the same bug you did it will be really hard for them to discover this opt-in flag that fixes it

if [ "$FROM_EXECROOT" = true ]; then
MAIN="$EXECROOT/$MAIN"
else
MAIN=TEMPLATED_entry_point_manifest_path
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to make the same logical fix in the .bzl file that calls the launcher, rather than change the shell script? If it is, then that's the better layer to make the change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be _nodejs_binary_impl. I wanted to reuse the logic to detect the execroot path, which is in the launcher. I'm not sure if there's another way to calculate it, or if it's even possible to move that logic to the rule implementation, since it seems to be based around detecting whether some paths exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexeagle any further comment here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah I think that makes sense.

@duarten
Copy link
Contributor Author

duarten commented Dec 15, 2020

ping :)

@alexeagle alexeagle merged commit 364ac89 into bazel-contrib:stable Dec 18, 2020
alexeagle pushed a commit that referenced this pull request Dec 18, 2020
NPM tools are currently run out of external/{md}/node_modules. If the
tool loads user-provided files in the execroot, which is the common
case, then this can lead to bad interactions.

Two examples of bad interactions are:
  1. A tool that loads React and the user code too,
     hooks becoming unusable.
  2. A tool that calls into a bundler like Webpack,
     potentially bundling duplicate packages.

Signed-off-by: Duarte Nunes <duarte@hey.com>
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.

2 participants