rolldown-license-plugin 0.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/LICENSE +22 -0
- package/README.md +62 -0
- package/dist/index.d.ts +5748 -0
- package/dist/index.js +67 -0
- package/package.json +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region index.ts
|
|
6
|
+
const defaultMatch = /^((UN)?LICEN(S|C)E|COPYING).*$/i;
|
|
7
|
+
function parseLicense(pkgJson) {
|
|
8
|
+
if (typeof pkgJson.license === "string") return pkgJson.license;
|
|
9
|
+
if (pkgJson.license?.type) return pkgJson.license.type;
|
|
10
|
+
if (Array.isArray(pkgJson.licenses)) return pkgJson.licenses.map((entry) => typeof entry === "string" ? entry : entry?.type ?? "").filter(Boolean).join(" OR ");
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const licensePlugin = ({ onDone, match = defaultMatch }) => ({
|
|
14
|
+
name: "rolldown-license-plugin",
|
|
15
|
+
async generateBundle(_opts, bundle) {
|
|
16
|
+
const pkgJsonCache = /* @__PURE__ */ new Map();
|
|
17
|
+
const pkgDirs = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const chunk of Object.values(bundle)) {
|
|
19
|
+
if (chunk.type !== "chunk") continue;
|
|
20
|
+
for (const moduleId of Object.keys(chunk.modules)) {
|
|
21
|
+
const fsPath = moduleId.split("?")[0];
|
|
22
|
+
if (!fsPath.includes("node_modules")) continue;
|
|
23
|
+
let dir = dirname(fsPath);
|
|
24
|
+
let pkgJson = null;
|
|
25
|
+
while (dir !== dirname(dir) && dir.includes("node_modules")) {
|
|
26
|
+
const cached = pkgJsonCache.get(dir);
|
|
27
|
+
if (cached !== void 0) pkgJson = cached;
|
|
28
|
+
else {
|
|
29
|
+
try {
|
|
30
|
+
pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
31
|
+
} catch {
|
|
32
|
+
pkgJson = null;
|
|
33
|
+
}
|
|
34
|
+
pkgJsonCache.set(dir, pkgJson);
|
|
35
|
+
}
|
|
36
|
+
if (pkgJson?.name) break;
|
|
37
|
+
pkgJson = null;
|
|
38
|
+
dir = dirname(dir);
|
|
39
|
+
}
|
|
40
|
+
if (!pkgJson?.name) continue;
|
|
41
|
+
const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
|
|
42
|
+
if (!pkgDirs.has(key)) pkgDirs.set(key, {
|
|
43
|
+
dir,
|
|
44
|
+
pkgJson
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const licenses = await Promise.all(Array.from(pkgDirs.values(), async ({ dir, pkgJson }) => {
|
|
49
|
+
let licenseText = "";
|
|
50
|
+
try {
|
|
51
|
+
const licenseFile = (await readdir(dir)).find((entry) => match.test(entry));
|
|
52
|
+
if (licenseFile) licenseText = await readFile(join(dir, licenseFile), "utf8");
|
|
53
|
+
} catch {}
|
|
54
|
+
return {
|
|
55
|
+
name: pkgJson.name,
|
|
56
|
+
version: pkgJson.version ?? "",
|
|
57
|
+
license: parseLicense(pkgJson),
|
|
58
|
+
licenseText
|
|
59
|
+
};
|
|
60
|
+
}));
|
|
61
|
+
licenses.sort((a, b) => a.name.localeCompare(b.name));
|
|
62
|
+
onDone(licenses);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { licensePlugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rolldown-license-plugin",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Rolldown plugin to extract dependency licenses",
|
|
5
|
+
"author": "silverwind <me@silverwind.io>",
|
|
6
|
+
"repository": "silverwind/rolldown-license-plugin",
|
|
7
|
+
"license": "BSD-2-Clause",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "25.5.0",
|
|
20
|
+
"@typescript/native-preview": "7.0.0-dev.20260324.1",
|
|
21
|
+
"eslint": "10.1.0",
|
|
22
|
+
"eslint-config-silverwind": "127.1.4",
|
|
23
|
+
"jest-extended": "7.0.0",
|
|
24
|
+
"rolldown": "1.0.0-rc.13",
|
|
25
|
+
"tsdown": "0.21.4",
|
|
26
|
+
"tsdown-config-silverwind": "2.0.2",
|
|
27
|
+
"typescript": "5.9.3",
|
|
28
|
+
"typescript-config-silverwind": "16.1.0",
|
|
29
|
+
"updates": "17.11.2",
|
|
30
|
+
"updates-config-silverwind": "2.0.1",
|
|
31
|
+
"versions": "14.2.4",
|
|
32
|
+
"vitest": "4.1.1",
|
|
33
|
+
"vitest-config-silverwind": "11.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|