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.
Files changed (2) hide show
  1. package/dist/index.js +23 -9
  2. 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 cached = pkgJsonCache.get(dir);
27
- if (cached !== void 0) pkgJson = cached;
28
- else {
29
- try {
30
- pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
31
- } catch {
32
- pkgJson = null;
33
- }
34
- pkgJsonCache.set(dir, pkgJson);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-license-plugin",
3
- "version": "0.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Rolldown plugin to extract dependency licenses",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rolldown-license-plugin",