mjeanroy / rollup-plugin-license

Rollup plugin to add license banner to the final bundle and output third party licenses
MIT License
109 stars 21 forks source link

DocBlocks for Licenses #5

Closed ghost closed 7 years ago

ghost commented 7 years ago

JavaScript libraries have traditionally output doc blocks for licenses like the following, plucked from the 3.2.1 jQuery slim build:

/*! jQuery v3.2.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector | (c) JS Foundation and other contributors | jquery.org/license */

Notice the block is prefixed with /*!. IIRC this is a de facto standard originating as early as (if not earlier than) the YUI compressor, and was created to signal special handling of those blocks and to never strip them from code (for legal reasons).

Let us implement this in Rollup Plugin License.

mjeanroy commented 7 years ago

Hi @jhabdas,

I don't understand what is your request, I would be happy to help you but can you explain more? Would you like an option to generate in the final bundle a comment block starting with /*!?

Thanks!

ghost commented 7 years ago

Would you like an option to generate in the final bundle a comment block starting with /*!?

Perhaps, but I felt it better to start a discussion first as it's been a while since I've delved into this topic and wanted to open this issue to raise visibility.

I would be happy to help you but can you explain more?

https://github.com/yui/yuicompressor/blob/master/README.md#notes

C-style comments starting with /*! are preserved. This is useful with comments containing copyright/license information. As of 2.4.8, the '!' is no longer dropped by YUICompressor.

Other compressors, like Uglify for example, retain comments if they have @license (or maybe @copyright?) in a doc block, but that doesn't prevent post compressors, for example, from stripping licenses from inline JS when run through an HTML compressor in a CI process.

mjeanroy commented 7 years ago

I know how this prefix works, indeed it is already handled (see it here): if the license header you want to prepend to your bundle is already a block comment (starting with /** or /*!), it will just be prepended to the bundle as it is.

What you want here seems to use /*! to generate a block comment if it's not one already. I'm not sure it should be the default, but I agree, it could probably be useful to add an option for that.

ghost commented 7 years ago

Here's the result. Works well and achieves what I was looking for. No modifications needed.

license({
  banner: `/*! My Module v<%= pkg.version %> Copyright (c) <%= moment().format('YYYY') %> Tom Jones @license ISC */`
})