forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-licenses
executable file
·189 lines (174 loc) · 6.11 KB
/
check-licenses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env node
const { execSync } = require("child_process");
const { readFileSync } = require("fs");
const _ = require("underscore");
const DEV_MODE = false;
function normalizeLicense(license) {
return license
.toLowerCase()
.trim()
.replace(/^the\s+/, "");
}
const LICENSE_ALLOWLIST = new Set(
[
"Apache 2",
"Apache 2.0",
"Apache License 2.0",
"Apache License",
"Apache License, Version 2.0",
"Apache Software License - Version 2.0",
"Apache Software License, Version 2.0",
"Apache v2",
"Apache*",
"Apache-2.0",
"Apache 2.0 License",
"Artistic-2.0",
"BSD 3-Clause License",
"BSD License",
"BSD licence",
"BSD",
"BSD*",
"0BSD",
"BSD-2-Clause",
"BSD-3-Clause",
"BSD 3-clause",
"BSD style",
"Bouncy Castle Licence",
"CC0 1.0 Universal",
"CC0-1.0",
"CC-BY-4.0",
"CC-BY-3.0",
"CDDL + GPLv2 with classpath exception", // this means CDDL or GPLv2 w/ classpath exception
"CDDL 1.1",
"CDDL License",
"CDDL/GPLv2+CE", // this means CDDL or GPLv2 w/ classpath exception
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0",
"Common Development and Distribution License (CDDL) v1.0",
"Common Public License Version 1.0",
"Common Public License Version",
"Eclipse Public License - v 1.0",
"Eclipse Public License 1.0",
"Eclipse Public License",
"GNU Lesser General Public License 3.0",
"GNU Lesser General Public License, Version 2.1",
"ISC",
"ISC/BSD License",
"LGPL-2.1",
"Lesser GPL",
"MIT (http://mootools.net/license.txt)",
"MIT License",
"MIT Licensed. http://www.opensource.org/licenses/mit-license.php",
"MIT",
"MIT*",
"MIT AND BSD-3-Clause",
"MIT AND Zlib",
"MPL 2.0",
"New BSD License", // same as 3-clause
"Public Domain",
"Revised BSD",
// "The MIT License (MIT)",
"Unlicense",
"WTFPL",
].map(normalizeLicense),
);
const PACKAGE_ALLOWLIST = new Set([
"com.amazon.redshift/[email protected]", // Apache 2.0?
"amalloy/[email protected]", // MIT https://github.com/clj-commons/ring-gzip-middleware/blob/master/LICENSE
"[email protected]", // CC-BY-4.0: https://github.com/Fyrd/caniuse
"[email protected]", // Eclipse Public License: https://github.com/ibdknox/colorize
"com.google.re2j/[email protected]", // Go License https://github.com/google/re2j/blob/master/LICENSE
"com.unboundid/[email protected]", // dual licensed LGPL/GPL: https://ldap.com/unboundid-ldap-sdk-for-java/
"[email protected]", // Public domain: https://github.com/dscape/cycle/blob/master/cycle.js
"[email protected]", // BSD 3-Clause: https://github.com/clojure-expectations/expectations
"[email protected]", // Eclipse Public License: https://github.com/weavejester/hiccup
"[email protected]", // MIT: https://github.com/leecrossley/isNumeric
"javax.servlet.jsp/[email protected]", // CDDL/GPL dual license: https://javaee.github.io/javaee-jsp-api/LICENSE
"[email protected]", // build tools
"net.jcip/[email protected]", // Public Domain: https://mvnrepository.com/artifact/net.jcip/jcip-annotations
"org.gnu.gettext/[email protected]", // LGPL: https://www.gnu.org/software/gettext/manual/html_node/Licenses.html
"org.json/json@20090211", // JSON License: https://www.json.org/license.html
"[email protected]", // build tool only
"[email protected]", // Eclipse Public License: https://github.com/scgilardi/slingshot
"[email protected]", // BSD-3-Clause: https://github.com/hueniverse/sntp/blob/master/LICENSE
"[email protected]", // build tool only
"[email protected]", // build tool only
"[email protected]", // Eclipse Public License: https://github.com/davidsantiago/stencil/blob/0.5.0/LICENSE
]);
function parseLicenses(license) {
license = license.replace(/^\((.*)\)$/g, "$1"); // trim parens
if (/\bor\b/i.test(license) && !/\band\b/i.test(license)) {
return license.split(/\bor\b/gi).map(normalizeLicense);
} else {
return [normalizeLicense(license)];
}
}
function getJavaScriptPackageLicences() {
return (DEV_MODE
? readFileSync("licenses.json", "utf-8")
: execSync("yarn licenses list --json", { encoding: "utf-8" })
)
.split("\n")
.slice(-2, -1) // 2nd to last row
.map(line => JSON.parse(line))[0]
.data.body.map(row => ({
name: row[0],
version: row[1],
license: row[2],
licenses: parseLicenses(row[2]),
type: "javascript",
}));
}
function getClojurePackageLicenses() {
return (
(DEV_MODE
? readFileSync("licenses.csv", "utf-8")
: execSync("lein with-profiles +include-all-drivers,-dev licenses :csv", {
encoding: "utf-8",
})
)
// rudimentary csv parsing
.split("\n")
.filter(line => /^".*"$/.test(line))
.map(line => line.replace(/^"(.*)"$/g, "$1").split(/","/g))
.map(row => ({
name: row[0],
version: row[1],
license: row[2],
licenses: parseLicenses(row[2]),
type: "clojure",
}))
);
}
function checkLicences(packages) {
return packages.filter(
({ name, version, licenses }) =>
// check if any of the licenses are allowed
!_.any(licenses, license => LICENSE_ALLOWLIST.has(license)) &&
// check package allowlist
!PACKAGE_ALLOWLIST.has(`${name}@${version}`),
);
}
const unknownJavaScriptLicenses = checkLicences(getJavaScriptPackageLicences());
const unknownClojureLicenses = checkLicences(getClojurePackageLicenses());
const unknownPackageLogs = [];
const unknownLicenseCounts = new Map();
for (const { name, version, license, type } of [
...unknownJavaScriptLicenses,
...unknownClojureLicenses,
]) {
unknownPackageLogs.push(`[${license}] ${name}@${version} (${type})`);
unknownLicenseCounts.set(
license,
(unknownLicenseCounts.get(license) || 0) + 1,
);
}
console.log("Packages\n========\n");
console.log(unknownPackageLogs.sort().join("\n"));
console.log("\nLicenses\n========\n");
console.log(
_.sortBy(Array.from(unknownLicenseCounts), 1)
.reverse()
.map(([license, count]) => `[${count}] ${license}`)
.join("\n"),
);
process.exit(unknownLicenseCounts.size === 0 ? 0 : 1);