spdx-satisfies 0.1.3 → 5.0.1
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.
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/index.js +131 -51
- package/package.json +17 -5
- package/LICENSE.md +0 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) spdx-satisfies.js contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
|
+
copy of this software and associated documentation files (the "Software"),
|
|
7
|
+
to deal in the Software without restriction, including without limitation
|
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
+
Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included
|
|
13
|
+
in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
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
|
|
18
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
20
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
21
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,7 +10,14 @@ assert(!satisfies('GPL-3.0', '(ISC OR MIT)'))
|
|
|
10
10
|
|
|
11
11
|
assert(satisfies('GPL-2.0', 'GPL-2.0+'))
|
|
12
12
|
assert(satisfies('GPL-3.0', 'GPL-2.0+'))
|
|
13
|
+
assert(satisfies('GPL-1.0+', 'GPL-2.0+'))
|
|
13
14
|
assert(!satisfies('GPL-1.0', 'GPL-2.0+'))
|
|
15
|
+
assert(satisfies('GPL-2.0-only', 'GPL-2.0-only'))
|
|
16
|
+
assert(satisfies('GPL-3.0-only', 'GPL-2.0+'))
|
|
17
|
+
assert(satisfies('LGPL-3.0-only', 'LGPL-3.0-or-later'))
|
|
18
|
+
assert(satisfies('GPL-2.0', 'GPL-2.0+'))
|
|
19
|
+
assert(satisfies('GPL-2.0-only', 'GPL-2.0+'))
|
|
20
|
+
assert(satisfies('GPL-2.0', 'GPL-2.0-or-later'))
|
|
14
21
|
|
|
15
22
|
assert(!satisfies(
|
|
16
23
|
'GPL-2.0',
|
|
@@ -23,6 +30,19 @@ assert(satisfies(
|
|
|
23
30
|
))
|
|
24
31
|
|
|
25
32
|
assert(satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)'))
|
|
33
|
+
assert(satisfies('(MIT AND GPL-2.0)', '(MIT AND GPL-2.0)'))
|
|
34
|
+
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'MIT AND GPL-2.0 AND ISC'))
|
|
35
|
+
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'ISC AND GPL-2.0 AND MIT'))
|
|
36
|
+
assert(satisfies('(MIT OR GPL-2.0) AND ISC', 'MIT AND ISC'))
|
|
37
|
+
assert(satisfies('MIT AND ISC', '(MIT OR GPL-2.0) AND ISC'))
|
|
38
|
+
assert(satisfies('MIT AND ISC', '(MIT AND GPL-2.0) OR ISC'))
|
|
39
|
+
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 AND ISC'))
|
|
40
|
+
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 OR ISC'))
|
|
26
41
|
assert(satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)'))
|
|
42
|
+
assert(satisfies('(MIT AND GPL-2.0)', '(GPL-2.0 AND MIT)'))
|
|
43
|
+
assert(satisfies('MIT', '(GPL-2.0 OR MIT) AND (MIT OR ISC)'))
|
|
44
|
+
assert(satisfies('MIT AND ICU', '(MIT AND GPL-2.0) OR (ISC AND (Apache-2.0 OR ICU))'))
|
|
27
45
|
assert(!satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)'))
|
|
46
|
+
assert(!satisfies('MIT AND (GPL-2.0 OR ISC)', 'MIT'))
|
|
47
|
+
assert(!satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'MIT'))
|
|
28
48
|
```
|
package/index.js
CHANGED
|
@@ -1,58 +1,138 @@
|
|
|
1
|
-
var parse = require('spdx-expression-parse')
|
|
2
1
|
var compare = require('spdx-compare')
|
|
2
|
+
var parse = require('spdx-expression-parse')
|
|
3
|
+
var ranges = require('spdx-ranges')
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ranges.some(function(range) {
|
|
9
|
-
return (
|
|
10
|
-
range.indexOf(first.license) > -1 &&
|
|
11
|
-
range.indexOf(second.license) ) }) ) }
|
|
12
|
-
|
|
13
|
-
var identifierInRange = function(identifier, range) {
|
|
14
|
-
return (
|
|
15
|
-
identifier.license === range.license ||
|
|
16
|
-
compare.gt(identifier.license, range.license) ) }
|
|
17
|
-
|
|
18
|
-
var licensesAreCompatible = function(first, second) {
|
|
19
|
-
if (first.exception !== second.exception) {
|
|
20
|
-
return false }
|
|
21
|
-
else if (second.hasOwnProperty('license')) {
|
|
22
|
-
if (second.hasOwnProperty('plus')) {
|
|
23
|
-
if (first.hasOwnProperty('plus')) {
|
|
24
|
-
// first+, second+
|
|
25
|
-
return rangesAreCompatible(first, second) }
|
|
26
|
-
else {
|
|
27
|
-
// first, second+
|
|
28
|
-
return identifierInRange(first, second) } }
|
|
29
|
-
else {
|
|
30
|
-
if (first.hasOwnProperty('plus')) {
|
|
31
|
-
// first+, second
|
|
32
|
-
return identifierInRange(second, first) }
|
|
33
|
-
else {
|
|
34
|
-
// first, second
|
|
35
|
-
return first.license === second.license } } } }
|
|
36
|
-
|
|
37
|
-
var recurseLeftAndRight = function(first, second) {
|
|
38
|
-
var firstConjunction = first.conjunction
|
|
39
|
-
if (firstConjunction === 'and') {
|
|
5
|
+
var rangesAreCompatible = function (first, second) {
|
|
6
|
+
return (
|
|
7
|
+
first.license === second.license ||
|
|
8
|
+
ranges.some(function (range) {
|
|
40
9
|
return (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
10
|
+
licenseInRange(first.license, range) &&
|
|
11
|
+
licenseInRange(second.license, range)
|
|
12
|
+
)
|
|
13
|
+
})
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function licenseInRange (license, range) {
|
|
18
|
+
return (
|
|
19
|
+
range.indexOf(license) !== -1 ||
|
|
20
|
+
range.some(function (element) {
|
|
44
21
|
return (
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
Array.isArray(element) &&
|
|
23
|
+
element.indexOf(license) !== -1
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var identifierInRange = function (identifier, range) {
|
|
30
|
+
return (
|
|
31
|
+
identifier.license === range.license ||
|
|
32
|
+
compare.gt(identifier.license, range.license) ||
|
|
33
|
+
compare.eq(identifier.license, range.license)
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var licensesAreCompatible = function (first, second) {
|
|
38
|
+
if (first.exception !== second.exception) {
|
|
39
|
+
return false
|
|
40
|
+
} else if (second.hasOwnProperty('license')) {
|
|
41
|
+
if (second.hasOwnProperty('plus')) {
|
|
42
|
+
if (first.hasOwnProperty('plus')) {
|
|
43
|
+
// first+, second+
|
|
44
|
+
return rangesAreCompatible(first, second)
|
|
45
|
+
} else {
|
|
46
|
+
// first, second+
|
|
47
|
+
return identifierInRange(first, second)
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (first.hasOwnProperty('plus')) {
|
|
51
|
+
// first+, second
|
|
52
|
+
return identifierInRange(second, first)
|
|
53
|
+
} else {
|
|
54
|
+
// first, second
|
|
55
|
+
return first.license === second.license
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function normalizeGPLIdentifiers (argument) {
|
|
62
|
+
var license = argument.license
|
|
63
|
+
if (license) {
|
|
64
|
+
if (endsWith(license, '-or-later')) {
|
|
65
|
+
argument.license = license.replace('-or-later', '')
|
|
66
|
+
argument.plus = true
|
|
67
|
+
} else if (endsWith(license, '-only')) {
|
|
68
|
+
argument.license = license.replace('-or-later', '')
|
|
69
|
+
delete argument.plus
|
|
70
|
+
}
|
|
71
|
+
} else if (argument.left && argument.right) {
|
|
72
|
+
argument.left = normalizeGPLIdentifiers(argument.left)
|
|
73
|
+
argument.right = normalizeGPLIdentifiers(argument.right)
|
|
74
|
+
}
|
|
75
|
+
return argument
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function endsWith (string, substring) {
|
|
79
|
+
return string.indexOf(substring) === string.length - substring.length
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function licenseString (e) {
|
|
83
|
+
if (e.hasOwnProperty('noassertion')) return 'NOASSERTION'
|
|
84
|
+
if (e.license) return `${e.license}${e.plus ? '+' : ''}${e.exception ? ` WITH ${e.exception}` : ''}`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Expand the given expression into an equivalent array where each member is an array of licenses AND'd
|
|
88
|
+
// together and the members are OR'd together. For example, `(MIT OR ISC) AND GPL-3.0` expands to
|
|
89
|
+
// `[[GPL-3.0 AND MIT], [ISC AND MIT]]`. Note that within each array of licenses, the entries are
|
|
90
|
+
// normalized (sorted) by license name.
|
|
91
|
+
function expand (expression) {
|
|
92
|
+
return sort(expandInner(expression))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Flatten the given expression into an array of all licenses mentioned in the expression.
|
|
96
|
+
function flatten (expression) {
|
|
97
|
+
var expanded = expandInner(expression)
|
|
98
|
+
var flattened = expanded.reduce(function (result, clause) {
|
|
99
|
+
return Object.assign(result, clause)
|
|
100
|
+
}, {})
|
|
101
|
+
return sort([flattened])[0]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function expandInner (expression) {
|
|
105
|
+
if (!expression.conjunction) return [{ [licenseString(expression)]: expression }]
|
|
106
|
+
if (expression.conjunction === 'or') return expandInner(expression.left).concat(expandInner(expression.right))
|
|
107
|
+
if (expression.conjunction === 'and') {
|
|
108
|
+
var left = expandInner(expression.left)
|
|
109
|
+
var right = expandInner(expression.right)
|
|
110
|
+
return left.reduce(function (result, l) {
|
|
111
|
+
right.forEach(function (r) { result.push(Object.assign({}, l, r)) })
|
|
112
|
+
return result
|
|
113
|
+
}, [])
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function sort (licenseList) {
|
|
118
|
+
var sortedLicenseLists = licenseList
|
|
119
|
+
.filter(function (e) { return Object.keys(e).length })
|
|
120
|
+
.map(function (e) { return Object.keys(e).sort() })
|
|
121
|
+
return sortedLicenseLists.map(function (list, i) {
|
|
122
|
+
return list.map(function (license) { return licenseList[i][license] })
|
|
123
|
+
})
|
|
124
|
+
}
|
|
47
125
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
return licensesAreCompatible(first, second) } }
|
|
126
|
+
function isANDCompatible (one, two) {
|
|
127
|
+
return one.every(function (o) {
|
|
128
|
+
return two.some(function (t) { return licensesAreCompatible(o, t) })
|
|
129
|
+
})
|
|
130
|
+
}
|
|
55
131
|
|
|
56
|
-
|
|
57
|
-
|
|
132
|
+
function satisfies (first, second) {
|
|
133
|
+
var one = expand(normalizeGPLIdentifiers(parse(first)))
|
|
134
|
+
var two = flatten(normalizeGPLIdentifiers(parse(second)))
|
|
135
|
+
return one.some(function (o) { return isANDCompatible(o, two) })
|
|
136
|
+
}
|
|
58
137
|
|
|
138
|
+
module.exports = satisfies
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spdx-satisfies",
|
|
3
3
|
"description": "test whether SPDX expressions satisfy licensing criteria",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
|
|
8
|
+
"Dan Butvinik <butvinik@outlook.com>",
|
|
9
|
+
"Jeff McAffer <jeffmcaffer@gmail.com>"
|
|
10
|
+
],
|
|
6
11
|
"dependencies": {
|
|
7
|
-
"spdx-compare": "^0.
|
|
8
|
-
"spdx-expression-parse": "^
|
|
12
|
+
"spdx-compare": "^1.0.0",
|
|
13
|
+
"spdx-expression-parse": "^3.0.0",
|
|
14
|
+
"spdx-ranges": "^2.0.0"
|
|
9
15
|
},
|
|
10
16
|
"devDependencies": {
|
|
11
|
-
"defence-cli": "^
|
|
17
|
+
"defence-cli": "^2.0.1",
|
|
18
|
+
"replace-require-self": "^1.1.1",
|
|
19
|
+
"standard": "^11.0.0"
|
|
12
20
|
},
|
|
13
21
|
"keywords": [
|
|
14
22
|
"SPDX",
|
|
@@ -22,7 +30,11 @@
|
|
|
22
30
|
],
|
|
23
31
|
"license": "MIT",
|
|
24
32
|
"repository": "kemitchell/spdx-satisfies.js",
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js"
|
|
35
|
+
],
|
|
25
36
|
"scripts": {
|
|
26
|
-
"test": "defence -i javascript README.md |
|
|
37
|
+
"test": "defence -i javascript README.md | replace-require-self | node",
|
|
38
|
+
"lint": "standard"
|
|
27
39
|
}
|
|
28
40
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2015 Kyle E. Mitchell
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|