rolldown-license-plugin 3.0.0 → 3.0.2

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/README.md CHANGED
@@ -13,13 +13,12 @@ export default {
13
13
  plugins: [
14
14
  licensePlugin({
15
15
  done(deps, context) {
16
- const content = deps.map(({name, version, license, licenseText}) => (
17
- `${name} ${version} (${license})\n${licenseText}`
18
- )).join("\n\n");
19
16
  context.emitFile({
20
17
  type: "asset",
21
18
  fileName: "licenses.txt",
22
- source: content,
19
+ source: deps.map(({name, version, license, licenseText}) => {
20
+ return `${name}@${version} - ${license}\n${licenseText}`;
21
+ }).join("\n\n"),
23
22
  });
24
23
  },
25
24
  }),
@@ -48,13 +47,15 @@ Regex to match license filenames in package directories.
48
47
 
49
48
  #### `opts.wrapLicenseText`
50
49
 
51
- Type: `number`
50
+ Type: `number`\
51
+ Default: `undefined` (no wrapping)
52
52
 
53
53
  When set, word-wrap `licenseText` to this column width.
54
54
 
55
55
  #### `opts.allow`
56
56
 
57
- Type: `(license: LicenseInfo) => boolean`
57
+ Type: `(license: LicenseInfo) => boolean`\
58
+ Default: `undefined` (no validation)
58
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
61
 
package/dist/index.d.ts CHANGED
@@ -19,6 +19,8 @@ type RolldownLicensePluginOpts = {
19
19
  };
20
20
  /** Word-wrap plain text to a specified column width */
21
21
  declare function wrap(text: string, width: number): string;
22
+ /** Resolve the package root directory from a file path inside node_modules */
23
+ declare function findPkgRoot(fsPath: string): string | null;
22
24
  /** Rolldown plugin that extracts license information from bundled dependencies */
23
25
  declare const licensePlugin: ({
24
26
  done,
@@ -29,4 +31,4 @@ declare const licensePlugin: ({
29
31
  failOnUnlicensed
30
32
  }: RolldownLicensePluginOpts) => Plugin;
31
33
  //#endregion
32
- export { LicenseInfo, RolldownLicensePluginOpts, licensePlugin, wrap };
34
+ export { LicenseInfo, RolldownLicensePluginOpts, findPkgRoot, licensePlugin, wrap };
package/dist/index.js CHANGED
@@ -39,21 +39,20 @@ function parseLicense(pkgJson) {
39
39
  return "";
40
40
  }
41
41
  const nmSep = "/node_modules/";
42
+ const needsPathNormalize = sep !== "/";
42
43
  /** Resolve the package root directory from a file path inside node_modules */
43
44
  function findPkgRoot(fsPath) {
44
- const p = sep !== "/" ? fsPath.replaceAll(sep, "/") : fsPath;
45
+ const p = needsPathNormalize ? fsPath.replaceAll(sep, "/") : fsPath;
45
46
  const nmIdx = p.lastIndexOf(nmSep);
46
47
  if (nmIdx === -1) return null;
47
48
  const base = nmIdx + 14;
48
- const rest = p.slice(base);
49
- if (rest.startsWith("@")) {
50
- const firstSlash = rest.indexOf("/");
49
+ const firstSlash = p.indexOf("/", base);
50
+ if (p.startsWith("@", base)) {
51
51
  if (firstSlash === -1) return null;
52
- const secondSlash = rest.indexOf("/", firstSlash + 1);
53
- return p.slice(0, base) + rest.slice(0, secondSlash === -1 ? rest.length : secondSlash);
52
+ const secondSlash = p.indexOf("/", firstSlash + 1);
53
+ return secondSlash === -1 ? p : p.slice(0, secondSlash);
54
54
  }
55
- const firstSlash = rest.indexOf("/");
56
- return p.slice(0, base) + rest.slice(0, firstSlash === -1 ? rest.length : firstSlash);
55
+ return firstSlash === -1 ? p : p.slice(0, firstSlash);
57
56
  }
58
57
  /** Rolldown plugin that extracts license information from bundled dependencies */
59
58
  const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
@@ -63,6 +62,7 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
63
62
  for (const chunk of Object.values(bundle)) {
64
63
  if (chunk.type !== "chunk") continue;
65
64
  for (const moduleId of Object.keys(chunk.modules)) {
65
+ if (moduleId[0] === "\0") continue;
66
66
  const qIdx = moduleId.indexOf("?");
67
67
  const root = findPkgRoot(qIdx === -1 ? moduleId : moduleId.slice(0, qIdx));
68
68
  if (root) roots.add(root);
@@ -83,8 +83,12 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
83
83
  seen.add(key);
84
84
  let licenseText = "";
85
85
  try {
86
- const licenseFile = existsSync(join(dir, "LICENSE")) ? "LICENSE" : readdirSync(dir).find((entry) => match.test(entry));
87
- if (licenseFile) licenseText = readFileSync(join(dir, licenseFile), "utf8");
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
+ }
88
92
  } catch {}
89
93
  if (wrapLicenseText && licenseText) licenseText = wrap(licenseText, wrapLicenseText).trim();
90
94
  licenses.push({
@@ -111,4 +115,4 @@ const licensePlugin = ({ done, match = defaultMatch, wrapLicenseText, allow, fai
111
115
  });
112
116
 
113
117
  //#endregion
114
- export { licensePlugin, wrap };
118
+ export { findPkgRoot, licensePlugin, wrap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",
@@ -15,25 +15,29 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "engines": {
19
+ "node": "*",
20
+ "bun": "*"
21
+ },
18
22
  "peerDependencies": {
19
23
  "rolldown": "*"
20
24
  },
21
25
  "devDependencies": {
22
26
  "@types/node": "25.6.0",
23
- "@typescript/native-preview": "7.0.0-dev.20260414.1",
24
- "eslint": "10.2.0",
25
- "eslint-config-silverwind": "131.0.4",
27
+ "@typescript/native-preview": "7.0.0-dev.20260420.1",
28
+ "eslint": "10.2.1",
29
+ "eslint-config-silverwind": "131.0.5",
26
30
  "jest-extended": "7.0.0",
27
- "rolldown": "1.0.0-rc.15",
28
- "tsdown": "0.21.8",
29
- "tsdown-config-silverwind": "2.0.6",
30
- "typescript": "6.0.2",
31
- "typescript-config-silverwind": "17.0.0",
32
- "updates": "17.15.3",
31
+ "rolldown": "1.0.0-rc.16",
32
+ "tsdown": "0.21.9",
33
+ "tsdown-config-silverwind": "2.1.0",
34
+ "typescript": "6.0.3",
35
+ "typescript-config-silverwind": "18.0.0",
36
+ "updates": "17.15.5",
33
37
  "updates-config-silverwind": "2.1.0",
34
- "versions": "14.3.2",
35
- "vite": "8.0.8",
38
+ "versions": "15.0.0",
39
+ "vite": "8.0.9",
36
40
  "vitest": "4.1.4",
37
- "vitest-config-silverwind": "11.1.4"
41
+ "vitest-config-silverwind": "11.3.0"
38
42
  }
39
43
  }