-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change API to satisfies(SPDX expression, array of licenses)
The design decision to take the argument expressing acceptable license policy as another SPDX expression has repeatedly confused people. Meanwhile, the primary use case for this package is to check some SPDX license expression for a package against a list of approved licenses. I believe we can better serve that use case and make this package easier to maintain by taking a list of approved licenses instead of a second SPDX expression.
- Loading branch information
1 parent
bb284e1
commit 01fc32b
Showing
7 changed files
with
106 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
`satisfies(SPDX license expression, array of approved licenses)` | ||
|
||
Approved licenses may be simple license identifiers like `MIT`, plus-ranges like `EPL-2.0+`, or licenses with exceptions like `Apache-2.0 WITH LLVM`. They may _not_ be compound expressions using `AND` or `OR`. | ||
|
||
```javascript | ||
var assert = require('assert') | ||
var satisfies = require('spdx-satisfies') | ||
|
||
// True Examples | ||
for (const [spdxExpression, arrayOfApproved] of [ | ||
<%- returnTrue.map(function (e) { return ' ' + JSON.stringify(e) }).join(',\n') %> | ||
]) assert(satisfies(spdxExpression, arrayOfApproved)) | ||
|
||
// False Examples | ||
for (const [spdxExpression, arrayOfApproved] of [ | ||
<%- returnFalse.map(function (e) { return ' ' + JSON.stringify(e) }).join(',\n') %> | ||
]) assert(!satisfies(spdxExpression, arrayOfApproved)) | ||
|
||
// Exceptions | ||
for (const [spdxExpression, arrayOfApproved] of [ | ||
<%- throwErrors.map(function (e) { return ' ' + JSON.stringify(e) }).join(',\n') %> | ||
]) assert.throws(function () { satisfies(spdxExpression, arrayOfApproved) }) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"returnTrue": [ | ||
["MIT", ["MIT"]], | ||
["MIT", ["ISC", "MIT"]], | ||
["Zlib", ["ISC", "MIT", "Zlib"]], | ||
["GPL-2.0", ["GPL-2.0+"]], | ||
["GPL-3.0", ["GPL-2.0+"]], | ||
["GPL-1.0+", ["GPL-2.0+"]], | ||
["GPL-2.0-only", ["GPL-2.0-only"]], | ||
["GPL-3.0-only", ["GPL-2.0+"]], | ||
["LGPL-3.0-only", ["LGPL-3.0-or-later"]], | ||
["GPL-2.0", ["GPL-2.0+"]], | ||
["GPL-2.0-only", ["GPL-2.0+"]], | ||
["GPL-2.0", ["GPL-2.0-or-later"]], | ||
["GPL-3.0 WITH Bison-exception-2.2", ["GPL-2.0+ WITH Bison-exception-2.2"]], | ||
["(MIT OR GPL-2.0)", ["ISC", "MIT"]], | ||
["(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)", ["Apache-2.0", "ISC"]], | ||
["(MIT AND GPL-2.0)", ["MIT", "GPL-2.0"]] | ||
], | ||
|
||
"returnFalse": [ | ||
["GPL-3.0", ["ISC", "MIT"]], | ||
["GPL-1.0", ["GPL-2.0+"]], | ||
["GPL-2.0", ["GPL-2.0+ WITH Bison-exception-2.2"]], | ||
["(MIT AND GPL-2.0)", ["ISC", "GPL-2.0"]], | ||
["MIT AND (GPL-2.0 OR ISC)", ["MIT"]], | ||
["(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)", ["MIT"]] | ||
], | ||
|
||
"throwErrors": [ | ||
["MIT AND ISC", ["(MIT OR GPL-2.0) AND ISC"]], | ||
["MIT AND ISC", ["(MIT AND GPL-2.0)", "ISC"]] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var examples = require('./examples.json') | ||
var satisfies = require('./') | ||
var tape = require('tape') | ||
|
||
function label(expression, approved) { | ||
return JSON.stringify(expression) + ', ' + JSON.stringify(approved) | ||
} | ||
|
||
for (const [expression, approved] of examples.returnTrue) { | ||
tape.test(label(expression, approved), t => { | ||
t.assert(satisfies(expression, approved), 'returns true') | ||
t.end() | ||
}) | ||
} | ||
|
||
// False Examples | ||
for (const [expression, approved] of examples.returnFalse) { | ||
tape.test(label(expression, approved), t => { | ||
t.assert(!satisfies(expression, approved)) | ||
t.end() | ||
}) | ||
} | ||
|
||
// Invalid License Arrays | ||
for (const [expression, approved] of examples.throwErrors) { | ||
tape.test(label(expression, approved), t => { | ||
t.throws(() => satisfies(expression, approved)) | ||
t.end() | ||
}) | ||
} |