rolldown-license-plugin 3.0.5 → 3.0.6

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +35 -34
  3. package/package.json +9 -9
package/README.md CHANGED
@@ -57,7 +57,7 @@ When set, word-wrap `licenseText` to this column width.
57
57
  Type: `(license: LicenseInfo) => boolean`\
58
58
  Default: `undefined` (no validation)
59
59
 
60
- Validate each dependency's license. Return `false` to reject it. By default, rejected dependencies are warned via `console.warn`. Use `failOnViolation` and `failOnUnlicensed` to throw build errors instead.
60
+ Validate each dependency's license. Return `false` to reject it. By default, rejected dependencies are reported via the rolldown plugin context's `warn`. Use `failOnViolation` and `failOnUnlicensed` to throw build errors instead.
61
61
 
62
62
  #### `opts.failOnViolation`
63
63
 
package/dist/index.js CHANGED
@@ -3,30 +3,31 @@ import { join, sep } from "node:path";
3
3
 
4
4
  //#region index.ts
5
5
  const defaultMatch = /^((UN)?LICEN(S|C)E|COPYING).*$/i;
6
+ const emptyText = Promise.resolve("");
6
7
  /** Word-wrap plain text to a specified column width */
7
8
  function wrap(text, width) {
8
9
  const lines = [];
9
10
  for (const rawLine of text.replace(/\r/g, "").split("\n")) {
10
- const trimmed = rawLine.replace(/\t/g, (_tab, offset) => " ".repeat(8 - offset % 8)).trim();
11
- if (trimmed.length <= width) {
12
- lines.push(trimmed);
11
+ const line = rawLine.replace(/\t/g, (_tab, offset) => " ".repeat(8 - offset % 8)).trimEnd();
12
+ if (line.length <= width) {
13
+ lines.push(line);
13
14
  continue;
14
15
  }
15
16
  let pos = 0;
16
- while (pos < trimmed.length) {
17
- if (pos + width >= trimmed.length) {
18
- lines.push(trimmed.slice(pos).trim());
17
+ while (pos < line.length) {
18
+ if (pos + width >= line.length) {
19
+ lines.push(line.slice(pos).trimEnd());
19
20
  break;
20
21
  }
21
- let breakAt = trimmed.lastIndexOf(" ", pos + width);
22
+ let breakAt = line.lastIndexOf(" ", pos + width);
22
23
  if (breakAt <= pos) {
23
- breakAt = trimmed.indexOf(" ", pos + width);
24
+ breakAt = line.indexOf(" ", pos + width);
24
25
  if (breakAt === -1) {
25
- lines.push(trimmed.slice(pos).trim());
26
+ lines.push(line.slice(pos).trimEnd());
26
27
  break;
27
28
  }
28
29
  }
29
- lines.push(trimmed.slice(pos, breakAt).trimEnd());
30
+ lines.push(line.slice(pos, breakAt).trimEnd());
30
31
  pos = breakAt + 1;
31
32
  }
32
33
  }
@@ -68,39 +69,39 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
68
69
  if (root) roots.add(root);
69
70
  }
70
71
  }
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;
72
+ const dirs = Array.from(roots);
73
+ const [pkgRaws, dirEntries] = await Promise.all([Promise.all(dirs.map((dir) => readFile(join(dir, "package.json"), "utf8").catch(() => null))), Promise.all(dirs.map((dir) => readdir(dir).catch(() => null)))]);
74
+ const seen = /* @__PURE__ */ new Set();
75
+ const unique = [];
76
+ for (let i = 0; i < dirs.length; i++) {
77
+ const pkgRaw = pkgRaws[i];
78
+ if (pkgRaw === null) continue;
74
79
  let pkgJson;
75
80
  try {
76
81
  pkgJson = JSON.parse(pkgRaw);
77
82
  } catch {
78
- return null;
83
+ continue;
79
84
  }
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;
85
+ if (!pkgJson.name) continue;
93
86
  const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
94
87
  if (seen.has(key)) continue;
95
88
  seen.add(key);
96
- const licenseText = wrapLicenseText && item.licenseText ? wrap(item.licenseText, wrapLicenseText).trim() : item.licenseText;
97
- licenses.push({
89
+ unique.push({
90
+ dir: dirs[i],
91
+ pkgJson,
92
+ licenseFile: dirEntries[i]?.find((entry) => match.test(entry))
93
+ });
94
+ }
95
+ const licenseTexts = await Promise.all(unique.map(({ dir, licenseFile }) => licenseFile ? readFile(join(dir, licenseFile), "utf8").catch(() => "") : emptyText));
96
+ const licenses = unique.map(({ pkgJson }, i) => {
97
+ const raw = licenseTexts[i];
98
+ return {
98
99
  name: pkgJson.name,
99
100
  version: pkgJson.version ?? "",
100
101
  license: parseLicense(pkgJson),
101
- licenseText
102
- });
103
- }
102
+ licenseText: wrapLicenseText && raw ? wrap(raw, wrapLicenseText).trim() : raw
103
+ };
104
+ });
104
105
  licenses.sort((a, b) => a.name.localeCompare(b.name));
105
106
  if (allow) {
106
107
  const errors = [];
@@ -109,9 +110,9 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
109
110
  const fail = entry.license ? failOnViolation : failOnUnlicensed;
110
111
  const msg = entry.license ? `Dependency "${entry.name}" has an incompatible license: ${entry.license}` : `Dependency "${entry.name}" does not specify any license.`;
111
112
  if (fail) errors.push(msg);
112
- else console.warn(msg);
113
+ else this.warn(msg);
113
114
  }
114
- if (errors.length) throw new Error(errors.join("\n"));
115
+ if (errors.length) this.error(errors.join("\n"));
115
116
  }
116
117
  await done(licenses, this);
117
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
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.7.0",
34
- "@typescript/native-preview": "7.0.0-dev.20260512.1",
35
- "eslint": "10.3.0",
33
+ "@types/node": "25.8.0",
34
+ "@typescript/native-preview": "7.0.0-dev.20260515.1",
35
+ "eslint": "10.4.0",
36
36
  "eslint-config-silverwind": "133.0.1",
37
37
  "jest-extended": "7.0.0",
38
- "rolldown": "1.0.0",
38
+ "rolldown": "1.0.1",
39
39
  "tsdown": "0.22.0",
40
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.10",
43
+ "updates": "17.16.12",
44
44
  "updates-config-silverwind": "3.0.2",
45
- "versions": "15.0.3",
46
- "vite": "8.0.12",
45
+ "versions": "15.0.4",
46
+ "vite": "8.0.13",
47
47
  "vitest": "4.1.6",
48
- "vitest-config-silverwind": "11.3.4"
48
+ "vitest-config-silverwind": "11.3.5"
49
49
  }
50
50
  }