https://github.com/silverwind/rolldown-license-plugin
Rolldown plugin to extract dependency licenses and optionally validate them. Zero dependencies, optimized for performance.
https://github.com/silverwind/rolldown-license-plugin
Last synced: 16 days ago
JSON representation
Rolldown plugin to extract dependency licenses and optionally validate them. Zero dependencies, optimized for performance.
- Host: GitHub
- URL: https://github.com/silverwind/rolldown-license-plugin
- Owner: silverwind
- License: bsd-2-clause
- Created: 2026-04-07T18:32:19.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2026-05-24T08:53:38.000Z (20 days ago)
- Last Synced: 2026-05-24T10:25:40.885Z (20 days ago)
- Language: TypeScript
- Homepage:
- Size: 350 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# rolldown-license-plugin
[](https://www.npmjs.org/package/rolldown-license-plugin) [](https://www.npmjs.org/package/rolldown-license-plugin) [](https://packagephobia.com/result?p=rolldown-license-plugin) [](https://depx.co/pkg/rolldown-license-plugin)
Rolldown plugin to extract dependency licenses and optionally validate them. Zero dependencies, optimized for performance.
## Usage
```js
import {defineConfig} from "rolldown";
import {licensePlugin} from "rolldown-license-plugin";
export default defineConfig({
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"),
});
},
}),
],
});
```
This also works with Vite, using `defineConfig` from `vite`.
## API
### `licensePlugin(opts)`
Returns the plugin.
#### `opts.done`
Type: `(licenses: LicenseInfo[], context: PluginContext) => void | Promise`
Callback invoked during `generateBundle` with the collected license data. The `context` parameter provides access to rolldown's plugin context, including `emitFile`.
#### `opts.match`
Type: `RegExp`\
Default: `/^((UN)?LICEN(S|C)E|COPYING).*$/i`
Regex to match license filenames in package directories.
#### `opts.wrapLicenseText`
Type: `number`\
Default: `undefined` (no wrapping)
When set, word-wrap `licenseText` to this column width.
#### `opts.allow`
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.
#### `opts.failOnViolation`
Type: `boolean`\
Default: `false`
Throw a build error when a dependency has an incompatible license.
#### `opts.failOnUnlicensed`
Type: `boolean`\
Default: `false`
Throw a build error when a dependency does not specify any license.
### `LicenseInfo`
```typescript
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 ""
};
```
### `wrap(text, width)`
Function to word-wrap `text` to a certain column `width`. Returns the wrapped string.
## License
© [silverwind](https://github.com/silverwind), distributed under BSD-2-Clause.