Skip to content

Commit

Permalink
Merge pull request #179 from jonny-improbable/fix/fix-strict-checks
Browse files Browse the repository at this point in the history
Fixes 176, Packages are not ignored when using --onlyAllow and --excludePackages
  • Loading branch information
davglass committed Oct 9, 2018
2 parents 890ca17 + 179077d commit e68878b
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,33 +320,13 @@ exports.init = function(options, callback) {
};

Object.keys(data).sort().forEach(function(item) {
if (toCheckforFailOn.length > 0) {
if (toCheckforFailOn.indexOf(data[item].licenses) > -1) {
console.error('Found license defined by the --failOn flag: "' + data[item].licenses + '". Exiting.');
process.exit(1);
}
}
if (data[item].private) {
data[item].licenses = colorizeString(UNLICENSED);
}
/*istanbul ignore next*/
if (!data[item].licenses) {
data[item].licenses = colorizeString(UNKNOWN);
}
if (toCheckforOnlyAllow.length > 0) {
var good = false;
toCheckforOnlyAllow.forEach(function(k) {
if (data[item].licenses.indexOf(k) === -1 && !good) {
good = false;
} else {
good = true;
}
});
if (!good) {
console.error('Package "' + item + '" is licensed under "' + data[item].licenses + '" which is not permitted by the --onlyAllow flag. Exiting.');
process.exit(1);
}
}
if (options.unknown) {
/*istanbul ignore else*/
if (data[item].licenses && data[item].licenses !== UNKNOWN) {
Expand All @@ -368,6 +348,11 @@ exports.init = function(options, callback) {
}
}
});

if (!Object.keys(sorted).length) {
err = new Error('No packages found in this path..');
}

if (exclude) {
var transformBSD = function(spdx) {
return spdx === 'BSD' ? '(0BSD OR BSD-2-Clause OR BSD-3-Clause OR BSD-4-Clause)' : spdx;
Expand Down Expand Up @@ -439,9 +424,28 @@ exports.init = function(options, callback) {
});
}

if (!Object.keys(sorted).length) {
err = new Error('No packages found in this path..');
}
Object.keys(restricted).forEach(function(item) {
if (toCheckforFailOn.length > 0) {
if (toCheckforFailOn.indexOf(restricted[item].licenses) > -1) {
console.error('Found license defined by the --failOn flag: "' + restricted[item].licenses + '". Exiting.');
process.exit(1);
}
}
if (toCheckforOnlyAllow.length > 0) {
var good = false;
toCheckforOnlyAllow.forEach(function(k) {
if (restricted[item].licenses.indexOf(k) === -1 && !good) {
good = false;
} else {
good = true;
}
});
if (!good) {
console.error('Package "' + item + '" is licensed under "' + restricted[item].licenses + '" which is not permitted by the --onlyAllow flag. Exiting.');
process.exit(1);
}
}
});

/*istanbul ignore next*/
if (err) {
Expand Down

0 comments on commit e68878b

Please sign in to comment.