Skip to content
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

Fixes 176, Packages are not ignored when using --onlyAllow and --excludePackages #179

Merged
merged 1 commit into from
Oct 9, 2018
Merged
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
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated drive-by, moved this up to sit after sorting and before an license exclusion / filtering.

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