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

Update UglifyJSPlugin transformation #401

Merged
merged 9 commits into from
Apr 18, 2018
Merged

Update UglifyJSPlugin transformation #401

merged 9 commits into from
Apr 18, 2018

Conversation

matheus1lva
Copy link
Member

What kind of change does this PR introduce?
Feature

Did you add tests for your changes?
Yes.
Tests included to test scenarios where:

  • User was using webpack.optimize.UglifyJsPlugin without custom options
  • User was using webpack.optimize.UglifyJsPlugin with custom options
  • User was using uglify-webpack-plugin with custom options
  • User was using uglify-webpack-plugin without custom options

Summary
Fix #389

Does this PR introduce a breaking change?
Yes. It deprecates migration from v1->v2 and only supports v3->v4

@@ -2,36 +2,110 @@

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = `
"module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
Copy link
Member Author

Choose a reason for hiding this comment

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

I found a problem here, something i left behind... i'm fixing it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

.filter(j.filters.VariableDeclarator.requiresModule("uglifyjs-webpack-plugin"));

// Look for a variable declaration which requires uglifyjs-webpack-plugin
// saves the name of this variable.
Copy link
Member

Choose a reason for hiding this comment

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

Multi line comment here

// options passed to plugin
const pluginOptions = node.value.arguments;

// check if there are any options passed to UglifyWebpackPlugin
Copy link
Member

Choose a reason for hiding this comment

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

ML comment.

// If user is using UglifyJsPlugin directly from webpack
// transformation must:
// - remove it
// - add require for uglify-webpack-plugin
Copy link
Member

Choose a reason for hiding this comment

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

  • .. -

sourceMap: true
})
]
plugins: [],
Copy link
Member

Choose a reason for hiding this comment

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

Why's this empty? Should be preserved when uglifyJSPlugin is correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed this cleanup. I'm going to create an utility to remove plugins property if they are empty, so it can be used by other transformations that fell into the same problem.

@webpack-bot
Copy link

@playma256 Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@ev1stensberg Please review the new changes.

@matheus1lva
Copy link
Member Author

I'm adding tests to this new method. I just messed up a bit, i'm fixing them.

@@ -90,6 +90,22 @@ exports[`utils createProperty should create properties for non-literal keys 1`]
}"
`;

exports[`utils findPluginsArrayAndRemoveIfEmpty should not remove plugins property, since it has length > 0 1`] = `
Copy link
Member

Choose a reason for hiding this comment

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

Use proper grammar here.

* remove if it has no elements.
* @param {any} j - jscodeshift API
* @param {Node} rootNode - node to start search from
*/
Copy link
Member

Choose a reason for hiding this comment

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

Missing jsdoc for return here

Copy link
Contributor

Choose a reason for hiding this comment

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

It lookouts for the plugins property and, the array is empty, it removes it from the AST

optimization: {
minimize: true,

minimizer: [new UglifyJsPlugin({
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? Could you link me to the docs on this?

Copy link
Contributor

@ematipico ematipico Apr 15, 2018

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oki, good stuff

@matheus1lva
Copy link
Member Author

All the small fixes which were required are done!

@webpack-bot
Copy link

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@ematipico ematipico added the Semver: minor ⚙️ When delivering new features that don't break label Apr 16, 2018
@evenstensberg evenstensberg merged commit 65c46e0 into webpack:master Apr 18, 2018
@matheus1lva matheus1lva deleted the feature/v3-v4-uglifyJs branch April 18, 2018 12:22
@matheus1lva matheus1lva restored the feature/v3-v4-uglifyJs branch April 23, 2018 18:07
@matheus1lva
Copy link
Member Author

matheus1lva commented Apr 23, 2018

I was looking at this, to tell my workmates that they could use to upgrade the webpack config on their projects, but i was not able to see my commits on the uglifyjs migration, it seems to be in its original state (v1->v2).

What happened (@ematipico @ev1stensberg )?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: CI-ok PR: reviewed-approved Semver: minor ⚙️ When delivering new features that don't break
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants