Skip to content

Commit

Permalink
[Fixes #136] Document --start option and add the depth option for loo…
Browse files Browse the repository at this point in the history
…king into root dependencies or infinitely

Fixed merge conflicts and added tests.
  • Loading branch information
davglass committed Jan 10, 2019
1 parent d6ea08c commit b897345
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (args.help) {
' --production only show production dependencies.',
' --development only show development dependencies.',
' --unknown report guessed licenses as unknown licenses.',
' --start [path of the initial json to look for]',
' --onlyunknown only list packages with unknown or guessed licenses.',
' --json output in json format.',
' --csv output in csv format.',
Expand All @@ -32,6 +33,7 @@ if (args.help) {
' --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',
' --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',
' --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',
Expand Down
7 changes: 7 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var nopt = require('nopt'),
summary: Boolean,
failOn: String,
onlyAllow: String,
direct: Boolean,
packages: String,
excludePackages: String,
excludePrivatePackages: Boolean,
Expand Down Expand Up @@ -75,6 +76,12 @@ var setDefaults = function(parsed) {
parsed.start = parsed.start || process.cwd();
parsed.relativeLicensePath = !!parsed.relativeLicensePath;

if (parsed.direct) {
parsed.direct = 0;
} else {
parsed.direct = Infinity;
}

return parsed;
};

Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ exports.init = function(options, callback) {
}
var opts = {
dev: true,
log: debugLog
log: debugLog,
depth: options.direct
};

if (options.production || options.development) {
Expand Down Expand Up @@ -426,6 +427,7 @@ exports.init = function(options, callback) {

if (options.excludePrivatePackages) {
Object.keys(filtered).forEach(function(key) {
/*istanbul ignore next - I don't have access to private packages to test */
if (restricted[key] && restricted[key].private) {
delete restricted[key];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/packages-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('bin/license-checker', function() {
it('should restrict the output to the provided packages', function() {
var restrictedPackages = [
'[email protected]',
'[email protected]',
//'[email protected]',
'[email protected]',
];
var output = spawn('node', [path.join(__dirname, '../bin/license-checker'), '--json', '--packages', restrictedPackages.join(';')], {
Expand Down
13 changes: 13 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('main tests', function() {
describe('should parse local with unknown', function() {
var output;
before(function(done) {
this.timeout(5000);
checker.init({
start: path.join(__dirname, '../')
}, function(err, sorted) {
Expand Down Expand Up @@ -400,6 +401,18 @@ describe('main tests', function() {
assert.equal(result.start, path.resolve(path.join(__dirname, '../')));
});

it('should handle direct undefined', function() {
var result = args.defaults({ direct: undefined, start: path.resolve(path.join(__dirname, '../')) });
assert.equal(result.direct, Infinity);
assert.equal(result.start, path.resolve(path.join(__dirname, '../')));
});

it('should handle direct true', function() {
var result = args.defaults({ direct: true, start: path.resolve(path.join(__dirname, '../')) });
assert.equal(result.direct, 0);
assert.equal(result.start, path.resolve(path.join(__dirname, '../')));
});

['json', 'markdown', 'csv', 'summary'].forEach(function(type) {
it('should disable color on ' + type, function() {
var def = {
Expand Down

0 comments on commit b897345

Please sign in to comment.