rolldown-license-plugin 2.2.5 → 3.0.1
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 +5 -6
- package/dist/index.d.ts +5 -3
- package/dist/index.js +20 -20
- package/package.json +6 -6
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
|
|
|
@@ -13,13 +13,12 @@ export default {
|
|
|
13
13
|
plugins: [
|
|
14
14
|
licensePlugin({
|
|
15
15
|
done(deps, context) {
|
|
16
|
-
const content = deps.map(({name, version, license, licenseText}) => (
|
|
17
|
-
`${name} ${version} (${license})\n${licenseText}`
|
|
18
|
-
)).join("\n\n");
|
|
19
16
|
context.emitFile({
|
|
20
17
|
type: "asset",
|
|
21
18
|
fileName: "licenses.txt",
|
|
22
|
-
source:
|
|
19
|
+
source: deps.map(({name, version, license, licenseText}) => {
|
|
20
|
+
return `${name}@${version} - ${license}\n${licenseText}`;
|
|
21
|
+
}).join("\n\n"),
|
|
23
22
|
});
|
|
24
23
|
},
|
|
25
24
|
}),
|
|
@@ -46,7 +45,7 @@ Default: `/^((UN)?LICEN(S|C)E|COPYING).*$/i`
|
|
|
46
45
|
|
|
47
46
|
Regex to match license filenames in package directories.
|
|
48
47
|
|
|
49
|
-
#### `opts.
|
|
48
|
+
#### `opts.wrapLicenseText`
|
|
50
49
|
|
|
51
50
|
Type: `number`
|
|
52
51
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,21 +12,23 @@ 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;
|
|
19
19
|
};
|
|
20
20
|
/** Word-wrap plain text to a specified column width */
|
|
21
21
|
declare function wrap(text: string, width: number): string;
|
|
22
|
+
/** Resolve the package root directory from a file path inside node_modules */
|
|
23
|
+
declare function findPkgRoot(fsPath: string): string | null;
|
|
22
24
|
/** Rolldown plugin that extracts license information from bundled dependencies */
|
|
23
25
|
declare const licensePlugin: ({
|
|
24
26
|
done,
|
|
25
27
|
match,
|
|
26
|
-
|
|
28
|
+
wrapLicenseText,
|
|
27
29
|
allow,
|
|
28
30
|
failOnViolation,
|
|
29
31
|
failOnUnlicensed
|
|
30
32
|
}: RolldownLicensePluginOpts) => Plugin;
|
|
31
33
|
//#endregion
|
|
32
|
-
export { LicenseInfo, RolldownLicensePluginOpts, licensePlugin, wrap };
|
|
34
|
+
export { LicenseInfo, RolldownLicensePluginOpts, findPkgRoot, licensePlugin, wrap };
|
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
|
|
@@ -39,30 +39,30 @@ function parseLicense(pkgJson) {
|
|
|
39
39
|
return "";
|
|
40
40
|
}
|
|
41
41
|
const nmSep = "/node_modules/";
|
|
42
|
+
const needsPathNormalize = sep !== "/";
|
|
42
43
|
/** Resolve the package root directory from a file path inside node_modules */
|
|
43
44
|
function findPkgRoot(fsPath) {
|
|
44
|
-
const p =
|
|
45
|
+
const p = needsPathNormalize ? fsPath.replaceAll(sep, "/") : fsPath;
|
|
45
46
|
const nmIdx = p.lastIndexOf(nmSep);
|
|
46
47
|
if (nmIdx === -1) return null;
|
|
47
48
|
const base = nmIdx + 14;
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
const firstSlash = rest.indexOf("/");
|
|
49
|
+
const firstSlash = p.indexOf("/", base);
|
|
50
|
+
if (p.startsWith("@", base)) {
|
|
51
51
|
if (firstSlash === -1) return null;
|
|
52
|
-
const secondSlash =
|
|
53
|
-
return
|
|
52
|
+
const secondSlash = p.indexOf("/", firstSlash + 1);
|
|
53
|
+
return secondSlash === -1 ? p : p.slice(0, secondSlash);
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
return p.slice(0, base) + rest.slice(0, firstSlash === -1 ? rest.length : firstSlash);
|
|
55
|
+
return firstSlash === -1 ? p : p.slice(0, firstSlash);
|
|
57
56
|
}
|
|
58
57
|
/** Rolldown plugin that extracts license information from bundled dependencies */
|
|
59
|
-
const licensePlugin = ({ done, match = defaultMatch,
|
|
58
|
+
const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
|
|
60
59
|
name: "rolldown-license-plugin",
|
|
61
60
|
async generateBundle(_opts, bundle) {
|
|
62
61
|
const roots = /* @__PURE__ */ new Set();
|
|
63
62
|
for (const chunk of Object.values(bundle)) {
|
|
64
63
|
if (chunk.type !== "chunk") continue;
|
|
65
64
|
for (const moduleId of Object.keys(chunk.modules)) {
|
|
65
|
+
if (moduleId[0] === "\0") continue;
|
|
66
66
|
const qIdx = moduleId.indexOf("?");
|
|
67
67
|
const root = findPkgRoot(qIdx === -1 ? moduleId : moduleId.slice(0, qIdx));
|
|
68
68
|
if (root) roots.add(root);
|
|
@@ -83,14 +83,14 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
|
|
|
83
83
|
seen.add(key);
|
|
84
84
|
let licenseText = "";
|
|
85
85
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (
|
|
86
|
+
const licensePath = join(dir, "LICENSE");
|
|
87
|
+
if (existsSync(licensePath)) licenseText = readFileSync(licensePath, "utf8");
|
|
88
|
+
else {
|
|
89
|
+
const found = readdirSync(dir).find((entry) => match.test(entry));
|
|
90
|
+
if (found) licenseText = readFileSync(join(dir, found), "utf8");
|
|
91
|
+
}
|
|
92
|
+
} catch {}
|
|
93
|
+
if (wrapLicenseText && licenseText) licenseText = wrap(licenseText, wrapLicenseText).trim();
|
|
94
94
|
licenses.push({
|
|
95
95
|
name: pkgJson.name,
|
|
96
96
|
version: pkgJson.version ?? "",
|
|
@@ -98,7 +98,7 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
|
|
|
98
98
|
licenseText
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
licenses.sort((a, b) => a.name.
|
|
101
|
+
licenses.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
102
102
|
if (allow) {
|
|
103
103
|
const errors = [];
|
|
104
104
|
for (const entry of licenses) {
|
|
@@ -115,4 +115,4 @@ const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViol
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
//#endregion
|
|
118
|
-
export { licensePlugin, wrap };
|
|
118
|
+
export { findPkgRoot, licensePlugin, wrap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-license-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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.
|
|
23
|
+
"@typescript/native-preview": "7.0.0-dev.20260415.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.
|
|
29
|
-
"tsdown-config-silverwind": "2.0.
|
|
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.
|
|
32
|
+
"updates": "17.15.3",
|
|
33
33
|
"updates-config-silverwind": "2.1.0",
|
|
34
|
-
"versions": "14.2
|
|
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"
|