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

Add alwaysInclude & filters options #1326

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Expand Up @@ -264,6 +264,32 @@ license({
})
```


You can also add or remove dependencies using a `filter` function:

```javascript
license({
thirdParty: {
output: path.join(__dirname, 'dist', 'dependencies.txt'),
filter: (deps) => deps.filter((dep) => !dep.name.include('mycorp'),
},
})
```

Or add packages that must always appear in the output, but would otherwise be omitted:


```javascript
license({
thirdParty: {
output: path.join(__dirname, 'dist', 'dependencies.txt'),
alwaysInclude: [ './node_modules/tailwindcss/package.json' ],
}
},
})

`alwaysInclude` may be either an array or a function that returns an array.

## License Checks

Starting with version 0.13, it is possible to ensure that dependencies does not violate any license restriction.
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"lint": "gulp lint",
"clean": "gulp clean",
"build": "gulp build",
"prepare": "gulp build",
"watch": "gulp watch",
"test": "gulp test",
"tdd": "gulp tdd",
Expand Down
5 changes: 5 additions & 0 deletions src/license-plugin-option.js
Expand Up @@ -62,6 +62,11 @@ const SCHEMA = {
validators.func(),
validators.object({
includePrivate: validators.boolean(),
alwaysInclude: [
validators.func(),
validators.array(),
],
filter: validators.func(),

allow: [
validators.string(),
Expand Down
13 changes: 12 additions & 1 deletion src/license-plugin.js
Expand Up @@ -301,8 +301,14 @@ class LicensePlugin {
return;
}

const alwaysInclude = thirdParty.alwaysInclude;
if (alwaysInclude) {
const entries = _.isFunction(alwaysInclude) ? alwaysInclude() : alwaysInclude;
entries.forEach((path) => this.scanDependency(path));
}

const includePrivate = thirdParty.includePrivate || false;
const outputDependencies = _.chain(this._dependencies)
let outputDependencies = _.chain(this._dependencies)
.values()
.filter((dependency) => includePrivate || !dependency.private)
.value();
Expand All @@ -312,6 +318,11 @@ class LicensePlugin {
return;
}

const filter = thirdParty.filter;
if (filter) {
outputDependencies = filter(outputDependencies);
}

const allow = thirdParty.allow;
if (allow) {
this._scanLicenseViolations(outputDependencies, allow);
Expand Down