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

feat: Implement --excludeScopes=@scope1;@scope2 option #219

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Options
* `--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
* `--excludePrivatePackages` restrict output to not include any package marked as private
* `--excludeScopes [list]` excludes all packages in scopes from the semicolon-seperated list (example: "@hapi;@babel")
* `--direct look for direct dependencies only`

Exclusions
Expand All @@ -109,6 +110,7 @@ license-checker --customPath customFormatExample.json
license-checker --exclude 'MIT, MIT OR X11, BSD, ISC'
license-checker --packages 'react@16.3.0;react-dom@16.3.0;lodash@4.3.1'
license-checker --excludePackages 'internal-1;internal-2'
license-checker --excludeScopes '@babel;@hapi'
license-checker --onlyunknown
```

Expand Down
1 change: 1 addition & 0 deletions bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (args.help) {
' --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',
' --excludePrivatePackages restrict output to not include any package marked as private',
' --excludeScopes [list] excludes all packages from the semicolon-seperated list',
'',
' --version The current version',
' --help The text you are reading right now :)',
Expand Down
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var nopt = require('nopt'),
packages: String,
excludePackages: String,
excludePrivatePackages: Boolean,
excludeScopes: String,
},
shorts = {
"v": ["--version"],
Expand Down
11 changes: 11 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,17 @@ exports.init = function(options, callback) {
});
}

if(options.excludeScopes) {
Object.keys(filtered).forEach(function(key) {
let scopes = options.excludeScopes.split(';');
scopes.forEach(s => {
if (s.trim() && key.startsWith(`${s.trim()}/`)) {
delete restricted[key];
}
});
});
}

Object.keys(restricted).forEach(function(item) {
if (toCheckforFailOn.length > 0) {
if (toCheckforFailOn.indexOf(restricted[item].licenses) > -1) {
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/excludeScopes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@scoped/one-in-a-million",
"version": "0.0.0",
"licenses": [
{
"type": "Apache License, Version 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
]
}
22 changes: 22 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ describe('main tests', function() {
});
});

function parseAndExcludeScops(parsePath, scopes, result) {
return function(done) {
checker.init({
start: path.join(__dirname, parsePath),
excludeScopes: scopes
}, function(err, filtered) {
result.output = filtered;
done();
});
};
}

describe('should parse local with excludeScopes', function() {
var result={};
before(parseAndExcludeScops('./fixtures/excludeScopes', "@scoped;@babel", result));

it('should exclude scope from list', function() {
var empty = Object.keys(result.output).length === 0;
assert.ok(empty);
});
});

function parseAndExclude(parsePath, licenses, result) {
return function(done) {
checker.init({
Expand Down