rolldown-license-plugin 2.2.2 → 2.2.4
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 +11 -5
- package/dist/index.js +6 -5
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -12,9 +12,15 @@ import {licensePlugin} from "rolldown-license-plugin";
|
|
|
12
12
|
export default {
|
|
13
13
|
plugins: [
|
|
14
14
|
licensePlugin({
|
|
15
|
-
done(deps) {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
done(deps, context) {
|
|
16
|
+
const content = deps.map(({name, version, license, licenseText}) => (
|
|
17
|
+
`${name} ${version} (${license})\n${licenseText}`
|
|
18
|
+
)).join("\n\n");
|
|
19
|
+
context.emitFile({
|
|
20
|
+
type: "asset",
|
|
21
|
+
fileName: "licenses.txt",
|
|
22
|
+
source: content,
|
|
23
|
+
});
|
|
18
24
|
},
|
|
19
25
|
}),
|
|
20
26
|
],
|
|
@@ -71,8 +77,8 @@ Throw a build error when a dependency does not specify any license.
|
|
|
71
77
|
```typescript
|
|
72
78
|
type LicenseInfo = {
|
|
73
79
|
name: string; // package name
|
|
74
|
-
version: string; // package version
|
|
75
|
-
license: string; // SPDX license identifier from package.json
|
|
80
|
+
version: string; // package version, or ""
|
|
81
|
+
license: string; // SPDX license identifier from package.json, or ""
|
|
76
82
|
licenseText: string; // contents of LICENSE/COPYING file, or ""
|
|
77
83
|
};
|
|
78
84
|
```
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { join, sep } from "node:path";
|
|
3
3
|
|
|
4
4
|
//#region index.ts
|
|
5
5
|
const defaultMatch = /^((UN)?LICEN(S|C)E|COPYING).*$/i;
|
|
@@ -41,18 +41,19 @@ function parseLicense(pkgJson) {
|
|
|
41
41
|
const nmSep = "/node_modules/";
|
|
42
42
|
/** Resolve the package root directory from a file path inside node_modules */
|
|
43
43
|
function findPkgRoot(fsPath) {
|
|
44
|
-
const
|
|
44
|
+
const p = sep !== "/" ? fsPath.replaceAll(sep, "/") : fsPath;
|
|
45
|
+
const nmIdx = p.lastIndexOf(nmSep);
|
|
45
46
|
if (nmIdx === -1) return null;
|
|
46
47
|
const base = nmIdx + 14;
|
|
47
|
-
const rest =
|
|
48
|
+
const rest = p.slice(base);
|
|
48
49
|
if (rest.startsWith("@")) {
|
|
49
50
|
const firstSlash = rest.indexOf("/");
|
|
50
51
|
if (firstSlash === -1) return null;
|
|
51
52
|
const secondSlash = rest.indexOf("/", firstSlash + 1);
|
|
52
|
-
return
|
|
53
|
+
return p.slice(0, base) + rest.slice(0, secondSlash === -1 ? rest.length : secondSlash);
|
|
53
54
|
}
|
|
54
55
|
const firstSlash = rest.indexOf("/");
|
|
55
|
-
return
|
|
56
|
+
return p.slice(0, base) + rest.slice(0, firstSlash === -1 ? rest.length : firstSlash);
|
|
56
57
|
}
|
|
57
58
|
/** Rolldown plugin that extracts license information from bundled dependencies */
|
|
58
59
|
const licensePlugin = ({ done, match = defaultMatch, wrapText, allow, failOnViolation = false, failOnUnlicensed = false }) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-license-plugin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Rolldown plugin to extract dependency licenses",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rolldown-license-plugin",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"updates": "17.14.0",
|
|
33
33
|
"updates-config-silverwind": "2.0.1",
|
|
34
34
|
"versions": "14.2.7",
|
|
35
|
+
"vite": "8.0.8",
|
|
35
36
|
"vitest": "4.1.4",
|
|
36
37
|
"vitest-config-silverwind": "11.1.4"
|
|
37
38
|
}
|