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

fix: add support for terser 5 under node 12 and higher #2558

Merged
merged 1 commit into from
Apr 18, 2021

Conversation

Aghassi
Copy link
Contributor

@Aghassi Aghassi commented Mar 26, 2021

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?

On Node 14 with Terser 5, Terser binary will fail to to be found as require.resolve will error out. See terser/terser#971

Issue Number: N/A

What is the new behavior?

We will fall through and attempt to do different resolve logic based on the version of Node

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Mar 26, 2021
@Aghassi Aghassi force-pushed the fix/support-terser-5 branch from 130a0c2 to 58a30c3 Compare March 26, 2021 21:27
@Aghassi Aghassi marked this pull request as ready for review March 26, 2021 21:28
@Aghassi Aghassi force-pushed the fix/support-terser-5 branch from 58a30c3 to f85bb87 Compare March 29, 2021 23:04
@Aghassi Aghassi force-pushed the fix/support-terser-5 branch from f85bb87 to 94f61ad Compare March 30, 2021 18:19
terserBinary = terserBinary || require.resolve('terser/bin/terser');
// Node 12 and above will respect exports field in package.json, Terser 5 added these
// `process.version` returns vx.x.x, here we strip the `v` and get the major number
if (process.version.split('.')[0].replace('v', '') <= '10') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

look around the repo for other js code that does semver parse, there's probably a more reliable way. I'm worried that this is doing string comparison rather than numbers

// If necessary, get the new `terser` binary, added for >=4.3.0 <5
terserBinary = terserBinary || require.resolve('terser/bin/terser');
} else {
// Terser 5 with Node 12 or higher breaks compatiability with how Rules NodeJS supports
Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment is confusing, is this branch specific to terser 5? or just node 12 and up?

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

okay my nits aren't that important, let's get this fixed

@alexeagle alexeagle merged commit bd53eb5 into bazel-contrib:stable Apr 18, 2021
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