rolldown-license-plugin 2.2.4 → 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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -14
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.org/package/rolldown-license-plugin) [](https://www.npmjs.org/package/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.
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
wrapLicenseText,
|
|
27
27
|
allow,
|
|
28
28
|
failOnViolation,
|
|
29
29
|
failOnUnlicensed
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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();
|
|
@@ -70,33 +70,31 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
|
|
|
70
70
|
}
|
|
71
71
|
const seen = /* @__PURE__ */ new Set();
|
|
72
72
|
const licenses = [];
|
|
73
|
-
|
|
73
|
+
for (const dir of roots) {
|
|
74
74
|
let pkgJson;
|
|
75
75
|
try {
|
|
76
|
-
pkgJson = JSON.parse(
|
|
76
|
+
pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
77
77
|
} catch {
|
|
78
|
-
|
|
78
|
+
continue;
|
|
79
79
|
}
|
|
80
|
-
if (!pkgJson.name)
|
|
80
|
+
if (!pkgJson.name) continue;
|
|
81
81
|
const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
|
|
82
|
-
if (seen.has(key))
|
|
82
|
+
if (seen.has(key)) continue;
|
|
83
83
|
seen.add(key);
|
|
84
84
|
let licenseText = "";
|
|
85
85
|
try {
|
|
86
|
-
const licenseFile = (
|
|
87
|
-
if (licenseFile)
|
|
88
|
-
licenseText = await readFile(join(dir, licenseFile), "utf8");
|
|
89
|
-
if (wrapText) licenseText = wrap(licenseText, wrapText).trim();
|
|
90
|
-
}
|
|
86
|
+
const licenseFile = existsSync(join(dir, "LICENSE")) ? "LICENSE" : readdirSync(dir).find((entry) => match.test(entry));
|
|
87
|
+
if (licenseFile) licenseText = readFileSync(join(dir, licenseFile), "utf8");
|
|
91
88
|
} catch {}
|
|
89
|
+
if (wrapLicenseText && licenseText) licenseText = wrap(licenseText, wrapLicenseText).trim();
|
|
92
90
|
licenses.push({
|
|
93
91
|
name: pkgJson.name,
|
|
94
92
|
version: pkgJson.version ?? "",
|
|
95
93
|
license: parseLicense(pkgJson),
|
|
96
94
|
licenseText
|
|
97
95
|
});
|
|
98
|
-
}
|
|
99
|
-
licenses.sort((a, b) => a.name.
|
|
96
|
+
}
|
|
97
|
+
licenses.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
100
98
|
if (allow) {
|
|
101
99
|
const errors = [];
|
|
102
100
|
for (const entry of licenses) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-license-plugin",
|
|
3
|
-
"version": "
|
|
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",
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"rolldown": "*"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/node": "25.
|
|
23
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
22
|
+
"@types/node": "25.6.0",
|
|
23
|
+
"@typescript/native-preview": "7.0.0-dev.20260414.1",
|
|
24
24
|
"eslint": "10.2.0",
|
|
25
|
-
"eslint-config-silverwind": "131.0.
|
|
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.
|
|
29
|
-
"tsdown-config-silverwind": "2.0.
|
|
30
|
-
"typescript": "
|
|
28
|
+
"tsdown": "0.21.8",
|
|
29
|
+
"tsdown-config-silverwind": "2.0.6",
|
|
30
|
+
"typescript": "6.0.2",
|
|
31
31
|
"typescript-config-silverwind": "17.0.0",
|
|
32
|
-
"updates": "17.
|
|
33
|
-
"updates-config-silverwind": "2.0
|
|
34
|
-
"versions": "14.2
|
|
32
|
+
"updates": "17.15.3",
|
|
33
|
+
"updates-config-silverwind": "2.1.0",
|
|
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"
|