rolldown-license-plugin 3.0.3 → 3.0.5

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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Plugin, PluginContext } from "rolldown";
2
2
 
3
3
  //#region index.d.ts
4
+ declare const defaultMatch: RegExp;
4
5
  /** License information for a single bundled dependency */
5
6
  type LicenseInfo = {
6
7
  /** Package name from package.json */name: string; /** Package version from package.json */
@@ -31,4 +32,4 @@ declare const licensePlugin: ({
31
32
  failOnUnlicensed
32
33
  }: RolldownLicensePluginOpts) => Plugin;
33
34
  //#endregion
34
- export { LicenseInfo, RolldownLicensePluginOpts, findPkgRoot, licensePlugin, wrap };
35
+ export { LicenseInfo, RolldownLicensePluginOpts, defaultMatch, findPkgRoot, licensePlugin, wrap };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, readdirSync } from "node:fs";
1
+ import { readFile, readdir } from "node:fs/promises";
2
2
  import { join, sep } from "node:path";
3
3
 
4
4
  //#region index.ts
@@ -7,7 +7,7 @@ const defaultMatch = /^((UN)?LICEN(S|C)E|COPYING).*$/i;
7
7
  function wrap(text, width) {
8
8
  const lines = [];
9
9
  for (const rawLine of text.replace(/\r/g, "").split("\n")) {
10
- const trimmed = rawLine.replace(/\t/g, (_, offset) => " ".repeat(8 - offset % 8)).trim();
10
+ const trimmed = rawLine.replace(/\t/g, (_tab, offset) => " ".repeat(8 - offset % 8)).trim();
11
11
  if (trimmed.length <= width) {
12
12
  lines.push(trimmed);
13
13
  continue;
@@ -42,17 +42,17 @@ const nmSep = "/node_modules/";
42
42
  const needsPathNormalize = sep !== "/";
43
43
  /** Resolve the package root directory from a file path inside node_modules */
44
44
  function findPkgRoot(fsPath) {
45
- const p = needsPathNormalize ? fsPath.replaceAll(sep, "/") : fsPath;
46
- const nmIdx = p.lastIndexOf(nmSep);
45
+ const normalized = needsPathNormalize ? fsPath.replaceAll(sep, "/") : fsPath;
46
+ const nmIdx = normalized.lastIndexOf(nmSep);
47
47
  if (nmIdx === -1) return null;
48
48
  const base = nmIdx + 14;
49
- const firstSlash = p.indexOf("/", base);
50
- if (p.startsWith("@", base)) {
49
+ const firstSlash = normalized.indexOf("/", base);
50
+ if (normalized.startsWith("@", base)) {
51
51
  if (firstSlash === -1) return null;
52
- const secondSlash = p.indexOf("/", firstSlash + 1);
53
- return secondSlash === -1 ? p : p.slice(0, secondSlash);
52
+ const secondSlash = normalized.indexOf("/", firstSlash + 1);
53
+ return secondSlash === -1 ? normalized : normalized.slice(0, secondSlash);
54
54
  }
55
- return firstSlash === -1 ? p : p.slice(0, firstSlash);
55
+ return firstSlash === -1 ? normalized : normalized.slice(0, firstSlash);
56
56
  }
57
57
  /** Rolldown plugin that extracts license information from bundled dependencies */
58
58
  const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
@@ -68,29 +68,32 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
68
68
  if (root) roots.add(root);
69
69
  }
70
70
  }
71
- const seen = /* @__PURE__ */ new Set();
72
- const licenses = [];
73
- for (const dir of roots) {
71
+ const reads = await Promise.all(Array.from(roots, async (dir) => {
72
+ const [pkgRaw, entries] = await Promise.all([readFile(join(dir, "package.json"), "utf8").catch(() => null), readdir(dir).catch(() => null)]);
73
+ if (pkgRaw === null) return null;
74
74
  let pkgJson;
75
75
  try {
76
- pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
76
+ pkgJson = JSON.parse(pkgRaw);
77
77
  } catch {
78
- continue;
78
+ return null;
79
79
  }
80
- if (!pkgJson.name) continue;
80
+ if (!pkgJson.name) return null;
81
+ const found = entries?.find((entry) => match.test(entry));
82
+ const licenseText = found ? await readFile(join(dir, found), "utf8").catch(() => "") : "";
83
+ return {
84
+ pkgJson,
85
+ licenseText
86
+ };
87
+ }));
88
+ const seen = /* @__PURE__ */ new Set();
89
+ const licenses = [];
90
+ for (const item of reads) {
91
+ if (!item) continue;
92
+ const { pkgJson } = item;
81
93
  const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
82
94
  if (seen.has(key)) continue;
83
95
  seen.add(key);
84
- let licenseText = "";
85
- try {
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();
96
+ const licenseText = wrapLicenseText && item.licenseText ? wrap(item.licenseText, wrapLicenseText).trim() : item.licenseText;
94
97
  licenses.push({
95
98
  name: pkgJson.name,
96
99
  version: pkgJson.version ?? "",
@@ -98,7 +101,7 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
98
101
  licenseText
99
102
  });
100
103
  }
101
- licenses.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
104
+ licenses.sort((a, b) => a.name.localeCompare(b.name));
102
105
  if (allow) {
103
106
  const errors = [];
104
107
  for (const entry of licenses) {
@@ -115,4 +118,4 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
115
118
  });
116
119
 
117
120
  //#endregion
118
- export { findPkgRoot, licensePlugin, wrap };
121
+ export { defaultMatch, findPkgRoot, licensePlugin, wrap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",
@@ -30,21 +30,21 @@
30
30
  "rolldown": "*"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/node": "25.6.0",
34
- "@typescript/native-preview": "7.0.0-dev.20260427.1",
35
- "eslint": "10.2.1",
36
- "eslint-config-silverwind": "132.0.0",
33
+ "@types/node": "25.7.0",
34
+ "@typescript/native-preview": "7.0.0-dev.20260512.1",
35
+ "eslint": "10.3.0",
36
+ "eslint-config-silverwind": "133.0.1",
37
37
  "jest-extended": "7.0.0",
38
- "rolldown": "1.0.0-rc.17",
39
- "tsdown": "0.21.10",
40
- "tsdown-config-silverwind": "2.1.1",
38
+ "rolldown": "1.0.0",
39
+ "tsdown": "0.22.0",
40
+ "tsdown-config-silverwind": "3.0.1",
41
41
  "typescript": "6.0.3",
42
42
  "typescript-config-silverwind": "18.0.0",
43
- "updates": "17.16.4",
44
- "updates-config-silverwind": "2.1.1",
45
- "versions": "15.0.1",
46
- "vite": "8.0.10",
47
- "vitest": "4.1.5",
48
- "vitest-config-silverwind": "11.3.1"
43
+ "updates": "17.16.10",
44
+ "updates-config-silverwind": "3.0.2",
45
+ "versions": "15.0.3",
46
+ "vite": "8.0.12",
47
+ "vitest": "4.1.6",
48
+ "vitest-config-silverwind": "11.3.4"
49
49
  }
50
50
  }