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

fix: license files now have .txt suffix by default #210

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ Default: `true`

Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a)).
By default extract only comments using `/^\**!|@preserve|@license|@cc_on/i` regexp condition and remove remaining comments.
If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE`.
If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE.txt`.
The `terserOptions.output.comments` option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.

#### `Boolean`
Expand Down Expand Up @@ -500,7 +500,7 @@ module.exports = {
// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
// You must consider this
// The "fileData" argument contains object with "filename", "basename", "query"
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE$2');
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE.txt$2');
},
banner: (licenseFile) => {
return `License information can be found in ${licenseFile}`;
Expand Down Expand Up @@ -533,7 +533,7 @@ module.exports = {

// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
// You must consider this
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE$2');
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE.txt$2');
},
banner: (licenseFile) => {
return `License information can be found in ${licenseFile}`;
Expand All @@ -548,12 +548,12 @@ module.exports = {
##### `filename`

Type: `String|Function<(string) -> String>`
Default: `[file].LICENSE[query]`
Default: `[file].LICENSE.txt[query]`

Available placeholders: `[file]`, `[query]` and `[filebase]` (`[base]` for webpack 5).

The file where the extracted comments will be stored.
Default is to append the suffix `.LICENSE` to the original filename.
Default is to append the suffix `.LICENSE.txt` to the original filename.

**webpack.config.js**

Expand Down Expand Up @@ -600,7 +600,7 @@ module.exports = {

// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
// You must consider this
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE$2');
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE.txt$2');
},
banner: (commentsFile) => {
return `My custom banner about license information ${commentsFile}`;
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class TerserPlugin {

if (this.options.extractComments) {
commentsFilename =
this.options.extractComments.filename || '[file].LICENSE[query]';
this.options.extractComments.filename ||
'[file].LICENSE.txt[query]';

if (TerserPlugin.isWebpack4()) {
// Todo remove this in next major release
Expand Down
448 changes: 224 additions & 224 deletions test/__snapshots__/extractComments-option.test.js.snap.webpack4

Large diffs are not rendered by default.

448 changes: 224 additions & 224 deletions test/__snapshots__/extractComments-option.test.js.snap.webpack5

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/__snapshots__/terserOptions-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ exports[`terserOptions option should match snapshot for the "compress" option wi

exports[`terserOptions option should match snapshot for the "compress" option with the "false" value: assets 1`] = `
Object {
"main.js": "/*! For license information please see main.js.LICENSE */
"main.js": "/*! For license information please see main.js.LICENSE.txt */
(function(e){var t={};function r(n){if(t[n]){return t[n].exports}var o=t[n]={i:n,l:false,exports:{}};e[n].call(o.exports,o,o.exports,r);o.l=true;return o.exports}r.m=e;r.c=t;r.d=function(e,t,n){if(!r.o(e,t)){Object.defineProperty(e,t,{enumerable:true,get:n})}};r.r=function(e){if(typeof Symbol!==\\"undefined\\"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"})}Object.defineProperty(e,\\"__esModule\\",{value:true})};r.t=function(e,t){if(t&1)e=r(e);if(t&8)return e;if(t&4&&typeof e===\\"object\\"&&e&&e.__esModule)return e;var n=Object.create(null);r.r(n);Object.defineProperty(n,\\"default\\",{enumerable:true,value:e});if(t&2&&typeof e!=\\"string\\")for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n};r.n=function(e){var t=e&&e.__esModule?function t(){return e[\\"default\\"]}:function t(){return e};r.d(t,\\"a\\",t);return t};r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};r.p=\\"\\";return r(r.s=0)})([function(e,t){const r=2+2;e.exports=function e(){const t=2+2;console.log(t+1+2)}}]);",
"main.js.LICENSE": "/* @preserve*/
"main.js.LICENSE.txt": "/* @preserve*/
",
}
`;
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/terserOptions-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ exports[`terserOptions option should match snapshot for the "compress" option wi

exports[`terserOptions option should match snapshot for the "compress" option with the "false" value: assets 1`] = `
Object {
"main.js": "/*! For license information please see main.js.LICENSE */
"main.js": "/*! For license information please see main.js.LICENSE.txt */
(()=>{var o={791:o=>{const r=2+2;o.exports=function o(){const r=2+2;console.log(r+1+2)}}};var r={};function t(n){if(r[n]){return r[n].exports}var e=r[n]={exports:{}};o[n](e,e.exports,t);return e.exports}t(791)})();",
"main.js.LICENSE": "/* @preserve*/
"main.js.LICENSE.txt": "/* @preserve*/
",
}
`;
Expand Down
6 changes: 3 additions & 3 deletions test/extractComments-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ function createFilenameFn() {

// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
// You must consider this
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE$2');
return file.replace(/\.(\w+)($|\?)/, '.$1.LICENSE.txt$2');
}
: (fileData) => {
expect(fileData).toBeDefined();

// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
// You must consider this
return `${fileData.filename}.LICENSE${fileData.query}`;
return `${fileData.filename}.LICENSE.txt${fileData.query}`;
};
}

Expand Down Expand Up @@ -309,7 +309,7 @@ describe('extractComments option', () => {
new TerserPlugin({
extractComments: {
condition: true,
filename: `[file].LICENSE?query=[query]&filebase=[${
filename: `[file].LICENSE.txt?query=[query]&filebase=[${
getCompiler.isWebpack4() ? 'filebase' : 'base'
}]`,
banner(licenseFile) {
Expand Down