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(terser): call terser binary instead of uglifyjs #1360

Merged
merged 2 commits into from
Nov 21, 2019

Conversation

josephperrott
Copy link
Collaborator

No description provided.

@buildsize
Copy link

buildsize bot commented Nov 20, 2019

File name Previous Size New Size Change
release.tar.gz 1014.52 KB 1015.37 KB 873 bytes (0%)

@josephperrott josephperrott requested review from alexeagle and Toxicable and removed request for alexeagle November 20, 2019 15:06
@josephperrott josephperrott added dependencies Pull requests that update a dependency file package:terser labels Nov 20, 2019
@josephperrott josephperrott marked this pull request as ready for review November 20, 2019 15:06
@gregmagolan
Copy link
Collaborator

Thanks for picking this up @josephperrott . That warning message was very spammy.

Copy link

@Toxicable Toxicable left a comment

Choose a reason for hiding this comment

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

Are there any major changes that we need to note going to v4?

@josephperrott
Copy link
Collaborator Author

@Toxicable the package.json file changed in this PR is actually the only time in this repo that terser 3.x is used. Elsewhere 4.x is already used, and the @bazel/terser package already has a peerDep of >4

I am unsure of what changes occured between the versions, but it seems that they already are accounted for in testing/usage

@@ -160,7 +160,7 @@ function main() {
const residual = argv.slice(outputArgIndex + 2);

// user override for the terser binary location. used in testing.
const terserBinary = process.env.TERSER_BINARY || require.resolve('terser/bin/uglifyjs')
const terserBinary = process.env.TERSER_BINARY || require.resolve('terser/bin/terser')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like terser/bin/terser was only added in terser 4.3.0 so this would break users that are on terser > 4.0 < 4.3.

We could either change the peer dep to be >= 4.3 but I think the better solution is to change the logic to this:

process.env.TERSER_BINARY || require.resolve('terser/bin/terser') || require.resolve('terser/bin/uglify')

in a try/catch (as require.resolve will throw if it doesn't find terser/bin/terser) and add a comment that terser/bin/terser is only available for >= 4.3.0

@@ -171,7 +171,7 @@ function main() {
if (!inputs.find(isDirectory) && inputs.length) {
// Inputs were only files
// Just use terser CLI exactly as it works outside bazel
require(terserBinary || 'terser/bin/uglifyjs');
require(terserBinary || 'terser/bin/terser');
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexeagle This should be fine as just require(terserBinary) right given that terserBinary is already resolved above?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why it needs another case here, maybe it's overabundance of caution. @soldair wrote that bit I think

@gregmagolan gregmagolan self-requested a review November 21, 2019 01:30
Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

LGTM. The fake_mac_rbe on buildkite failure is not related. Will fix that up tonight.

@gregmagolan gregmagolan merged commit a100420 into bazel-contrib:master Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants