Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject sourcemap before sending it to uglify #63

Merged
merged 3 commits into from
Aug 30, 2019
Merged

Reject sourcemap before sending it to uglify #63

merged 3 commits into from
Aug 30, 2019

Conversation

uorbe001
Copy link
Contributor

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. I have no idea what's changed today, as the option rejection has been in uglify for ages: https://github.com/mishoo/UglifyJS2/blob/v3.6.0/lib/utils.js#L93

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.
index.js Outdated
})
reject(Object.assign({}, userOptions, {
sourceMap: userOptions.sourcemap !== false
}), [ "sourcemap" ])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use delete operator.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Dependence of serialize-javascript update to 1.9.0, leads to uglify-js always fail,
the message is Error: "sourcemap is not a supported option"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TrySound updated

@TrySound
Copy link
Owner

Could you add test please

@uorbe001
Copy link
Contributor Author

@TrySound how do you suggest I write a test for it? The only change here is that this.worker.transform doesn't receive the offending params, and that object is instantiated by the index itself. The only way I can think of to test that properly would be to refactor the minifiedOptions out of the index and test that independently.

In terms of the params being sent to uglify being correct, the pre-existing tests should ensure that. I would even argue that "allow to disable source maps" covers this change, as it was failing before it.

@TrySound
Copy link
Owner

serialize-javascript upgrade in master gave me failing test. Please upgrade to get this change covered.

@uorbe001
Copy link
Contributor Author

Extracted the normalize in order to add a test for it, and upgraded serialize-javascript to 1.9.0.

test/test.js Outdated

test("normalizeOptions removes 'sourcemap'", async () => {
const normalizedOptions = normalizeOptions({ sourcemap: true })
expect(normalizedOptions).toEqual({ sourceMap: true });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't need unit test. The whole plugin should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove that commit then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's gone now

@TrySound TrySound merged commit 7d13ce5 into TrySound:master Aug 30, 2019
@TrySound
Copy link
Owner

Great! Thank you

@TrySound
Copy link
Owner

Published 6.0.3

@TrySound
Copy link
Owner

Also I recommend to use rollup-plugin-terser instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants