Skip to content

Commit

Permalink
[core] Fix breaking change in upstream terser dependency (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Feb 3, 2019
1 parent 01b6b86 commit 38438a7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/@sanity/core/src/actions/build/compressJavascript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fse from 'fs-extra'
import Terser from 'terser'
import Terser, {minify as minifyJs} from 'terser'

export default async inputFile => {
const content = await fse.readFile(inputFile, 'utf8')
Expand All @@ -9,7 +9,17 @@ export default async inputFile => {

function minify(content, fileName) {
return new Promise((resolve, reject) => {
const result = Terser.minify(content)
// Terser introduced a breaking API change in a patch version
// In case they revert or people are using an older version,
// try both combinations
let result
if (minifyJs) {
result = minifyJs(content)
} else if (Terser.minify) {
result = Terser.minify(content)
} else {
return reject(new Error('Breaking change in Terser - `minify` function not found'))
}

if (result.error) {
reject(formatError(result.error, fileName, content))
Expand Down

0 comments on commit 38438a7

Please sign in to comment.