spdx-satisfies 0.1.2 → 5.0.0
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 +35 -27
- package/index.js +138 -0
- package/package.json +24 -7
- package/spdx-satisfies.js +0 -58
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
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
```javascript
|
|
2
|
+
var assert = require('assert')
|
|
3
|
+
var satisfies = require('spdx-satisfies')
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
npm install --save spdx-satisfies
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
In JavaScript:
|
|
8
|
-
|
|
9
|
-
<!--js
|
|
10
|
-
var satisfies = require('./');
|
|
11
|
-
-->
|
|
5
|
+
assert(satisfies('MIT', 'MIT'))
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
satisfies('
|
|
7
|
+
assert(satisfies('MIT', '(ISC OR MIT)'))
|
|
8
|
+
assert(satisfies('Zlib', '(ISC OR (MIT OR Zlib))'))
|
|
9
|
+
assert(!satisfies('GPL-3.0', '(ISC OR MIT)'))
|
|
15
10
|
|
|
16
|
-
satisfies('
|
|
17
|
-
satisfies('
|
|
18
|
-
satisfies('GPL-
|
|
11
|
+
assert(satisfies('GPL-2.0', 'GPL-2.0+'))
|
|
12
|
+
assert(satisfies('GPL-3.0', 'GPL-2.0+'))
|
|
13
|
+
assert(satisfies('GPL-1.0+', 'GPL-2.0+'))
|
|
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+'))
|
|
19
17
|
|
|
20
|
-
satisfies(
|
|
21
|
-
satisfies('GPL-3.0', 'GPL-2.0+') // => true
|
|
22
|
-
satisfies('GPL-1.0', 'GPL-2.0+') // => false
|
|
23
|
-
|
|
24
|
-
satisfies(
|
|
18
|
+
assert(!satisfies(
|
|
25
19
|
'GPL-2.0',
|
|
26
20
|
'GPL-2.0+ WITH Bison-exception-2.2'
|
|
27
|
-
)
|
|
28
|
-
|
|
21
|
+
))
|
|
22
|
+
|
|
23
|
+
assert(satisfies(
|
|
29
24
|
'GPL-3.0 WITH Bison-exception-2.2',
|
|
30
25
|
'GPL-2.0+ WITH Bison-exception-2.2'
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)')
|
|
34
|
-
satisfies('(MIT AND GPL-2.0)', '(MIT
|
|
35
|
-
satisfies('
|
|
26
|
+
))
|
|
27
|
+
|
|
28
|
+
assert(satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)'))
|
|
29
|
+
assert(satisfies('(MIT AND GPL-2.0)', '(MIT AND GPL-2.0)'))
|
|
30
|
+
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'MIT AND GPL-2.0 AND ISC'))
|
|
31
|
+
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'ISC AND GPL-2.0 AND MIT'))
|
|
32
|
+
assert(satisfies('(MIT OR GPL-2.0) AND ISC', 'MIT AND ISC'))
|
|
33
|
+
assert(satisfies('MIT AND ISC', '(MIT OR GPL-2.0) AND ISC'))
|
|
34
|
+
assert(satisfies('MIT AND ISC', '(MIT AND GPL-2.0) OR ISC'))
|
|
35
|
+
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 AND ISC'))
|
|
36
|
+
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 OR ISC'))
|
|
37
|
+
assert(satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)'))
|
|
38
|
+
assert(satisfies('(MIT AND GPL-2.0)', '(GPL-2.0 AND MIT)'))
|
|
39
|
+
assert(satisfies('MIT', '(GPL-2.0 OR MIT) AND (MIT OR ISC)'))
|
|
40
|
+
assert(satisfies('MIT AND ICU', '(MIT AND GPL-2.0) OR (ISC AND (Apache-2.0 OR ICU))'))
|
|
41
|
+
assert(!satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)'))
|
|
42
|
+
assert(!satisfies('MIT AND (GPL-2.0 OR ISC)', 'MIT'))
|
|
43
|
+
assert(!satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'MIT'))
|
|
36
44
|
```
|
package/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var compare = require('spdx-compare')
|
|
2
|
+
var parse = require('spdx-expression-parse')
|
|
3
|
+
var ranges = require('spdx-ranges')
|
|
4
|
+
|
|
5
|
+
var rangesAreCompatible = function (first, second) {
|
|
6
|
+
return (
|
|
7
|
+
first.license === second.license ||
|
|
8
|
+
ranges.some(function (range) {
|
|
9
|
+
return (
|
|
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) {
|
|
21
|
+
return (
|
|
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 - 1
|
|
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(Array.from(expandInner(expression)))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Flatten the given expression into an array of all licenses mentioned in the expression.
|
|
96
|
+
function flatten (expression) {
|
|
97
|
+
const expanded = Array.from(expandInner(expression))
|
|
98
|
+
const 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
|
+
}
|
|
125
|
+
|
|
126
|
+
function isANDCompatible (one, two) {
|
|
127
|
+
return one.every(function (o) {
|
|
128
|
+
return two.some(function (t) { return licensesAreCompatible(o, t) })
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
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
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = satisfies
|
package/package.json
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spdx-satisfies",
|
|
3
3
|
"description": "test whether SPDX expressions satisfy licensing criteria",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "5.0.0",
|
|
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": "0.
|
|
8
|
-
"spdx-
|
|
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
|
-
"
|
|
12
|
-
"
|
|
17
|
+
"defence-cli": "^2.0.1",
|
|
18
|
+
"replace-require-self": "^1.1.1",
|
|
19
|
+
"standard": "^11.0.0"
|
|
13
20
|
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"SPDX",
|
|
23
|
+
"law",
|
|
24
|
+
"legal",
|
|
25
|
+
"license",
|
|
26
|
+
"metadata",
|
|
27
|
+
"package",
|
|
28
|
+
"package.json",
|
|
29
|
+
"standards"
|
|
30
|
+
],
|
|
14
31
|
"license": "MIT",
|
|
15
|
-
"main": "spdx-satisfies.js",
|
|
16
32
|
"repository": "kemitchell/spdx-satisfies.js",
|
|
17
33
|
"scripts": {
|
|
18
|
-
"test": "
|
|
34
|
+
"test": "defence -i javascript README.md | replace-require-self | node",
|
|
35
|
+
"lint": "standard"
|
|
19
36
|
}
|
|
20
37
|
}
|
package/spdx-satisfies.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
var spdx = require('spdx')
|
|
2
|
-
var compare = require('spdx-compare')
|
|
3
|
-
|
|
4
|
-
module.exports = (function() {
|
|
5
|
-
var rangesAreCompatible = function(first, second) {
|
|
6
|
-
return (
|
|
7
|
-
first.license === second.license ||
|
|
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') {
|
|
40
|
-
return (
|
|
41
|
-
recurse(first.left, second) &&
|
|
42
|
-
recurse(first.right, second) ) }
|
|
43
|
-
else if (firstConjunction === 'or') {
|
|
44
|
-
return (
|
|
45
|
-
recurse(first.left, second) ||
|
|
46
|
-
recurse(first.right, second) ) } }
|
|
47
|
-
|
|
48
|
-
var recurse = function(first, second) {
|
|
49
|
-
if (first.hasOwnProperty('conjunction')) {
|
|
50
|
-
return recurseLeftAndRight(first, second) }
|
|
51
|
-
else if (second.hasOwnProperty('conjunction')) {
|
|
52
|
-
return recurseLeftAndRight(second, first) }
|
|
53
|
-
else {
|
|
54
|
-
return licensesAreCompatible(first, second) } }
|
|
55
|
-
|
|
56
|
-
return function(first, second) {
|
|
57
|
-
return recurse(spdx.parse(first), spdx.parse(second)) } })()
|
|
58
|
-
|