license-checker-plugin 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -79,6 +79,9 @@ export declare class LicensePluginCore {
|
|
|
79
79
|
}>;
|
|
80
80
|
private resolveLicenseEntries;
|
|
81
81
|
private checkCompliance;
|
|
82
|
+
private isAllowed;
|
|
83
|
+
private isFailed;
|
|
84
|
+
private parseSpdxIdentifiers;
|
|
82
85
|
private buildOutputItems;
|
|
83
86
|
private recordReport;
|
|
84
87
|
private mergeReports;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.LicensePluginCore = void 0;
|
|
4
7
|
const fs_1 = require("fs");
|
|
5
8
|
const path_1 = require("path");
|
|
9
|
+
const spdx_expression_parse_1 = __importDefault(require("spdx-expression-parse"));
|
|
6
10
|
const LicenseDatabase_1 = require("./checker/LicenseDatabase");
|
|
7
11
|
const BuiltInLicenseChecker_1 = require("./checker/BuiltInLicenseChecker");
|
|
8
12
|
const HtmlFormatter_1 = require("./formatter/HtmlFormatter");
|
|
@@ -47,12 +51,14 @@ class LicensePluginCore {
|
|
|
47
51
|
async generateLicenseItems(packages, context) {
|
|
48
52
|
const entries = this.resolveLicenseEntries(packages);
|
|
49
53
|
const errors = this.checkCompliance(entries);
|
|
54
|
+
let items;
|
|
50
55
|
if (errors.length > 0) {
|
|
51
56
|
for (const err of errors)
|
|
52
57
|
context.reportError(err);
|
|
58
|
+
this.recordReport([]);
|
|
53
59
|
return { items: [], errors };
|
|
54
60
|
}
|
|
55
|
-
|
|
61
|
+
items = this.buildOutputItems(entries);
|
|
56
62
|
this.recordReport(items);
|
|
57
63
|
if (this.options.recordOnly)
|
|
58
64
|
return { items: [], errors: [] };
|
|
@@ -87,15 +93,61 @@ class LicensePluginCore {
|
|
|
87
93
|
checkCompliance(entries) {
|
|
88
94
|
const errors = [];
|
|
89
95
|
for (const { info, licenseInfo } of entries) {
|
|
90
|
-
if (this.options.onlyAllow.length > 0 && !this.
|
|
96
|
+
if (this.options.onlyAllow.length > 0 && !this.isAllowed(licenseInfo.license)) {
|
|
91
97
|
errors.push(`LicensePlugin: License "${licenseInfo.license}" for package "${info.name}@${info.version}" is not in the allowed list: ${this.options.onlyAllow.join(', ')}`);
|
|
92
98
|
}
|
|
93
|
-
else if (this.options.failOn.length > 0 && this.
|
|
99
|
+
else if (this.options.failOn.length > 0 && this.isFailed(licenseInfo.license)) {
|
|
94
100
|
errors.push(`LicensePlugin: License "${licenseInfo.license}" for package "${info.name}@${info.version}" is in the fail list`);
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
return errors;
|
|
98
104
|
}
|
|
105
|
+
isAllowed(license) {
|
|
106
|
+
if (this.options.onlyAllow.includes(license))
|
|
107
|
+
return true;
|
|
108
|
+
const ids = this.parseSpdxIdentifiers(license);
|
|
109
|
+
if (!ids)
|
|
110
|
+
return false;
|
|
111
|
+
if (ids.conjunction === 'and')
|
|
112
|
+
return ids.identifiers.every((id) => this.options.onlyAllow.includes(id));
|
|
113
|
+
if (ids.conjunction === 'or')
|
|
114
|
+
return ids.identifiers.some((id) => this.options.onlyAllow.includes(id));
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
isFailed(license) {
|
|
118
|
+
if (this.options.failOn.includes(license))
|
|
119
|
+
return true;
|
|
120
|
+
const ids = this.parseSpdxIdentifiers(license);
|
|
121
|
+
if (!ids)
|
|
122
|
+
return false;
|
|
123
|
+
return ids.identifiers.some((id) => this.options.failOn.includes(id));
|
|
124
|
+
}
|
|
125
|
+
parseSpdxIdentifiers(license) {
|
|
126
|
+
try {
|
|
127
|
+
const node = (0, spdx_expression_parse_1.default)(license);
|
|
128
|
+
const identifiers = [];
|
|
129
|
+
let conjunction = null;
|
|
130
|
+
const walk = (n) => {
|
|
131
|
+
if ('license' in n) {
|
|
132
|
+
identifiers.push(n.license);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const expr = n;
|
|
136
|
+
if (!conjunction)
|
|
137
|
+
conjunction = expr.conjunction;
|
|
138
|
+
walk(expr.left);
|
|
139
|
+
walk(expr.right);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
walk(node);
|
|
143
|
+
if (!conjunction)
|
|
144
|
+
return null;
|
|
145
|
+
return { identifiers, conjunction };
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
99
151
|
buildOutputItems(entries) {
|
|
100
152
|
return entries.map(({ info, licenseInfo }) => ({
|
|
101
153
|
package: {
|
|
@@ -34,8 +34,10 @@ class LicenseWebpackPlugin {
|
|
|
34
34
|
reportWarning: (msg) => compilation.warnings.push(new Error(msg)),
|
|
35
35
|
};
|
|
36
36
|
const initialized = await this.core.initialize(startPath, context);
|
|
37
|
-
if (!initialized)
|
|
37
|
+
if (!initialized) {
|
|
38
|
+
this.core.options.recorder?.record({ items: [] });
|
|
38
39
|
return;
|
|
40
|
+
}
|
|
39
41
|
const scanner = new PackageScanner_1.PackageScanner();
|
|
40
42
|
const packages = scanner.scan(compilation);
|
|
41
43
|
const { items, errors } = await this.core.generateLicenseItems(packages, context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "license-checker-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A bundler-agnostic plugin to generate third-party license notices for bundled packages. Supports webpack 5, Rspack, and Vite.",
|
|
5
5
|
"author": "Axetroy <axetroy.dev@gmail.com>",
|
|
6
6
|
"repository": {
|