Skip to content

Commit

Permalink
Reject sourcemap before sending it to uglify (#63)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
uorbe001 authored and TrySound committed Aug 30, 2019
1 parent aa945a7 commit 7d13ce5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions index.js
Expand Up @@ -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

This comment has been minimized.

Copy link
@kav137

kav137 Aug 30, 2019

@uorbe001 do you know the reason why uglify started to reject "sourcemap" parameter? I didn't find any relevant changes in uglify

BTW, thanks for fix :)

This comment has been minimized.

Copy link
@TrySound

TrySound Aug 30, 2019

Owner
});

["sourcemap"].forEach(key => {
if (normalizedOptions.hasOwnProperty(key)) {
delete normalizedOptions[key];
}
});

const minifierOptions = serialize(normalizedOptions);

return {
name: "uglify",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down

0 comments on commit 7d13ce5

Please sign in to comment.