Skip to content

Commit

Permalink
fix(terser): call terser binary instead of uglifyjs (#1360)
Browse files Browse the repository at this point in the history
* fix(terser): call terser binary instead of uglifyjs

* fixup! fix(terser): call terser binary instead of uglifyjs
  • Loading branch information
josephperrott authored and gregmagolan committed Nov 21, 2019
1 parent 0672533 commit a100420
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"sinon": "^7.3.2",
"source-map": "^0.7.3",
"source-map-support": "0.5.9",
"terser": "3.17.0",
"terser": "^4.4.0",
"testy": "file:./tools/npm_packages/testy",
"tmp": "0.1.0",
"tsickle": "0.33.1",
Expand Down
13 changes: 10 additions & 3 deletions packages/terser/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ function main() {
const output = argv[outputArgIndex + 1];
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')
// Allow for user to override terser binary for testing.
let terserBinary = process.env.TERSER_BINARY;
try {
// If necessary, get the new `terser` binary, added for >=4.3.0
terserBinary = terserBinary || require.resolve('terser/bin/terser');
} finally {
// If necessary, get the old `uglifyjs` binary from <4.3.0
terserBinary = terserBinary || require.resolve('terser/bin/uglifyjs');
}
// choose a default concurrency of the number of cores -1 but at least 1.

log_verbose(`Running terser/index.js
Expand All @@ -171,7 +178,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);

} else if (inputs.length > 1) {
// We don't know how to merge multiple input dirs to one output dir
Expand Down

0 comments on commit a100420

Please sign in to comment.