rolldown-license-plugin 2.2.5 → 3.0.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
@@ -2,7 +2,7 @@
2
2
 
3
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.
5
+ Rolldown plugin to extract dependency licenses and optionally validate them. Zero dependencies, optimized for performance.
6
6
 
7
7
  ## Usage
8
8
 
@@ -46,7 +46,7 @@ Default: `/^((UN)?LICEN(S|C)E|COPYING).*$/i`
46
46
 
47
47
  Regex to match license filenames in package directories.
48
48
 
49
- #### `opts.wrapText`
49
+ #### `opts.wrapLicenseText`
50
50
 
51
51
  Type: `number`
52
52
 
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ type LicenseInfo = {
12
12
  type RolldownLicensePluginOpts = {
13
13
  /** Called during `generateBundle` with the collected license data, sorted by name */done: (licenses: LicenseInfo[], context: PluginContext) => void | Promise<void>; /** Regex to match license filenames. Default: `/^((UN)?LICEN(S|C)E|COPYING).*$/i` */
14
14
  match?: RegExp; /** When set, word-wrap `licenseText` to this column width */
15
- wrapText?: number; /** Validate each dependency's license. Return `false` to reject it */
15
+ wrapLicenseText?: number; /** Validate each dependency's license. Return `false` to reject it */
16
16
  allow?: (license: LicenseInfo) => boolean; /** Throw a build error when a dependency has an incompatible license. Default: `false` (warn only) */
17
17
  failOnViolation?: boolean; /** Throw a build error when a dependency does not specify any license. Default: `false` (warn only) */
18
18
  failOnUnlicensed?: boolean;
@@ -23,7 +23,7 @@ declare function wrap(text: string, width: number): string;
23
23
  declare const licensePlugin: ({
24
24
  done,
25
25
  match,
26
- wrapText,
26
+ wrapLicenseText,
27
27
  allow,
28
28
  failOnViolation,
29
29
  failOnUnlicensed
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFileSync, readdirSync } from "node:fs";
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import { join, sep } from "node:path";
3
3
 
4
4
  //#region index.ts
@@ -56,7 +56,7 @@ function findPkgRoot(fsPath) {
56
56
  return p.slice(0, base) + rest.slice(0, firstSlash === -1 ? rest.length : firstSlash);
57
57
  }
58
58
  /** Rolldown plugin that extracts license information from bundled dependencies */
59
- const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
59
+ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
60
60
  name: "rolldown-license-plugin",
61
61
  async generateBundle(_opts, bundle) {
62
62
  const roots = /* @__PURE__ */ new Set();
@@ -83,14 +83,10 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
83
83
  seen.add(key);
84
84
  let licenseText = "";
85
85
  try {
86
- licenseText = readFileSync(join(dir, "LICENSE"), "utf8");
87
- } catch {
88
- try {
89
- const licenseFile = readdirSync(dir).find((entry) => match.test(entry));
90
- if (licenseFile) licenseText = readFileSync(join(dir, licenseFile), "utf8");
91
- } catch {}
92
- }
93
- if (wrapText && licenseText) licenseText = wrap(licenseText, wrapText).trim();
86
+ const licenseFile = existsSync(join(dir, "LICENSE")) ? "LICENSE" : readdirSync(dir).find((entry) => match.test(entry));
87
+ if (licenseFile) licenseText = readFileSync(join(dir, licenseFile), "utf8");
88
+ } catch {}
89
+ if (wrapLicenseText && licenseText) licenseText = wrap(licenseText, wrapLicenseText).trim();
94
90
  licenses.push({
95
91
  name: pkgJson.name,
96
92
  version: pkgJson.version ?? "",
@@ -98,7 +94,7 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
98
94
  licenseText
99
95
  });
100
96
  }
101
- licenses.sort((a, b) => a.name.localeCompare(b.name));
97
+ licenses.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
102
98
  if (allow) {
103
99
  const errors = [];
104
100
  for (const entry of licenses) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "2.2.5",
3
+ "version": "3.0.0",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",
@@ -20,18 +20,18 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "25.6.0",
23
- "@typescript/native-preview": "7.0.0-dev.20260410.1",
23
+ "@typescript/native-preview": "7.0.0-dev.20260414.1",
24
24
  "eslint": "10.2.0",
25
25
  "eslint-config-silverwind": "131.0.4",
26
26
  "jest-extended": "7.0.0",
27
27
  "rolldown": "1.0.0-rc.15",
28
- "tsdown": "0.21.7",
29
- "tsdown-config-silverwind": "2.0.5",
28
+ "tsdown": "0.21.8",
29
+ "tsdown-config-silverwind": "2.0.6",
30
30
  "typescript": "6.0.2",
31
31
  "typescript-config-silverwind": "17.0.0",
32
- "updates": "17.14.0",
32
+ "updates": "17.15.3",
33
33
  "updates-config-silverwind": "2.1.0",
34
- "versions": "14.2.7",
34
+ "versions": "14.3.2",
35
35
  "vite": "8.0.8",
36
36
  "vitest": "4.1.4",
37
37
  "vitest-config-silverwind": "11.1.4"