xz64 / license-webpack-plugin

Outputs licenses from 3rd party libraries to a file
ISC License
165 stars 51 forks source link

License whitelist #123

Open jojomatik opened 2 years ago

jojomatik commented 2 years ago

I've seen in the docs that unacceptableLicenseTest can be used to blacklist certain licenses.

To be totally safe though I'd like to be able to whitelist certain licenses, so that the build process fails if any other license is found.

Is this possible? Could this be implemented?

lokanx commented 2 years ago

You can do that with unacceptableLicenseTest easily, example that breaks the build if a non-white-listed license are found

const ACCEPTABLE_LICENSE_TYPES = [
  'MIT',
  'Apache-2.0',
  'ISC',
  'BSD-3-Clause'
];

...

 new LicenseWebpackPlugin({
   ...
   unacceptableLicenseTest: (licenseType) => !ACCEPTABLE_LICENSE_TYPES.includes(licenseType),
   handleUnacceptableLicense: (packageName, licenseType) => {
        console.error("Unacceptable license found: packageName=", packageName, ", licenseType=", licenseType);
        process.exit(-1);
   },
   ...
 })

I suggest you handle missing licenses in the same way, eg break the build on that as well.