Rolldown plugin to extract dependency licenses and optionally validate them. Zero dependencies, optimized for performance.
import {licensePlugin} from "rolldown-license-plugin";
export default {
plugins: [
licensePlugin({
done(deps, context) {
context.emitFile({
type: "asset",
fileName: "licenses.txt",
source: deps.map(({name, version, license, licenseText}) => {
return `${name}@${version} - ${license}\n${licenseText}`;
}).join("\n\n"),
});
},
}),
],
};Returns the plugin.
Type: (licenses: LicenseInfo[], context: PluginContext) => void | Promise<void>
Callback invoked during generateBundle with the collected license data. The context parameter provides access to rolldown's plugin context, including emitFile.
Type: RegExp
Default: /^((UN)?LICEN(S|C)E|COPYING).*$/i
Regex to match license filenames in package directories.
Type: number
Default: undefined (no wrapping)
When set, word-wrap licenseText to this column width.
Type: (license: LicenseInfo) => boolean
Default: undefined (no validation)
Validate each dependency's license. Return false to reject it. By default, rejected dependencies are reported via the rolldown plugin context's warn. Use failOnViolation and failOnUnlicensed to throw build errors instead.
Type: boolean
Default: false
Throw a build error when a dependency has an incompatible license.
Type: boolean
Default: false
Throw a build error when a dependency does not specify any license.
type LicenseInfo = {
name: string; // package name
version: string; // package version, or ""
license: string; // SPDX license identifier from package.json, or ""
licenseText: string; // contents of LICENSE/COPYING file, or ""
};Function to word-wrap text to a certain column width. Returns the wrapped string.
© silverwind, distributed under BSD-2-Clause.