rolldown-license-plugin 3.0.6 → 3.0.8

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 (2) hide show
  1. package/dist/index.js +34 -23
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { readFile, readdir } from "node:fs/promises";
2
- import { join, sep } from "node:path";
2
+ import { 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("");
7
6
  /** Word-wrap plain text to a specified column width */
8
7
  function wrap(text, width) {
9
8
  const lines = [];
@@ -70,11 +69,11 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
70
69
  }
71
70
  }
72
71
  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)))]);
72
+ const pkgRaws = await Promise.all(dirs.map((dir) => readFile(`${dir}/package.json`, "utf8").catch(() => null)));
74
73
  const seen = /* @__PURE__ */ new Set();
75
- const unique = [];
76
- for (let i = 0; i < dirs.length; i++) {
77
- const pkgRaw = pkgRaws[i];
74
+ const pkgs = [];
75
+ for (let idx = 0; idx < dirs.length; idx++) {
76
+ const pkgRaw = pkgRaws[idx];
78
77
  if (pkgRaw === null) continue;
79
78
  let pkgJson;
80
79
  try {
@@ -82,34 +81,46 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
82
81
  } catch {
83
82
  continue;
84
83
  }
85
- if (!pkgJson.name) continue;
86
- 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}`;
87
88
  if (seen.has(key)) continue;
88
89
  seen.add(key);
89
- unique.push({
90
- dir: dirs[i],
91
- pkgJson,
92
- licenseFile: dirEntries[i]?.find((entry) => match.test(entry))
90
+ pkgs.push({
91
+ dir: dirs[idx],
92
+ name,
93
+ version,
94
+ license: parseLicense(pkgJson)
93
95
  });
94
96
  }
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];
97
+ const probeDirect = match.test("LICENSE");
98
+ const licenses = await Promise.all(pkgs.map(async ({ dir, name, version, license }) => {
99
+ let raw = probeDirect ? await readFile(`${dir}/LICENSE`, "utf8").catch(() => "") : "";
100
+ if (!raw) {
101
+ const file = (await readdir(dir).catch(() => null))?.find((entry) => match.test(entry));
102
+ if (file) raw = await readFile(`${dir}/${file}`, "utf8").catch(() => "");
103
+ }
98
104
  return {
99
- name: pkgJson.name,
100
- version: pkgJson.version ?? "",
101
- license: parseLicense(pkgJson),
105
+ name,
106
+ version,
107
+ license,
102
108
  licenseText: wrapLicenseText && raw ? wrap(raw, wrapLicenseText).trim() : raw
103
109
  };
104
- });
105
- licenses.sort((a, b) => a.name.localeCompare(b.name));
110
+ }));
111
+ licenses.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
106
112
  if (allow) {
107
113
  const errors = [];
108
114
  for (const entry of licenses) {
109
115
  if (allow(entry)) continue;
110
- const fail = entry.license ? failOnViolation : failOnUnlicensed;
111
- const msg = entry.license ? `Dependency "${entry.name}" has an incompatible license: ${entry.license}` : `Dependency "${entry.name}" does not specify any license.`;
112
- if (fail) errors.push(msg);
116
+ if (!entry.license) {
117
+ const msg = `Dependency "${entry.name}" does not specify any license.`;
118
+ if (failOnUnlicensed) errors.push(msg);
119
+ else this.warn(msg);
120
+ continue;
121
+ }
122
+ const msg = `Dependency "${entry.name}" has an incompatible license: ${entry.license}`;
123
+ if (failOnViolation) errors.push(msg);
113
124
  else this.warn(msg);
114
125
  }
115
126
  if (errors.length) this.error(errors.join("\n"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
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.8.0",
34
- "@typescript/native-preview": "7.0.0-dev.20260515.1",
33
+ "@types/node": "25.9.1",
34
+ "@typescript/native-preview": "7.0.0-dev.20260524.1",
35
35
  "eslint": "10.4.0",
36
- "eslint-config-silverwind": "133.0.1",
36
+ "eslint-config-silverwind": "133.0.3",
37
37
  "jest-extended": "7.0.0",
38
- "rolldown": "1.0.1",
38
+ "rolldown": "1.0.2",
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.12",
43
+ "updates": "17.17.2",
44
44
  "updates-config-silverwind": "3.0.2",
45
45
  "versions": "15.0.4",
46
- "vite": "8.0.13",
47
- "vitest": "4.1.6",
46
+ "vite": "8.0.14",
47
+ "vitest": "4.1.7",
48
48
  "vitest-config-silverwind": "11.3.5"
49
49
  }
50
50
  }