rolldown-license-plugin 3.0.0 → 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 +3 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +15 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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
|
}),
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ type RolldownLicensePluginOpts = {
|
|
|
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,
|
|
@@ -29,4 +31,4 @@ declare const licensePlugin: ({
|
|
|
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
|
@@ -39,21 +39,20 @@ 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
58
|
const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
|
|
@@ -63,6 +62,7 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
|
|
|
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,8 +83,12 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
|
|
|
83
83
|
seen.add(key);
|
|
84
84
|
let licenseText = "";
|
|
85
85
|
try {
|
|
86
|
-
const
|
|
87
|
-
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
|
+
}
|
|
88
92
|
} catch {}
|
|
89
93
|
if (wrapLicenseText && licenseText) licenseText = wrap(licenseText, wrapLicenseText).trim();
|
|
90
94
|
licenses.push({
|
|
@@ -111,4 +115,4 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
|
|
|
111
115
|
});
|
|
112
116
|
|
|
113
117
|
//#endregion
|
|
114
|
-
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.0.
|
|
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,7 +20,7 @@
|
|
|
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",
|