Skip to content

Commit 7d13ce5

Browse files
uorbe001TrySound
authored andcommitted
Reject sourcemap before sending it to uglify (#63)
* 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 <anonymous> (node_modules/uglify-js/tools/node.js:20:1), <anonymous>: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
1 parent aa945a7 commit 7d13ce5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ function uglify(userOptions = {}) {
77
throw Error("sourceMap option is removed, use sourcemap instead");
88
}
99

10-
const minifierOptions = serialize(
11-
Object.assign({}, userOptions, {
12-
sourceMap: userOptions.sourcemap !== false,
13-
sourcemap: undefined,
14-
numWorkers: undefined
15-
})
16-
);
10+
const normalizedOptions = Object.assign({}, userOptions, {
11+
sourceMap: userOptions.sourcemap !== false
12+
});
13+
14+
["sourcemap"].forEach(key => {
15+
if (normalizedOptions.hasOwnProperty(key)) {
16+
delete normalizedOptions[key];
17+
}
18+
});
19+
20+
const minifierOptions = serialize(normalizedOptions);
1721

1822
return {
1923
name: "uglify",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"dependencies": {
2727
"@babel/code-frame": "^7.0.0",
2828
"jest-worker": "^24.0.0",
29-
"serialize-javascript": "^1.6.1",
29+
"serialize-javascript": "^1.9.0",
3030
"uglify-js": "^3.4.9"
3131
},
3232
"peerDependencies": {

0 commit comments

Comments
 (0)