Skip to content

DRAFT: add --failOnCopyleft option #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Options
* `--relativeLicensePath` output the location of the license files as relative paths
* `--summary` output a summary of the license usage',
* `--failOn [list]` fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list
* `--failOnCopyleft` fail (exit with code 1) on the first occurrence of a [license with a copyleft effect](https://github.com/jslicense/spdx-copyleft.json/blob/master/index.json)
* `--onlyAllow [list]` fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list
* `--packages [list]` restrict output to the packages (package@version) in the semicolon-seperated list
* `--excludePackages [list]` restrict output to the packages (package@version) not in the semicolon-seperated list
Expand Down
1 change: 1 addition & 0 deletions bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if (args.help) {
' --relativeLicensePath output the location of the license files as relative paths',
' --summary output a summary of the license usage',
' --failOn [list] fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list',
' --failOnCopyleft fail (exit with code 1) on the first occurrence of a license with a copyleft effect',
' --onlyAllow [list] fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list',
' --direct look for direct dependencies only',
' --packages [list] restrict output to the packages (package@version) in the semicolon-seperated list',
Expand Down
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var nopt = require('nopt'),
files: require('path'),
summary: Boolean,
failOn: String,
failOnCopyleft: Boolean,
onlyAllow: String,
direct: Boolean,
packages: String,
Expand Down
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var debug = require('debug');
var mkdirp = require('mkdirp');
var spdxSatisfies = require('spdx-satisfies');
var spdxCorrect =require('spdx-correct');
var copyLeftLicenses = require('spdx-copyleft');

// Set up debug logging
// https://www.npmjs.com/package/debug#stderr-vs-stdout
Expand Down Expand Up @@ -441,6 +442,12 @@ exports.init = function(options, callback) {
process.exit(1);
}
}
if (options.failOnCopyleft) {
if (copyLeftLicenses.includes(restricted[item].licenses)) {
console.error('Found license defined by the --failOnCopyleft flag: "' + restricted[item].licenses + '". Exiting.');
process.exit(1);
}
}
if (toCheckforOnlyAllow.length > 0) {
var good = false;
toCheckforOnlyAllow.forEach(function(k) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"nopt": "^4.0.1",
"read-installed": "~4.0.3",
"semver": "^5.5.0",
"spdx-copyleft": "^1.0.0",
"spdx-correct": "^3.0.0",
"spdx-expression-parse": "^3.0.0",
"spdx-satisfies": "^4.0.0",
Expand Down
17 changes: 17 additions & 0 deletions tests/failOnCopyleft-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn;

describe('failOnCopyleft', function() {
this.timeout(8000);

it('should exit 1 if it finds forbidden license due to --failOnCopyleft', function(done) {
spawn('node', [path.join(__dirname, '../bin/license-checker'), '--failOnCopyleft'], {
cwd: path.join(__dirname, './fixtures/copyleftProject'),
stdio: 'ignore'
}).on('exit', function(code) {
assert.equal(code, 1);
done();
});
});
});
5 changes: 5 additions & 0 deletions tests/fixtures/copyleftProject/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "copyleft-project",
"version": "1.0.0",
"license": "GPL-3.0-only"
}
9 changes: 9 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ describe('main tests', function() {
});
});

describe('should exit on single failOnCopyleft license', function() {
var result={};
before(parseAndFailOn('failOnCopyleft', './fixtures/copyleftProject', true, result));

it('should exit on GPL licensed modules from results', function() {
assert.equal(result.exitCode, 1);
});
});

describe('should parse local and handle private modules', function() {
var output;
before(function(done) {
Expand Down