Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

fix(index): don't remove legal comments by default (options.extractComments) #250

Merged
merged 1 commit into from Mar 16, 2018

Conversation

alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented Mar 6, 2018

@@ -85,7 +122,7 @@ describe('when options.extractComments', () => {
source: () => '// Comment\nvar foo = 1;',
},
'test1.js': {
source: () => '/* Comment */\nvar foo = 1;',
source: () => '/*! Legal Comment */\nvar foo = 1;',
Copy link
Member Author

Choose a reason for hiding this comment

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

Also fix basic test, because /* Comment */ is not legal comment and test1.js.LICENSE is empty, but we expect below what test1.js.LICENSE is not empty

@alexander-akait
Copy link
Member Author

Also need refactor tests, but we can do this before next minor/major release, i will send PR in future

src/index.js Outdated
@@ -22,7 +22,7 @@ class UglifyJsPlugin {
uglifyOptions = {},
test = /\.js$/i,
warningsFilter = () => true,
extractComments = false,
extractComments = true,
Copy link
Member

Choose a reason for hiding this comment

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

This would produce a name.js.LICENSE file by default or just preserves the comments within the file ? Is it really necessary to produce this file by default instead of opt-in if needed ?

semver-ness is also debatable here...

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky yep, it is output name.js.LICENSE file, same as in @0.4.6 version

Copy link
Member

Choose a reason for hiding this comment

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

Was outputting the file.js.LICENSE the default in v0.4.6 ? I can't remember... 😄 and if so do we really want it to be the default ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky ok let's test this 😄 i will put screen shot 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky i was right 😄
screenshot from 2018-03-07 22-08-27

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky Good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky from slack

sokra [4:27 PM]
I would keep comments in code by default. LICENSE file by default could be confusing for users and the benefit is small...

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@julmot WIP 👍

@michael-ciniawsky michael-ciniawsky changed the title fix: don't remove legal comments by default fix(index): don't remove legal comments by default Mar 7, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix(index): don't remove legal comments by default fix(index): don't remove legal comments by default (options.extractComments) Mar 7, 2018
@michael-ciniawsky
Copy link
Member

Also need refactor tests, but we can do this before next minor/major release, i will send PR in future

#200 (needs a rebase)

@alexander-akait
Copy link
Member Author

@michael-ciniawsky friendly ping. Also:

  • Refactor tests for readability.
  • Add tests when extractComments is not specify

@@ -42,7 +42,7 @@ class UglifyJsPlugin {
exclude,
uglifyOptions: {
output: {
comments: false,
comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be just the {RegExp} to always preserve this comments ? Why is the extractComments check needed here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky When we use extractComments we should remove their from source code. If you pass extractComments: true and comments: /^\**!|@preserve|@license|@cc_on/ output will be contain legal comments in source file and generate name.js.LICENSE file

Copy link
Member

Choose a reason for hiding this comment

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

Isn't extractComments not only responsible for only extracting what's preseverd via uglifyOptions.output.comments ?

// Preserve comments based on options, 
// defaults to /^\**!|@preserve|@license|@cc_on/
if (uglifyOptions.output.comments) {
   // Extract all preserved comments
   if (options.extractComments) {
       // [name].js.LICENSE
       extractComments()
   }
   // Leave comments in the source 
}

Why is are these options 'decoupled' ? 🙃

Anyways if that's more complicated atm and this PR now leaves the default preserved comments in the source aswell as options.extractComments also preserves the same default comments (with it's own logic) when extracting them into a separate file, then let's do it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-ciniawsky extractComments does not responsible uglify comments, they are separatly. If think about your logic. But sometimes people leave comment in source code and generate license file to allow difference type of distribution.

@psulek
Copy link

psulek commented Mar 16, 2018

@evilebottnawi In which version of uglifyjs-webpack-plugin will this be published? In current latest version 1.2.3 it does not work.

@michael-ciniawsky
Copy link
Member

@evilebottnawi There is nothing left to do here for the moment right ? :) In case there is please chime in, otherwise I will land and release this today...

@alexander-akait
Copy link
Member Author

@michael-ciniawsky let's release 👍

@michael-ciniawsky
Copy link
Member

Released in v1.2.4 🎉

@michael-ciniawsky michael-ciniawsky removed this from the 1.2.5 milestone Mar 16, 2018
@psulek
Copy link

psulek commented Mar 16, 2018

@michael-ciniawsky at npm there is still 1.2.3 version. Am i too fast ?

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 16, 2018

https://status.npmjs.org/incidents/gbk5bjx1169j
npm/npm#20077

Resolved :)

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

Successfully merging this pull request may close these issues.

None yet

4 participants