rolldown-license-plugin 0.0.0 → 1.0.1
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/dist/index.js +23 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,22 +21,36 @@ const licensePlugin = ({ onDone, match = defaultMatch }) => ({
|
|
|
21
21
|
const fsPath = moduleId.split("?")[0];
|
|
22
22
|
if (!fsPath.includes("node_modules")) continue;
|
|
23
23
|
let dir = dirname(fsPath);
|
|
24
|
+
const cached = pkgJsonCache.get(dir);
|
|
25
|
+
if (cached !== void 0) {
|
|
26
|
+
if (cached?.name) {
|
|
27
|
+
const key = `${cached.name}@${cached.version ?? ""}`;
|
|
28
|
+
if (!pkgDirs.has(key)) pkgDirs.set(key, {
|
|
29
|
+
dir,
|
|
30
|
+
pkgJson: cached
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
24
35
|
let pkgJson = null;
|
|
36
|
+
const walked = [];
|
|
25
37
|
while (dir !== dirname(dir) && dir.includes("node_modules")) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
const cachedInner = pkgJsonCache.get(dir);
|
|
39
|
+
if (cachedInner !== void 0) {
|
|
40
|
+
pkgJson = cachedInner;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
walked.push(dir);
|
|
44
|
+
try {
|
|
45
|
+
pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
46
|
+
} catch {
|
|
47
|
+
pkgJson = null;
|
|
35
48
|
}
|
|
36
49
|
if (pkgJson?.name) break;
|
|
37
50
|
pkgJson = null;
|
|
38
51
|
dir = dirname(dir);
|
|
39
52
|
}
|
|
53
|
+
for (const walkedDir of walked) pkgJsonCache.set(walkedDir, pkgJson);
|
|
40
54
|
if (!pkgJson?.name) continue;
|
|
41
55
|
const key = `${pkgJson.name}@${pkgJson.version ?? ""}`;
|
|
42
56
|
if (!pkgDirs.has(key)) pkgDirs.set(key, {
|
package/package.json
CHANGED