Skip to content

fix(builtin): remove unnecessary loader script - #3493

Closed
kormide wants to merge 1 commit into
stablefrom
remove-loader-script
Closed

fix(builtin): remove unnecessary loader script#3493
kormide wants to merge 1 commit into
stablefrom
remove-loader-script

Conversation

@kormide

@kormide kormide commented Jun 23, 2022

Copy link
Copy Markdown
Collaborator

FYI: @devversion

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: Related to #3277

ESM scripts couldn't be used with nodejs_binary when --nobazel_run_linker was set. This is because the loader script is always a .cjs file.

What is the new behavior?

Remove the loader script as it no longer seems to be necessary. It would be helpful if someone with more historical context could verify this.

Does this PR introduce a breaking change?

  • Yes
  • No

@kormide
kormide force-pushed the remove-loader-script branch 3 times, most recently from f09854b to 979223f Compare June 23, 2022 07:17

@devversion devversion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not an approver, but nice!!

@kormide
kormide force-pushed the remove-loader-script branch 3 times, most recently from 1b3bd9f to 4633d84 Compare June 23, 2022 20:38
Comment thread internal/node/loader.cjs
Comment on lines -23 to -24
process.env.PATH = [require('path').dirname(process.execPath), process.env.PATH].join(
/^win/i.test(process.platform) ? ';' : ':');

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kormide
kormide force-pushed the remove-loader-script branch from 4633d84 to e7c9b3d Compare June 23, 2022 22:33
@kormide

kormide commented Jun 23, 2022

Copy link
Copy Markdown
Collaborator Author

I thought this was working but it was a false positive. The problem is that our require patch only works for node's cjs loader, not their esm loader. If we want to support esm scripts with the linker disabled, we'll need a similar monkey patch for esm.

@kormide kormide closed this Jun 23, 2022
devversion added a commit to devversion/angular that referenced this pull request Jul 11, 2022
The integration test rule now always executes tests in a directory
outside of the execroot. This ensures a more hermetic test environment
on platforms without a sandbox, or when tests are run with `tags:
local`.

As part of this change, an issue with Yarn 1.x. and `nodejs_binary`
unveiled. Yarn 1.x. is resolved properly using the tool mapping but
when Yarn inside Yarn is invoked (e.g. using `package.json` scripts),
then the second nested Yarn invocation fails due to an unknown path.

This happens because Yarn in the original invocation creates another
directory in the `/tmp` directory and modifies the `PATH` so that
the same `yarn` can be invoked again. This makes sense conceptually
but breaks in our case because the Yarn Bash script put into the `/tmp`
directory tries to resolve our vendored Yarn script relatively (which
is the wrong spot here). It worked previously in the execroot because
`nodejs_binary` invoked Yarn through `<external>/../node.sh
<absolute-path-to-yarn-cjs-script>`, but outside the execroot it invoked
Yarn using a relative path (which then ended up being preserved in the
Yarn temporary directory).

We can fix this by updating the Bazel NodeJS repository which seems to
have coincidentally have a fix for the path resolution. See:

bazel-contrib/rules_nodejs#3493 (comment).
jessicajaniuk pushed a commit to angular/angular that referenced this pull request Jul 11, 2022
The integration test rule now always executes tests in a directory
outside of the execroot. This ensures a more hermetic test environment
on platforms without a sandbox, or when tests are run with `tags:
local`.

As part of this change, an issue with Yarn 1.x. and `nodejs_binary`
unveiled. Yarn 1.x. is resolved properly using the tool mapping but
when Yarn inside Yarn is invoked (e.g. using `package.json` scripts),
then the second nested Yarn invocation fails due to an unknown path.

This happens because Yarn in the original invocation creates another
directory in the `/tmp` directory and modifies the `PATH` so that
the same `yarn` can be invoked again. This makes sense conceptually
but breaks in our case because the Yarn Bash script put into the `/tmp`
directory tries to resolve our vendored Yarn script relatively (which
is the wrong spot here). It worked previously in the execroot because
`nodejs_binary` invoked Yarn through `<external>/../node.sh
<absolute-path-to-yarn-cjs-script>`, but outside the execroot it invoked
Yarn using a relative path (which then ended up being preserved in the
Yarn temporary directory).

We can fix this by updating the Bazel NodeJS repository which seems to
have coincidentally have a fix for the path resolution. See:

bazel-contrib/rules_nodejs#3493 (comment).

PR Close #46778
jessicajaniuk pushed a commit to angular/angular that referenced this pull request Jul 11, 2022
The integration test rule now always executes tests in a directory
outside of the execroot. This ensures a more hermetic test environment
on platforms without a sandbox, or when tests are run with `tags:
local`.

As part of this change, an issue with Yarn 1.x. and `nodejs_binary`
unveiled. Yarn 1.x. is resolved properly using the tool mapping but
when Yarn inside Yarn is invoked (e.g. using `package.json` scripts),
then the second nested Yarn invocation fails due to an unknown path.

This happens because Yarn in the original invocation creates another
directory in the `/tmp` directory and modifies the `PATH` so that
the same `yarn` can be invoked again. This makes sense conceptually
but breaks in our case because the Yarn Bash script put into the `/tmp`
directory tries to resolve our vendored Yarn script relatively (which
is the wrong spot here). It worked previously in the execroot because
`nodejs_binary` invoked Yarn through `<external>/../node.sh
<absolute-path-to-yarn-cjs-script>`, but outside the execroot it invoked
Yarn using a relative path (which then ended up being preserved in the
Yarn temporary directory).

We can fix this by updating the Bazel NodeJS repository which seems to
have coincidentally have a fix for the path resolution. See:

bazel-contrib/rules_nodejs#3493 (comment).

PR Close #46778
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants