Skip to content

Commit db31d20

Browse files
committed
Initial implementation
1 parent b96b2f9 commit db31d20

11 files changed

+4879
-27
lines changed

.eslintrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2017
4+
},
5+
"env": {
6+
"node": true
7+
},
8+
"extends": "eslint:recommended",
9+
"plugins": ["prettier"],
10+
"rules": {
11+
"prettier/prettier": "error"
12+
}
13+
}

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 100
3+
}

LICENSE

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
MIT License
1+
MIT License
22

3-
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Copyright (c) Microsoft Corporation. All rights reserved.
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

README.md

+105-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,109 @@
1+
# license-checker-webpack-plugin
12

2-
# Contributing
3+
Webpack plugin that verifies licenses of all external dependencies in a compilation, and outputs all that information to a file.
34

4-
This project welcomes contributions and suggestions. Most contributions require you to agree to a
5-
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
6-
the rights to use your contribution. For details, visit https://cla.microsoft.com.
5+
## Installation
76

8-
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
9-
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
10-
provided by the bot. You will only need to do this once across all repos using our CLA.
7+
### npm
118

12-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
13-
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
14-
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
9+
```
10+
npm install license-checker-webpack-plugin --save-dev
11+
```
12+
13+
### yarn
14+
15+
```
16+
yarn add license-checker-webpack-plugin --dev
17+
```
18+
19+
## Usage
20+
21+
Require the plugin into your Webpack configuration, and pass it to the `plugins` array.
22+
23+
```js
24+
const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin");
25+
26+
module.exports = {
27+
// ...
28+
plugins: [new LicenseCheckerWebpackPlugin({ output: "ThirdPartyNotices.txt" })]
29+
};
30+
```
31+
32+
## Options
33+
34+
| Property | Type | Default | Description |
35+
| ---------------- | ---------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| `allow` | `string` | `"(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)"` | SPDX expression with allowed licenses. |
37+
| `ignore` | `array` | `[]` | Array of dependencies to ignore, in the format `["<dependency name>@<version range>"]`. For example, `["assignment@^2.0.0"]`. |
38+
| `override` | `object` | `{}` | Object of dependencies to override, in the format `{"<dependency name>@<version range>": { ... }}`. For example, `{"assignment@^2.0.0": { licenseName: "MIT" }}`. |
39+
| `emitError` | `boolean` | `false` | Whether to emit errors instead of warnings. |
40+
| `outputWriter` | `function` | See [`defaultOutputWriter`](./src/defaultOutputWriter.js). | Function that will generate the contents of the third-party notices file. |
41+
| `outputFilename` | `string` | `"ThirdPartyNotices.txt"` | Name of the third-party notices file with all licensing information. |
42+
43+
The data that gets passed to the `outputWriter` function looks like this:
44+
45+
```json
46+
[
47+
{
48+
"name": "react",
49+
"version": "16.3.2",
50+
"repository": "git+https://github.com/facebook/react.git",
51+
"licenseName": "MIT",
52+
"licenseText": "MIT License\n\nCopyright (c) 2013-present, Facebook, Inc. [...]"
53+
},
54+
{
55+
"name": "webpack",
56+
"version": "4.8.3",
57+
"author": "Tobias Koppers @sokra",
58+
"repository": "git+https://github.com/webpack/webpack.git",
59+
"licenseName": "MIT",
60+
"licenseText": "Copyright JS Foundation and other contributors [...]"
61+
},
62+
{
63+
"name": "whatwg-fetch",
64+
"version": "2.0.4",
65+
"repository": "git+https://github.com/github/fetch.git",
66+
"licenseName": "MIT",
67+
"licenseText": "Copyright (c) 2014-2016 GitHub, Inc. [...]"
68+
}
69+
]
70+
```
71+
72+
Here's an example `webpack.config.js` file that uses all options:
73+
74+
```js
75+
const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin");
76+
const template = require("lodash.template");
77+
78+
const customTemplate = templaet(readFileSync("customTemplate.ejs"));
79+
80+
module.exports = {
81+
// ...
82+
plugins: [
83+
new LicenseCheckerWebpackPlugin({
84+
allow: "(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)",
85+
ignore: ["@microsoft/*"],
86+
override: {
87+
"[email protected]": { licenseName: "MIT" },
88+
"[email protected]": { licenseName: "MIT" },
89+
"[email protected]": { licenseName: "MIT" }
90+
},
91+
emitError: true,
92+
outputWriter: data => customTemplate(data),
93+
outputFilename: "ThirdPartyNotices.txt"
94+
})
95+
]
96+
};
97+
```
98+
99+
## Contributing
100+
101+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://cla.microsoft.com>.
102+
103+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
104+
105+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
106+
107+
## Licensing
108+
109+
All files on this repository are subject to the MIT license. Please read the `LICENSE` file at the root of the project.

0 commit comments

Comments
 (0)