Gathering detailed insights and metrics for @vertigis/rollup-plugin-license
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
Gathering detailed insights and metrics for @vertigis/rollup-plugin-license
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
npm install @vertigis/rollup-plugin-license
60.1
Supply Chain
97.3
Quality
78.1
Maintenance
100
Vulnerability
97.3
License
2,103 Commits
1 Watching
5 Branches
4 Contributors
Updated on 30 Apr 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
0%
5
Compared to previous week
Last month
-47.6%
11
Compared to previous month
Last year
0%
172
Compared to previous year
9
1
32
Adds exclude property to the third party options.
Rollup plugin that can be used to:
Install the plugin with NPM:
npm install --save-dev rollup-plugin-license
Then add it to your rollup configuration:
1const path = require('path'); 2const license = require('rollup-plugin-license'); 3 4module.exports = { 5 plugins: [ 6 license({ 7 sourcemap: true, 8 cwd: process.cwd(), // The default 9 10 banner: { 11 commentStyle: 'regular', // The default 12 13 content: { 14 file: path.join(__dirname, 'LICENSE'), 15 encoding: 'utf-8', // Default is utf-8 16 }, 17 18 // Optional, may be an object or a function returning an object. 19 data() { 20 return { 21 foo: 'foo', 22 }; 23 }, 24 }, 25 26 thirdParty: { 27 includePrivate: true, // Default is false. 28 // Optional. Accepts strings and RegExp. 29 exclude: ["packageName", /rollup-plugin.*/], 30 output: { 31 file: path.join(__dirname, 'dist', 'dependencies.txt'), 32 encoding: 'utf-8', // Default is utf-8. 33 }, 34 }, 35 }), 36 ], 37}
The banner file can be a text file and it will be converted to a block comment automatically if needed.
Note that the content will be translated to a lodash template with the following data model:
pkg
: The content of the project package.json
.dependencies
: An array of all the dependencies included in the bundle.moment
: The moment
object._
: The lodash object.data
A custom data object, defined in banner options.Here is a valid banner:
1Bundle of <%= pkg.name %> 2Generated: <%= moment().format('YYYY-MM-DD') %> 3Version: <%= pkg.version %> 4Dependencies: 5<% _.forEach(dependencies, function (dependency) { %> 6 <%= dependency.name %> -- <%= dependency.version %> 7<% }) %>
Since version 0.10.0, it is possible to customize banner style using the commentStyle
option:
1license({ 2 banner: { 3 commentStyle: 'regular', // The default 4 content: { 5 file: path.join(__dirname, 'LICENSE'), 6 }, 7 }, 8})
Following options are available:
regular
: "classic" comment block is used (this is the default), for example:1/** 2 * This is the `regular` style. 3 */
ignored
: a comment block with prefix ignored by minifiers, for example:1/*! 2 * This is the `ignored` style. 3 */
slash
: banner is prepended using "slash" comments, for example:1// 2// This is the `slash` style. 3//
none
: nothing done, be careful to prepenbd a banner already "commented".Since version 0.3.0, banner
can be a simple string that will be used directly:
1const license = require('rollup-plugin-license'); 2 3module.exports = { 4 plugins: [ 5 license({ 6 banner: `Copyright <%= moment().format('YYYY') %>`, 7 }), 8 ], 9}
If you want to add some options to banner (such as the comment style to use), and still define it as a string
(insead of pointing to a file), you can also define the banner like this (since version 0.11.0
):
1const license = require('rollup-plugin-license'); 2 3module.exports = { 4 plugins: [ 5 license({ 6 banner: { 7 content: `Copyright <%= moment().format('YYYY') %>`, 8 commentStyle: 'ignored', 9 }, 10 }), 11 ], 12}
Until version 0.10.0, banner file was defined as:
1const path = require('path'); 2const license = require('rollup-plugin-license'); 3 4module.exports = { 5 plugins: [ 6 license({ 7 banner: { 8 file: path.join(__dirname, 'LICENSE'), 9 encoding: 'utf-8', 10 }, 11 }), 12 ], 13};
This format has been deprecated with version 0.11.0 and removed with version 1.0.O, and the banner file should be defined inside banner.content
entry:
1const path = require('path'); 2const license = require('rollup-plugin-license'); 3 4module.exports = { 5 plugins: [ 6 license({ 7 banner: { 8 content: { 9 file: path.join(__dirname, 'LICENSE'), 10 encoding: 'utf-8', 11 }, 12 }, 13 }), 14 ], 15};
A file containing a summary of all dependencies can be generated automatically using the following options:
1license({ 2 thirdParty: { 3 output: path.join(__dirname, 'dist', 'dependencies.txt'), 4 includePrivate: true, // Default is false. 5 }, 6})
Starting with version 0.12.0
, you can have more control by defining output
as an object, for example:
1license({ 2 thirdParty: { 3 includePrivate: false, 4 output: { 5 file: path.join(__dirname, 'dist', 'dependencies.txt'), // Path of the license report 6 encoding: 'utf-8', // default is UTF-8 7 8 // Template function that can be defined to customize report output 9 template(dependencies) { 10 return dependencies.map((dependency) => `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\n'); 11 }, 12 }, 13 }, 14})
Note that the template option can also be a lodash template:
1license({ 2 thirdParty: { 3 includePrivate: false, 4 output: { 5 file: path.join(__dirname, 'dist', 'dependencies.txt'), 6 7 // Lodash template that can be defined to customize report output 8 template: ` 9 <% _.forEach(dependencies, function (dependency) { %> 10 <%= dependency.name %>:<%= dependency.version%> -- <%= dependency.license %> 11 <% }) %> 12 `, 13 }, 14 }, 15})
For example, it can be relatively easy to produce a JSON output instead of a text file:
1license({ 2 thirdParty: { 3 includePrivate: false, 4 output: { 5 file: path.join(__dirname, 'dist', 'dependencies.json'), 6 template(dependencies) { 7 return JSON.stringify(dependencies); 8 } 9 }, 10 }, 11})
Starting with version 0.13, it is possible to ensure that dependencies does not violate any license restriction. For example, suppose you want to limit dependencies with MIT or Apache-2.0 licenses, simply define the restriction such as:
1license({ 2 thirdParty: { 3 allow: '(MIT OR Apache-2.0)', 4 }, 5})
Note that the allow
value here should be a valid SPDX pattern (more information here).
The allow
option here will print a warning to the console for all license violation. Note that, if you want more control, it can also be defined as function:
1license({ 2 thirdParty: { 3 allow(dependency) { 4 return dependency.license === 'MIT'; 5 }, 6 }, 7})
The function defined here allow only MIT licenses, and will print a warning for anything else.
Finally, if emitting a warning is not enought for you, you can also choose to fail the build:
1license({ 2 thirdParty: { 3 allow: { 4 test: 'MIT', // Or a function that should returns `true` or `false` 5 failOnUnlicensed: true, // Fail if a dependency does not specify any licenses, default is `false` 6 failOnViolation: true, // Fail if a dependency specify a license that does not match given requirement, default is `false` 7 }, 8 }, 9})
LICENCE
or LICENSE
files (PR), thanks @codepunkt!output
configuration (see #379).thirdParty.encoding
option.NULL
character (see #1).sourceMap
option (use sourcemap
option in lowercase) to keep it consistent with rollup.cwd
option to specify custom working directory (optional option).commenting
dependency.sourcemap
option).sourcemp
is used instead of the "global" one in rollup options.moment
).magic-string
).MIT License (MIT)
If you find a bug or think about enhancement, feel free to contribute and submit an issue or a pull request.
No vulnerabilities found.
No security vulnerabilities found.