rolldown-license-plugin 3.0.6 → 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 (2) hide show
  1. package/dist/index.js +26 -20
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@ 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("");
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(join(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,33 +81,40 @@ 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
+ 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
+ }
98
105
  return {
99
- name: pkgJson.name,
100
- version: pkgJson.version ?? "",
101
- license: parseLicense(pkgJson),
106
+ name,
107
+ version,
108
+ license,
102
109
  licenseText: wrapLicenseText && raw ? wrap(raw, wrapLicenseText).trim() : raw
103
110
  };
104
- });
111
+ }));
105
112
  licenses.sort((a, b) => a.name.localeCompare(b.name));
106
113
  if (allow) {
107
114
  const errors = [];
108
115
  for (const entry of licenses) {
109
116
  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.`;
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];
112
118
  if (fail) errors.push(msg);
113
119
  else this.warn(msg);
114
120
  }
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.7",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "25.8.0",
34
- "@typescript/native-preview": "7.0.0-dev.20260515.1",
34
+ "@typescript/native-preview": "7.0.0-dev.20260517.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
38
  "rolldown": "1.0.1",
39
39
  "tsdown": "0.22.0",