rolldown-license-plugin 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,8 @@
1
1
  # rolldown-license-plugin
2
2
 
3
- [![](https://img.shields.io/npm/v/rolldown-license-plugin.svg?style=flat)](https://www.npmjs.org/package/rolldown-license-plugin) [![](https://img.shields.io/npm/dm/rolldown-license-plugin.svg)](https://www.npmjs.org/package/rolldown-license-plugin)
3
+ [![](https://img.shields.io/npm/v/rolldown-license-plugin.svg?style=flat)](https://www.npmjs.org/package/rolldown-license-plugin) [![](https://img.shields.io/npm/dm/rolldown-license-plugin.svg)](https://www.npmjs.org/package/rolldown-license-plugin) [![](https://depx.co/api/badge/rolldown-license-plugin)](https://depx.co/pkg/rolldown-license-plugin)
4
4
 
5
- Rolldown plugin to extract dependency licenses from bundled `node_modules` with zero dependencies.
6
-
7
- ## Installation
8
-
9
- ```console
10
- npm i rolldown-license-plugin
11
- ```
5
+ Rolldown plugin to extract dependency licenses.
12
6
 
13
7
  ## Usage
14
8
 
@@ -19,8 +13,8 @@ export default {
19
13
  plugins: [
20
14
  licensePlugin({
21
15
  onDone(licenses) {
22
- // licenses is an array of {name, version, license, licenseText}
23
16
  console.info(licenses);
17
+ // => [{name, version, license, licenseText}]
24
18
  },
25
19
  }),
26
20
  ],
@@ -31,7 +25,7 @@ export default {
31
25
 
32
26
  ### `licensePlugin(opts)`
33
27
 
34
- Returns a Rolldown plugin.
28
+ Returns the plugin.
35
29
 
36
30
  #### `opts.onDone`
37
31
 
@@ -52,6 +46,12 @@ Type: `number`
52
46
 
53
47
  When set, word-wrap `licenseText` to this column width.
54
48
 
49
+ #### `opts.allow`
50
+
51
+ Type: `(license: LicenseInfo) => boolean`
52
+
53
+ Validate each dependency's license. Return `false` to throw a build error.
54
+
55
55
  ### `LicenseInfo`
56
56
 
57
57
  ```typescript
@@ -63,6 +63,10 @@ type LicenseInfo = {
63
63
  };
64
64
  ```
65
65
 
66
+ ### `wrap(length)`
67
+
68
+ Function to word-wrap text to a certain column width.
69
+
66
70
  ## License
67
71
 
68
72
  © [silverwind](https://github.com/silverwind), distributed under BSD-2-Clause.
package/dist/index.d.ts CHANGED
@@ -5741,7 +5741,8 @@ type LicenseInfo = {
5741
5741
  type RolldownLicensePluginOpts = {
5742
5742
  /** Called during `generateBundle` with the collected license data, sorted by name */onDone: (licenses: LicenseInfo[]) => void; /** Regex to match license filenames. Default: `/^((UN)?LICEN(S|C)E|COPYING).*$/i` */
5743
5743
  match?: RegExp; /** When set, word-wrap `licenseText` to this column width */
5744
- wrapText?: number;
5744
+ wrapText?: number; /** Validate each dependency's license. Return `false` to throw a build error */
5745
+ allow?: (license: LicenseInfo) => boolean;
5745
5746
  };
5746
5747
  /** Word-wrap plain text to a specified column width */
5747
5748
  declare function wrap(text: string, width: number): string;
@@ -5749,7 +5750,8 @@ declare function wrap(text: string, width: number): string;
5749
5750
  declare const licensePlugin: ({
5750
5751
  onDone,
5751
5752
  match,
5752
- wrapText
5753
+ wrapText,
5754
+ allow
5753
5755
  }: RolldownLicensePluginOpts) => Plugin;
5754
5756
  //#endregion
5755
5757
  export { LicenseInfo, RolldownLicensePluginOpts, licensePlugin, wrap };
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ function parseLicense(pkgJson) {
40
40
  return "";
41
41
  }
42
42
  /** Rolldown plugin that extracts license information from bundled dependencies */
43
- const licensePlugin = ({ onDone, match = defaultMatch, wrapText }) => ({
43
+ const licensePlugin = ({ onDone, match = defaultMatch, wrapText, allow }) => ({
44
44
  name: "rolldown-license-plugin",
45
45
  async generateBundle(_opts, bundle) {
46
46
  const pkgJsonCache = /* @__PURE__ */ new Map();
@@ -106,6 +106,10 @@ const licensePlugin = ({ onDone, match = defaultMatch, wrapText }) => ({
106
106
  };
107
107
  }));
108
108
  licenses.sort((a, b) => a.name.localeCompare(b.name));
109
+ if (allow) {
110
+ const violations = licenses.filter((entry) => !allow(entry));
111
+ if (violations.length) throw new Error(`License violation in: ${violations.map((entry) => `${entry.name}@${entry.version} (${entry.license || "unlicensed"})`).join(", ")}`);
112
+ }
109
113
  onDone(licenses);
110
114
  }
111
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",