rolldown-license-plugin 3.0.5 → 3.0.7

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 +45 -38
  3. package/package.json +10 -10
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
@@ -7,26 +7,26 @@ 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, (_tab, offset) => " ".repeat(8 - offset % 8)).trim();
11
- if (trimmed.length <= width) {
12
- lines.push(trimmed);
10
+ const line = rawLine.replace(/\t/g, (_tab, offset) => " ".repeat(8 - offset % 8)).trimEnd();
11
+ if (line.length <= width) {
12
+ lines.push(line);
13
13
  continue;
14
14
  }
15
15
  let pos = 0;
16
- while (pos < trimmed.length) {
17
- if (pos + width >= trimmed.length) {
18
- lines.push(trimmed.slice(pos).trim());
16
+ while (pos < line.length) {
17
+ if (pos + width >= line.length) {
18
+ lines.push(line.slice(pos).trimEnd());
19
19
  break;
20
20
  }
21
- let breakAt = trimmed.lastIndexOf(" ", pos + width);
21
+ let breakAt = line.lastIndexOf(" ", pos + width);
22
22
  if (breakAt <= pos) {
23
- breakAt = trimmed.indexOf(" ", pos + width);
23
+ breakAt = line.indexOf(" ", pos + width);
24
24
  if (breakAt === -1) {
25
- lines.push(trimmed.slice(pos).trim());
25
+ lines.push(line.slice(pos).trimEnd());
26
26
  break;
27
27
  }
28
28
  }
29
- lines.push(trimmed.slice(pos, breakAt).trimEnd());
29
+ lines.push(line.slice(pos, breakAt).trimEnd());
30
30
  pos = breakAt + 1;
31
31
  }
32
32
  }
@@ -68,50 +68,57 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
68
68
  if (root) roots.add(root);
69
69
  }
70
70
  }
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;
71
+ const dirs = Array.from(roots);
72
+ const pkgRaws = await Promise.all(dirs.map((dir) => readFile(join(dir, "package.json"), "utf8").catch(() => null)));
73
+ const seen = /* @__PURE__ */ new Set();
74
+ const pkgs = [];
75
+ for (let idx = 0; idx < dirs.length; idx++) {
76
+ const pkgRaw = pkgRaws[idx];
77
+ if (pkgRaw === null) continue;
74
78
  let pkgJson;
75
79
  try {
76
80
  pkgJson = JSON.parse(pkgRaw);
77
81
  } catch {
78
- return null;
82
+ continue;
79
83
  }
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;
93
- const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
84
+ const name = pkgJson.name;
85
+ if (!name) continue;
86
+ const version = pkgJson.version ?? "";
87
+ const key = `${name}@${version}`;
94
88
  if (seen.has(key)) continue;
95
89
  seen.add(key);
96
- const licenseText = wrapLicenseText && item.licenseText ? wrap(item.licenseText, wrapLicenseText).trim() : item.licenseText;
97
- licenses.push({
98
- name: pkgJson.name,
99
- version: pkgJson.version ?? "",
100
- license: parseLicense(pkgJson),
101
- licenseText
90
+ pkgs.push({
91
+ dir: dirs[idx],
92
+ name,
93
+ version,
94
+ license: parseLicense(pkgJson)
102
95
  });
103
96
  }
97
+ const probeDirect = match.test("LICENSE");
98
+ const licenses = await Promise.all(pkgs.map(async ({ dir, name, version, license }) => {
99
+ const read = (file) => readFile(join(dir, file), "utf8").catch(() => "");
100
+ let raw = probeDirect ? await read("LICENSE") : "";
101
+ if (!raw) {
102
+ const file = (await readdir(dir).catch(() => null))?.find((entry) => match.test(entry));
103
+ if (file) raw = await read(file);
104
+ }
105
+ return {
106
+ name,
107
+ version,
108
+ license,
109
+ licenseText: wrapLicenseText && raw ? wrap(raw, wrapLicenseText).trim() : raw
110
+ };
111
+ }));
104
112
  licenses.sort((a, b) => a.name.localeCompare(b.name));
105
113
  if (allow) {
106
114
  const errors = [];
107
115
  for (const entry of licenses) {
108
116
  if (allow(entry)) continue;
109
- const fail = entry.license ? failOnViolation : failOnUnlicensed;
110
- const msg = entry.license ? `Dependency "${entry.name}" has an incompatible license: ${entry.license}` : `Dependency "${entry.name}" does not specify any license.`;
117
+ const [msg, fail] = entry.license ? [`Dependency "${entry.name}" has an incompatible license: ${entry.license}`, failOnViolation] : [`Dependency "${entry.name}" does not specify any license.`, failOnUnlicensed];
111
118
  if (fail) errors.push(msg);
112
- else console.warn(msg);
119
+ else this.warn(msg);
113
120
  }
114
- if (errors.length) throw new Error(errors.join("\n"));
121
+ if (errors.length) this.error(errors.join("\n"));
115
122
  }
116
123
  await done(licenses, this);
117
124
  }
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.7",
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",
36
- "eslint-config-silverwind": "133.0.1",
33
+ "@types/node": "25.8.0",
34
+ "@typescript/native-preview": "7.0.0-dev.20260517.1",
35
+ "eslint": "10.4.0",
36
+ "eslint-config-silverwind": "133.0.3",
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
  }