Skip to content

Commit

Permalink
Merge pull request #1 from rhl2401/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
rhl2401 authored Dec 2, 2022
2 parents dd42afc + 41ec1f6 commit 2a9adc3
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 99 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

## Table of Contents

- [Introduction](#introduction)
- [Changes](#changes)
- [All options in alphabetical order](#all_options_in_alphabetical_order)
- [Exclusions](#exclusions)
- [Examples](#examples)
- [Custom format](#custom_format)
- [Requiring](#requiring)
- [Debugging](#debugging)
- [Related information sources on the internet](#all_options_in_alphabetical_order)
- [NPM License Checker](#npm-license-checker)
- [Table of Contents](#table-of-contents)
- [Introduction](#introduction)
- [Changes](#changes)
- [Version 3.1.0](#version-310)
- [Version 3.0.1](#version-301)
- [Version 3.0.0](#version-300)
- [All options in alphabetical order:](#all-options-in-alphabetical-order)
- [Exclusions](#exclusions)
- [Examples](#examples)
- [Custom format](#custom-format)
- [Requiring](#requiring)
- [Debugging](#debugging)
- [How Licenses are Found](#how-licenses-are-found)
- [Related information sources on the internet](#related-information-sources-on-the-internet)

<a name="introduction"/>

Expand Down Expand Up @@ -119,6 +125,7 @@ before.
- `--direct` look for direct dependencies only
- `--excludeLicenses [list]` exclude modules which licenses are in the comma-separated list from the output
- `--excludePackages [list]` restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") not in the semicolon-seperated list
- `--excludePackagesStartingWith [list]` exclude modules which names start with the comma-separated list from the output (useful for excluding modules from a specific vendor and such). Example: `--excludePackagesStartingWith "webpack;@types;@babel"`
- `--excludePrivatePackages` restrict output to not include any package marked as private
- `--failOn [list]` fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list
- `--files [path]` copy all license files to path and rename them to `module-name`@`version`-LICENSE.txt.
Expand Down
1 change: 1 addition & 0 deletions bin/license-checker-rseidelsohn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const usageMessage = [
' --direct look for direct dependencies only',
' --excludeLicenses [list] exclude modules which licenses are in the comma-separated list from the output',
' --excludePackages [list] restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") not in the semicolon-seperated list',
' --excludePackageStartingWith [list] excludes packages starting with anything the comma-separated list',
' --excludePrivatePackages restrict output to not include any package marked as private',
' --failOn [list] fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list',
' --files [path] copy all license files to path and rename them to `module-name`@`version`-LICENSE.txt.',
Expand Down
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const knownOpts = {
direct: Boolean,
excludeLicenses: String,
excludePackages: String,
excludePackagesStartingWith: String,
excludePrivatePackages: Boolean,
failOn: String,
files: require('path'),
Expand Down
11 changes: 6 additions & 5 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Options struct for the init() function
*/
export interface InitOpts {
export interface InitOpts {
/**
* Path to start checking dependencies from
*/
Expand Down Expand Up @@ -74,6 +74,10 @@
* Restrict output to not include any package marked as private
*/
excludePrivatePackages?: boolean | undefined;
/**
* Exclude modules starting with a specific string
*/
excludePackagesStartingWith?: string | undefined;
/**
* Look for direct dependencies only
*/
Expand Down Expand Up @@ -167,7 +171,4 @@ export interface ModuleInfos {
* Run the license check
* @param opts specifies the path to the module to check dependencies of
*/
export function init(
opts: InitOpts,
callback: (err: Error, ret: ModuleInfos) => void
): void;
export function init(opts: InitOpts, callback: (err: Error, ret: ModuleInfos) => void): void;
22 changes: 22 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,22 @@ exports.init = function init(args, callback) {
return resultJson;
}

function excludePackagesStartingWith(blacklist, filtered) {
const resultJson = {};

Object.keys(filtered).map((filteredPackage) => {
blacklist.forEach((blacklist) => {
if (!filteredPackage.startsWith(blacklist)) {
resultJson[filteredPackage] = filtered[filteredPackage];
} else {
delete filtered[filteredPackage];
}
});
});

return resultJson;
}

function exitIfCheckHits(packageName) {
const currentLicense = resultJson[packageName].licenses;

Expand Down Expand Up @@ -641,6 +657,12 @@ exports.init = function init(args, callback) {
resultJson = excludeBlacklist(blacklist, filtered);
}

// exclude by package name starting with a string
const excludeStartString = getOptionArray(args.excludePackagesStartingWith);
if (excludeStartString) {
resultJson = excludePackagesStartingWith(excludeStartString, filtered);
}

if (args.excludePrivatePackages) {
Object.keys(filtered).forEach(filterDeletePrivatePackages);
}
Expand Down
Loading

0 comments on commit 2a9adc3

Please sign in to comment.