{"id":13774966,"url":"https://github.com/mjeanroy/rollup-plugin-license","last_synced_at":"2025-05-14T20:04:43.797Z","repository":{"id":38007973,"uuid":"74790739","full_name":"mjeanroy/rollup-plugin-license","owner":"mjeanroy","description":"Rollup plugin to add license banner to the final bundle and output third party licenses","archived":false,"fork":false,"pushed_at":"2025-04-01T09:40:46.000Z","size":1956,"stargazers_count":118,"open_issues_count":6,"forks_count":23,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T10:32:04.852Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjeanroy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-25T22:09:13.000Z","updated_at":"2025-04-01T09:40:42.000Z","dependencies_parsed_at":"2023-10-15T13:23:30.307Z","dependency_job_id":"84eafb9e-7ae2-4d94-bcca-f20f5e164f6b","html_url":"https://github.com/mjeanroy/rollup-plugin-license","commit_stats":{"total_commits":1443,"total_committers":17,"mean_commits":84.88235294117646,"dds":0.6826056826056826,"last_synced_commit":"30c6526f2c2a6b16c4d599dd3b267b04842c8b43"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjeanroy%2Frollup-plugin-license","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjeanroy%2Frollup-plugin-license/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjeanroy%2Frollup-plugin-license/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjeanroy%2Frollup-plugin-license/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjeanroy","download_url":"https://codeload.github.com/mjeanroy/rollup-plugin-license/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248384921,"owners_count":21094795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:32.313Z","updated_at":"2025-04-11T11:38:08.146Z","avatar_url":"https://github.com/mjeanroy.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Output"],"readme":"# rollup-plugin-license\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/mjeanroy/rollup-plugin-license.svg)](https://greenkeeper.io/)\n[![Build Status](https://travis-ci.org/mjeanroy/rollup-plugin-license.svg?branch=master)](https://travis-ci.org/mjeanroy/rollup-plugin-license)\n[![Npm version](https://badge.fury.io/js/rollup-plugin-license.svg)](https://badge.fury.io/js/rollup-plugin-license)\n\nRollup plugin that can be used to:\n- Prepend a banner from a file.\n- Create a file containing all third-parties used in the bundle (and display the license of each dependency).\n\n## How to use\n\nInstall the plugin with NPM:\n\n```npm install --save-dev rollup-plugin-license```\n\nThen add it to your rollup configuration:\n\n```javascript\nconst path = require('path');\nconst license = require('rollup-plugin-license');\n\nmodule.exports = {\n  plugins: [\n    license({\n      sourcemap: true,\n      cwd: process.cwd(), // The default\n\n      banner: {\n        commentStyle: 'regular', // The default\n\n        content: {\n          file: path.join(__dirname, 'LICENSE'),\n          encoding: 'utf-8', // Default is utf-8\n        },\n\n        // Optional, may be an object or a function returning an object.\n        data() {\n          return {\n            foo: 'foo',\n          };\n        },\n      },\n\n      thirdParty: {\n        includePrivate: true, // Default is false.\n        includeSelf: true, // Default is false.\n        multipleVersions: true, // Default is false.\n        output: {\n          file: path.join(__dirname, 'dist', 'dependencies.txt'),\n          encoding: 'utf-8', // Default is utf-8.\n        },\n      },\n    }),\n  ],\n}\n```\n\n## Banner\n\n### Banner file\n\nThe banner file can be a text file and it will be converted to a block comment automatically if needed.\n\nNote that the content will be translated to a lodash template with the following data model:\n- `pkg`: The content of the project `package.json`.\n- `dependencies`: An array of all the dependencies included in the bundle.\n- `moment`: The `moment` object.\n- `_`: The lodash object.\n- `data` A custom data object, defined in banner options.\n\nHere is a valid banner:\n\n```text\nBundle of \u003c%= pkg.name %\u003e\nGenerated: \u003c%= moment().format('YYYY-MM-DD') %\u003e\nVersion: \u003c%= pkg.version %\u003e\nDependencies:\n\u003c% _.forEach(dependencies, function (dependency) { %\u003e\n  \u003c%= dependency.name %\u003e -- \u003c%= dependency.version %\u003e\n\u003c% }) %\u003e\n```\n\n### Comment style\n\nSince version 0.10.0, it is possible to customize banner style using the `commentStyle` option:\n\n```javascript\nlicense({\n  banner: {\n    commentStyle: 'regular', // The default\n    content: {\n      file: path.join(__dirname, 'LICENSE'),\n    },\n  },\n})\n```\n\nFollowing options are available:\n\n- `regular`: \"classic\" comment block is used (this is the default), for example:\n\n```javascript\n/**\n * This is the `regular` style.\n */\n```\n\n- `ignored`: a comment block with prefix ignored by minifiers, for example:\n\n```javascript\n/*!\n * This is the `ignored` style.\n */\n```\n\n- `slash`: banner is prepended using \"slash\" comments, for example:\n\n```javascript\n//\n// This is the `slash` style.\n//\n```\n\n- `none`: nothing done, be careful to prepenbd a banner already \"commented\".\n\n### Banner as a \"simple\" string\n\nSince version 0.3.0, `banner` can be a simple string that will be used directly:\n\n```javascript\nconst license = require('rollup-plugin-license');\n\nmodule.exports = {\n  plugins: [\n    license({\n      banner: `Copyright \u003c%= moment().format('YYYY') %\u003e`,\n    }),\n  ],\n}\n```\n\nIf 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`):\n\n```javascript\nconst license = require('rollup-plugin-license');\n\nmodule.exports = {\n  plugins: [\n    license({\n      banner: {\n        content: `Copyright \u003c%= moment().format('YYYY') %\u003e`,\n        commentStyle: 'ignored',\n      },\n    }),\n  ],\n}\n```\n\n### Deprecated format\n\nUntil version 0.10.0, banner file was defined as:\n\n\n```javascript\nconst path = require('path');\nconst license = require('rollup-plugin-license');\n\nmodule.exports = {\n  plugins: [\n    license({\n      banner: {\n        file: path.join(__dirname, 'LICENSE'),\n        encoding: 'utf-8',\n      },\n    }),\n  ],\n};\n```\n\nThis 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:\n\n```javascript\nconst path = require('path');\nconst license = require('rollup-plugin-license');\n\nmodule.exports = {\n  plugins: [\n    license({\n      banner: {\n        content: {\n          file: path.join(__dirname, 'LICENSE'),\n          encoding: 'utf-8',\n        },\n      },\n    }),\n  ],\n};\n```\n\n## Dependencies output\n\nA file containing a summary of all dependencies can be generated automatically using the following options:\n\n```javascript\nlicense({\n  thirdParty: {\n    output: path.join(__dirname, 'dist', 'dependencies.txt'),\n    includePrivate: true, // Default is false.\n  },\n})\n```\n\nStarting with version `0.12.0`, you can have more control by defining `output` as an object, for example:\n\n```javascript\nlicense({\n  thirdParty: {\n    includePrivate: false,\n    output: {\n      file: path.join(__dirname, 'dist', 'dependencies.txt'), // Path of the license report\n      encoding: 'utf-8', // default is UTF-8\n\n      // Template function that can be defined to customize report output\n      template(dependencies) {\n        return dependencies.map((dependency) =\u003e `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\\n');\n      },\n    },\n  },\n})\n```\n\nNote that the template option can also be a lodash template:\n\n```javascript\nlicense({\n  thirdParty: {\n    includePrivate: false,\n    output: {\n      file: path.join(__dirname, 'dist', 'dependencies.txt'),\n\n      // Lodash template that can be defined to customize report output\n      template: `\n        \u003c% _.forEach(dependencies, function (dependency) { %\u003e\n          \u003c%= dependency.name %\u003e:\u003c%= dependency.version%\u003e -- \u003c%= dependency.license %\u003e\n        \u003c% }) %\u003e\n      `,\n    },\n  },\n})\n```\n\nFor example, it can be relatively easy to produce a JSON output instead of a text file:\n\n```javascript\nlicense({\n  thirdParty: {\n    includePrivate: false,\n    output: {\n      file: path.join(__dirname, 'dist', 'dependencies.json'),\n      template(dependencies) {\n        return JSON.stringify(dependencies);\n      }\n    },\n  },\n})\n```\n\nBy default, the \"self\" package is ignored (by \"self\", we mean the package being built), but startint with version 3.4.0, you can force inclusion using the `includeSelf` option:\n\n```javascript\nlicense({\n  thirdParty: {\n    includeSelf: true,\n    output: {\n      file: path.join(__dirname, 'dist', 'dependencies.json'),\n      template(dependencies) {\n        return JSON.stringify(dependencies);\n      }\n    },\n  },\n})\n```\n\n## License Checks\n\nStarting with version 0.13, it is possible to ensure that dependencies does not violate any license restriction.\nFor example, suppose you want to limit dependencies with MIT or Apache-2.0 licenses, simply define the restriction such as:\n\n```javascript\nlicense({\n  thirdParty: {\n    allow: '(MIT OR Apache-2.0)',\n  },\n})\n```\n\nNote that the `allow` value here should be a valid SPDX pattern (more information [here](https://www.npmjs.com/package/spdx-expression-validate)).\n\nThe `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:\n\n```javascript\nlicense({\n  thirdParty: {\n    allow(dependency) {\n      return dependency.license === 'MIT';\n    },\n  },\n})\n```\n\nThe function defined here allow only MIT licenses, and will print a warning for anything else.\n\nFinally, if emitting a warning is not enought for you, you can also choose to fail the build:\n\n```javascript\nlicense({\n  thirdParty: {\n    allow: {\n      test: 'MIT',             // Or a function that should returns `true` or `false`\n      failOnUnlicensed: true,  // Fail if a dependency does not specify any licenses, default is `false`\n      failOnViolation: true,   // Fail if a dependency specify a license that does not match given requirement, default is `false`\n    },\n  },\n})\n```\n\nStarting with version `3.1.0`, you can also use the `multipleVersions` option to track dependencies in different version as a different dependency.\nIt can be particularly useful in case a dependency changed its license between two versions.\n\nNote that this option is `false` by default (mainly to keep backward compatibility).\n\n```javascript\nlicense({\n  thirdParty: {\n    includePrivate: false,\n    multipleVersions: true,\n    output: {\n      file: path.join(__dirname, 'dist', 'dependencies.txt'), // Path of the license report\n      encoding: 'utf-8', // default is UTF-8\n      template(dependencies) {\n        return dependencies.map((dependency) =\u003e `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\\n');\n      },\n    },\n  },\n})\n```\n\n## Changelogs\n\n- 3.6.0\n  - Use semver versioning for the `fdir` dependency ([#1895](https://github.com/mjeanroy/rollup-plugin-license/pull/1895))\n  - Dependency upgrades\n- 3.5.0\n  - Remove `mkidrp` dependency ([#1743](https://github.com/mjeanroy/rollup-plugin-license/pull/1743))\n  - Replace `glob` with `fdir` dependency ([#1742](https://github.com/mjeanroy/rollup-plugin-license/pull/1742))\n  - Dependency upgrades\n- 3.4.1\n  - Add the license for the package itself without having to specify `includePrivate` flag (see [comment](https://github.com/mjeanroy/rollup-plugin-license/issues/1685#issuecomment-2110103508)).\n- 3.4.0\n  - Allow adding the license for the package itself into the thirdParty output [#1685](https://github.com/mjeanroy/rollup-plugin-license/issues/1685)\n  - Dependency upgrades\n- 3.3.1\n  - Ensure the `multipleVersions` option is correctly validated ([#1682](https://github.com/mjeanroy/rollup-plugin-license/issues/1682))\n- 3.3.0\n  - Include notice file in the third party output ([#1683](https://github.com/mjeanroy/rollup-plugin-license/issues/1683))\n  - Dependency upgrades\n- 3.2.0\n  - Support rollup ^4.0.0\n  - Dependency upgrades\n- 3.1.0\n  - Add `thirdParty.multipleVersions` option ([#1528](https://github.com/mjeanroy/rollup-plugin-license/pull/1528))\n- 3.0.0\n  - Support rollup^3.0.0\n- 2.8.0\n  - Relax production dependency versions ([#1128]()https://github.com/mjeanroy/rollup-plugin-license/issues/1128)\n  - Update dependencies\n- 2.7.0\n  - Update dependencies ([#1077](https://github.com/mjeanroy/rollup-plugin-license/issues/1077))\n- 2.6.0\n  - Improve case insensitive search ([PR](https://github.com/mjeanroy/rollup-plugin-license/pull/931)), thanks [@codepunkt](https://github.com/codepunkt)!\n  - Search for `LICENCE` or `LICENSE` files ([PR](https://github.com/mjeanroy/rollup-plugin-license/pull/931)), thanks [@codepunkt](https://github.com/codepunkt)!\n- 2.5.0\n  - Look for dependencies' license files case insensitively, thanks [@Luke-zhang-04](https://github.com/Luke-zhang-04)!\n- 2.4.0\n  - Typings added\n  - Update dependencies\n- 2.0.0\n  - Support node \u003e= 10\n  - Update dependencies\n- 1.0.0\n  - Remove support for rollup \u003c 1.0.0\n  - Remove support for deprecated options.\n  - Support node \u003e= 6\n- 0.14.0\n  - Update rollup peer dependency\n  - Produce a single file as dist output\n  - Update dependencies\n- 0.13.0\n  - Add license checking (see [#381](https://github.com/mjeanroy/rollup-plugin-license/issues/381)).\n- 0.12.1\n  - Restore compatibility with Node6\n- 0.12.0\n  - Improve `output` configuration (see [#379](https://github.com/mjeanroy/rollup-plugin-license/issues/379)).\n  - Improve option object validation and warning.\n  - Deprecate `thirdParty.encoding` option.\n  - Dev dependencies updates.\n- 0.11.0\n  - Fail if the banner file does not exist (breaking change).\n  - Deprecate `banner.file` / `banner.encoding` entries, use `banner.content.file` / `banner.content.encoding` instead (see [#428](https://github.com/mjeanroy/rollup-plugin-license/issues/428)).\n  - Allow comment style to be defined with a \"string\" banner (see [#308](https://github.com/mjeanroy/rollup-plugin-license/issues/308) and [#428](https://github.com/mjeanroy/rollup-plugin-license/issues/428)).\n  - Dev dependencies updates.\n- 0.10.0\n  - Support different comment style for banner (see [#308](https://github.com/mjeanroy/rollup-plugin-license/issues/308)).\n  - Do not include tree shaken dependencies (see [#380](https://github.com/mjeanroy/rollup-plugin-license/issues/380))\n  - Various dependency updates.\n- 0.9.0\n  - Fix for `NULL` character (see [#1](https://github.com/mjeanroy/rollup-plugin-license/issues/1)).\n  - Various dependency updates.\n- 0.8.1\n  - Add rollup as a peer dependency.\n- 0.8.0\n  - Deprecate `sourceMap` option (use `sourcemap` option in lowercase) to keep it consistent with rollup.\n  - Fix deprecate call with rollup \u003e= 1, keep compatibility with legacy versions of rollup.\n  - Upgrade dependencies.\n- 0.7.0\n  - Add a way to specify custom data object when rendering banner.\n  - Add `cwd` option to specify custom working directory (optional option).\n  - Upgrade dependencies.\n- 0.6.0\n  - Upgrade `commenting` dependency.\n- 0.5.0\n  - Feat: Sourcemap is now enable by default to ensure compatibility with other rollup plugins.\n  - Fix: Add compatibility with rollup \u003e= 0.48.0 (the new `sourcemap` option).\n  - Fix: Ensure plugin `sourcemp` is used instead of the \"global\" one in rollup options.\n  - Chore: dependency updates.\n- 0.4.0\n  - Dependency update (`moment`).\n  - Dependency update (`magic-string`).\n- 0.3.0\n  - Add encoding option for banner and third-party output file.\n  - Banner can be a simple string.\n\n## License\n\nMIT License (MIT)\n\n## Contributing\n\nIf you find a bug or think about enhancement, feel free to contribute and submit an issue or a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjeanroy%2Frollup-plugin-license","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjeanroy%2Frollup-plugin-license","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjeanroy%2Frollup-plugin-license/lists"}