From 7d13ce5a9fc4665e63c49d97b3c9142a368eda88 Mon Sep 17 00:00:00 2001 From: Unai Date: Fri, 30 Aug 2019 12:41:10 +0200 Subject: [PATCH] Reject sourcemap before sending it to uglify (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Reject sourcemap before sending it to uglify At some point today, our builds started failing with a sourcemap error from this lib. Running the tests here makes it replicable: ``` ● allow to disable source maps DefaultsError: `sourcemap` is not a supported option at DefaultsError.get (eval at (node_modules/uglify-js/tools/node.js:20:1), :71:23) ``` This fixes the error by rejecting the option uglify is now rejecting before the whole thing crashes. * Use delete to mutate options object instead of a new copy * Upgrade serialize-javascript --- index.js | 18 +++++++++++------- package.json | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index dfb9df9..d5db5f0 100644 --- a/index.js +++ b/index.js @@ -7,13 +7,17 @@ function uglify(userOptions = {}) { throw Error("sourceMap option is removed, use sourcemap instead"); } - const minifierOptions = serialize( - Object.assign({}, userOptions, { - sourceMap: userOptions.sourcemap !== false, - sourcemap: undefined, - numWorkers: undefined - }) - ); + const normalizedOptions = Object.assign({}, userOptions, { + sourceMap: userOptions.sourcemap !== false + }); + + ["sourcemap"].forEach(key => { + if (normalizedOptions.hasOwnProperty(key)) { + delete normalizedOptions[key]; + } + }); + + const minifierOptions = serialize(normalizedOptions); return { name: "uglify", diff --git a/package.json b/package.json index a819445..6a9fc44 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dependencies": { "@babel/code-frame": "^7.0.0", "jest-worker": "^24.0.0", - "serialize-javascript": "^1.6.1", + "serialize-javascript": "^1.9.0", "uglify-js": "^3.4.9" }, "peerDependencies": {