@arcgis/codemod 6.0.0-next.0 → 6.0.0-next.10

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.
@@ -1,143 +1,174 @@
1
- var k = (e, o) => (o = Symbol[e]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + e), N = (e) => {
2
- throw TypeError(e);
1
+ var D = (a, o) => (o = Symbol[a]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + a), y = (a) => {
2
+ throw TypeError(a);
3
3
  };
4
- var h = (e, o, a) => {
4
+ var P = (a, o, c) => {
5
5
  if (o != null) {
6
- typeof o != "object" && typeof o != "function" && N("Object expected");
7
- var s, t;
8
- a && (s = o[k("asyncDispose")]), s === void 0 && (s = o[k("dispose")], a && (t = s)), typeof s != "function" && N("Object not disposable"), t && (s = function() {
6
+ typeof o != "object" && typeof o != "function" && y("Object expected");
7
+ var t, i;
8
+ c && (t = o[D("asyncDispose")]), t === void 0 && (t = o[D("dispose")], c && (i = t)), typeof t != "function" && y("Object not disposable"), i && (t = function() {
9
9
  try {
10
- t.call(this);
11
- } catch (c) {
12
- return Promise.reject(c);
10
+ i.call(this);
11
+ } catch (e) {
12
+ return Promise.reject(e);
13
13
  }
14
- }), e.push([a, s, o]);
15
- } else a && e.push([a]);
14
+ }), a.push([c, t, o]);
15
+ } else c && a.push([c]);
16
16
  return o;
17
- }, w = (e, o, a) => {
18
- var s = typeof SuppressedError == "function" ? SuppressedError : function(n, p, r, m) {
19
- return m = Error(r), m.name = "SuppressedError", m.error = n, m.suppressed = p, m;
20
- }, t = (n) => o = a ? new s(n, o, "An error was suppressed during disposal") : (a = !0, n), c = (n) => {
21
- for (; n = e.pop(); )
17
+ }, v = (a, o, c) => {
18
+ var t = typeof SuppressedError == "function" ? SuppressedError : function(s, p, r, d) {
19
+ return d = Error(r), d.name = "SuppressedError", d.error = s, d.suppressed = p, d;
20
+ }, i = (s) => o = c ? new t(s, o, "An error was suppressed during disposal") : (c = !0, s), e = (s) => {
21
+ for (; s = a.pop(); )
22
22
  try {
23
- var p = n[1] && n[1].call(n[2]);
24
- if (n[0]) return Promise.resolve(p).then(c, (r) => (t(r), c()));
23
+ var p = s[1] && s[1].call(s[2]);
24
+ if (s[0]) return Promise.resolve(p).then(e, (r) => (i(r), e()));
25
25
  } catch (r) {
26
- t(r);
26
+ i(r);
27
27
  }
28
- if (a) throw o;
28
+ if (c) throw o;
29
29
  };
30
- return c();
30
+ return e();
31
31
  };
32
- import { log as D } from "@arcgis/toolkit/log";
33
- import { path as S } from "@arcgis/node-toolkit/path";
34
- import { styleText as $ } from "node:util";
35
- import P from "typescript";
36
- import { f as g } from "./log.js";
37
- import { r as v } from "./cli.js";
38
- import { c as x } from "./useProjectInstance.js";
39
- import { g as C, s as T, e as R, a as y, b, p as j, f as E } from "./hardcodedBehavior.js";
32
+ import { log as b } from "@arcgis/toolkit/log";
33
+ import { path as O } from "@arcgis/node-toolkit/path";
34
+ import { styleText as R } from "node:util";
35
+ import S from "typescript";
36
+ import { f as h } from "./log.js";
37
+ import { r as T, i as A } from "./cli.js";
38
+ import { c as M } from "./useProjectInstance.js";
39
+ import { g as $, a as w, p as j, s as E } from "./artifact.js";
40
40
  import { loadCodeowners as F } from "@arcgis/node-toolkit/codeowners";
41
- async function V(e, o) {
42
- await v(
41
+ import { b as L, d as z, a as I, c as K, e as Q, f as V } from "./classification.js";
42
+ import { s as W, f as J, g as q, b as B, d as G } from "./componentAudit.js";
43
+ async function pe(a, o) {
44
+ const c = !a && process.cwd() === $().repositoryRoot;
45
+ await T(
43
46
  {
44
- meta: { needsTypeInformation: !0, needsFooter: !1 },
45
- run(a) {
46
- O(a, o);
47
+ meta: { needsTypeInformation: !0, needsFooter: !1, includeComponentFiles: !0 },
48
+ async run(t) {
49
+ await H(t, o, c);
47
50
  }
48
51
  },
49
52
  "deprecations audit-definitions",
50
- e
53
+ a
51
54
  );
52
55
  }
53
- function O(e, o) {
54
- const a = [], s = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set(), c = C();
55
- for (const i of e) {
56
- var n = [];
56
+ async function H(a, o, c) {
57
+ const t = [], i = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), p = B("throw"), r = $();
58
+ for (const n of a) {
59
+ var d = [];
57
60
  try {
58
- if (T(i.packageJson?.contents.name)) {
59
- const d = i.packageJson?.filePath;
60
- d !== void 0 && !t.has(d) && (t.add(d), D(
61
+ const m = n.packageJson?.filePath;
62
+ if (W(n.packageJson?.contents.name) || m !== void 0 && J(w(m, r.repositoryRoot))) {
63
+ m !== void 0 && !e.has(m) && (e.add(m), b(
61
64
  "warn",
62
- g(d),
63
- `Skipping excluded package \`${i.packageJson?.contents.name ?? i.cwd}\`.`
65
+ h(m),
66
+ `Skipping excluded package \`${n.packageJson?.contents.name ?? n.cwd}\`.`
64
67
  ));
65
68
  continue;
66
69
  }
67
- const f = h(n, x(i, !1));
68
- const J = i.packageJson?.contents.name ?? g(i.cwd);
69
- for (const d of f.getCodemodFiles()) {
70
- if (R(
71
- y(d.compilerNode.fileName, c.repositoryRoot)
70
+ if (m !== void 0 && !s.has(m)) {
71
+ s.add(m);
72
+ const f = await p(m);
73
+ f !== void 0 && t.push(...f.definitions);
74
+ }
75
+ if (!n.filePaths.some(A))
76
+ continue;
77
+ const g = P(d, M(n, !1));
78
+ const u = n.packageJson?.contents.name ?? h(n.cwd);
79
+ for (const f of g.getCodemodFiles()) {
80
+ if (J(
81
+ w(f.compilerNode.fileName, r.repositoryRoot)
72
82
  ))
73
83
  continue;
74
- const l = S.dirname(d.compilerNode.fileName), u = s.get(l) ?? b(l, J);
75
- s.set(l, u), a.push(...z(d.compilerNode, u));
84
+ const k = O.dirname(f.compilerNode.fileName), N = i.get(k) ?? q(k, u);
85
+ i.set(k, N), t.push(...U(f.compilerNode, N));
76
86
  }
77
- } catch (p) {
78
- var r = p, m = !0;
87
+ } catch (l) {
88
+ var x = l, C = !0;
79
89
  } finally {
80
- w(n, r, m);
90
+ v(d, x, C);
81
91
  }
82
92
  }
83
93
  if (o)
84
- I(a, c);
94
+ Y(t, r, c);
85
95
  else
86
- for (const i of a) {
87
- const f = $(
96
+ for (const n of t) {
97
+ const m = R(
88
98
  "blue",
89
- `${g(i.sourceFileName)}:${i.line}:${i.column}`
90
- );
91
- D("warn", f, `\`${i.name}\` is deprecated.${i.reason ? ` ${i.reason}` : ""}`);
99
+ `${h(n.sourceFileName)}:${n.line}:${n.column}`
100
+ ), g = L({
101
+ name: n.name,
102
+ memberOf: n.memberOf,
103
+ kind: n.kind
104
+ }), u = z(n.kind, "parentheses");
105
+ b("warn", m, `\`${g}\`${u} is deprecated.${n.reason ? ` ${n.reason}` : ""}`);
92
106
  }
93
107
  j(
94
108
  "definitions",
95
- a.length,
96
- new Set(a.map(({ sourceFileName: i }) => i)).size,
97
- new Set(a.map(({ package: i }) => i)).size
109
+ t.length,
110
+ new Set(t.map(({ sourceFileName: n }) => n)).size,
111
+ new Set(t.map(({ package: n }) => n)).size
98
112
  );
99
113
  }
100
- function z(e, o) {
101
- const a = /* @__PURE__ */ new Map();
102
- function s(t) {
103
- const c = P.getJSDocDeprecatedTag(t), n = A(t);
104
- if (c !== void 0 && n !== void 0) {
105
- const p = n.getStart(e), { line: r, character: m } = e.getLineAndCharacterOfPosition(p);
106
- a.set(`${p}:${n.getWidth(e)}`, {
114
+ function U(a, o) {
115
+ const c = /* @__PURE__ */ new Map(), t = I([a.fileName], o);
116
+ function i(e) {
117
+ const s = S.getJSDocDeprecatedTag(e), p = X(e);
118
+ if (s !== void 0 && p !== void 0) {
119
+ const r = p.getStart(a), { line: d, character: l } = a.getLineAndCharacterOfPosition(r);
120
+ c.set(`${r}:${p.getWidth(a)}`, {
107
121
  package: o,
108
- name: n.getText(e),
109
- reason: c.comment === void 0 ? void 0 : E(c.comment),
110
- sourceFileName: e.fileName,
111
- line: r + 1,
112
- column: m + 1
122
+ module: t,
123
+ name: V(e, p.getText(a)),
124
+ ...Q(e),
125
+ reason: s.comment === void 0 ? void 0 : G(s.comment),
126
+ sourceFileName: a.fileName,
127
+ line: d + 1,
128
+ column: l + 1
113
129
  });
114
130
  }
115
- P.forEachChild(t, s);
131
+ S.forEachChild(e, i);
116
132
  }
117
- return s(e), [...a.values()].sort((t, c) => t.line - c.line || t.column - c.column);
133
+ return i(a), [...c.values()].sort((e, s) => e.line - s.line || e.column - s.column);
118
134
  }
119
- function A(e) {
120
- return e.name;
135
+ function X(a) {
136
+ return a.name;
121
137
  }
122
- function I(e, o) {
123
- const a = F(), s = {
124
- kind: "definitions",
138
+ function Y(a, o, c) {
139
+ const t = F(), i = {
140
+ auditKind: "definitions",
125
141
  repository: o.repository,
126
142
  ref: o.ref,
127
- findings: e.map((t) => ({
128
- package: t.package,
129
- api: t.name,
130
- reason: t.reason ?? null,
131
- file: y(t.sourceFileName, o.repositoryRoot),
132
- line: t.line,
133
- column: t.column,
134
- codeowners: a?.getOwners(t.sourceFileName) ?? []
143
+ branch: o.branch,
144
+ scannerVersion: E,
145
+ scanDate: Date.now(),
146
+ complete: c,
147
+ findings: a.map((e) => ({
148
+ package: e.package,
149
+ name: e.name,
150
+ module: e.module,
151
+ kind: e.kind,
152
+ memberOf: e.memberOf,
153
+ provenance: e.provenance,
154
+ category: K({
155
+ package: e.package,
156
+ name: e.name,
157
+ memberOf: e.memberOf,
158
+ module: e.module,
159
+ deprecated: e.reason ?? !0
160
+ }),
161
+ deprecated: e.reason ?? !0,
162
+ file: w(e.sourceFileName, o.repositoryRoot),
163
+ line: e.line,
164
+ column: e.column,
165
+ codeowners: t?.getOwners(e.sourceFileName) ?? []
135
166
  }))
136
167
  };
137
- process.stdout.write(`${JSON.stringify(s, void 0, 2)}
168
+ process.stdout.write(`${JSON.stringify(i, void 0, 2)}
138
169
  `);
139
170
  }
140
171
  export {
141
- V as auditDeprecatedDefinitions,
142
- z as collectDeprecatedApiDefinitions
172
+ pe as auditDeprecatedDefinitions,
173
+ U as collectDeprecatedApiDefinitions
143
174
  };
@@ -0,0 +1,307 @@
1
+ import { readFile as P } from "node:fs/promises";
2
+ import { b } from "./artifact.js";
3
+ import { c as f, g as R, i as C, b as y, d as h } from "./classification.js";
4
+ import { e as I, b as k, d as A } from "./cli.js";
5
+ async function E(e = {}) {
6
+ const a = new URL(e.url ?? I);
7
+ for (const n of e.repositories ?? [])
8
+ a.searchParams.append("repository", n);
9
+ for (const n of ["branch", "since", "until"])
10
+ e[n] !== void 0 && a.searchParams.set(n, e[n]);
11
+ const o = await fetch(a, {
12
+ signal: AbortSignal.timeout(12e4),
13
+ redirect: "error"
14
+ });
15
+ if (!o.ok)
16
+ throw new Error(`Remote aggregation failed: HTTP ${o.status}.`);
17
+ const r = await o.json();
18
+ if (!Array.isArray(r))
19
+ throw new Error("Invalid collector response.");
20
+ return r.map((n) => {
21
+ const s = b(JSON.stringify(n));
22
+ if (s.auditKind !== "usages")
23
+ throw new Error("Expected an audit-usages report from the collector.");
24
+ return { ...s, auditKind: "usages" };
25
+ });
26
+ }
27
+ async function G(e, a, o = {}, r = [], n) {
28
+ const { section: s = "all", ...u } = o, [t, c, i] = await Promise.all([
29
+ Promise.all(e.map(async (l) => await v(l, "usages"))),
30
+ Promise.all(r.map(async (l) => await v(l, "definitions"))),
31
+ n === void 0 ? [] : E(n)
32
+ ]), m = j(
33
+ [...t, ...i],
34
+ u,
35
+ r.length === 0 ? void 0 : c
36
+ ), p = a === "json" ? JSON.stringify(m, void 0, 2) : J(m, a, s);
37
+ process.stdout.write(`${p}
38
+ `);
39
+ }
40
+ function j(e, a = {}, o) {
41
+ const r = /* @__PURE__ */ new Set(), n = [], s = e.flatMap((t) => {
42
+ if (r.has(t.repository))
43
+ throw new Error(`Duplicate audit-usages report for ${t.repository}.`);
44
+ r.add(t.repository);
45
+ const c = t.findings.map((i) => ({ ...i, category: i.category ?? f(i) })).filter((i) => M(i, a));
46
+ return n.push(z(t, c)), c.map((i) => ({ finding: i, source: { repository: t.repository, ref: t.ref } }));
47
+ }), u = D(s);
48
+ return {
49
+ auditKind: "aggregated-usages",
50
+ aggregatedDate: Date.now(),
51
+ count: s.length,
52
+ repositories: n.sort(
53
+ (t, c) => c.count - t.count || t.repository.localeCompare(c.repository)
54
+ ),
55
+ packages: u,
56
+ ...o === void 0 ? {} : { unused: B(e, o, a) }
57
+ };
58
+ }
59
+ function z(e, a) {
60
+ return {
61
+ repository: e.repository,
62
+ ref: e.ref,
63
+ branch: e.branch,
64
+ scanDate: e.scanDate,
65
+ scannerVersion: e.scannerVersion,
66
+ count: a.length,
67
+ apiCount: new Set(a.map(g)).size,
68
+ categories: R(a, (o) => o).map(({ categoryName: o, count: r, packages: n }) => ({
69
+ category: o,
70
+ label: A[o].label,
71
+ count: r,
72
+ packages: n.map(({ packageName: s, displayName: u, count: t }) => ({
73
+ package: s,
74
+ ...u === s ? {} : { displayName: u },
75
+ count: t
76
+ }))
77
+ }))
78
+ };
79
+ }
80
+ function M(e, a) {
81
+ return (!a.esriOnly || k(e.package)) && (a.category === void 0 || e.category === a.category) && (a.packageName === void 0 || e.package === a.packageName);
82
+ }
83
+ function D(e) {
84
+ const a = [...Map.groupBy(e, ({ finding: o }) => o.package)].map(([o, r]) => {
85
+ const n = [...Map.groupBy(r, ({ finding: s }) => s.module)].map(([s, u]) => {
86
+ const t = [
87
+ ...Map.groupBy(
88
+ u,
89
+ ({ finding: c }) => JSON.stringify([c.category ?? f(c), g(c)])
90
+ )
91
+ ].map(([, c]) => {
92
+ const i = c[0].finding, m = c.flatMap(({ source: p }) => p === void 0 ? [] : [p]);
93
+ return {
94
+ name: i.name,
95
+ category: i.category ?? f(i),
96
+ kind: i.kind,
97
+ memberOf: i.memberOf,
98
+ count: m.length,
99
+ repositories: [...Map.groupBy(m, ({ repository: p }) => p)].map(([p, l]) => ({
100
+ repository: U(p),
101
+ ref: l[0].ref,
102
+ count: l.length
103
+ })).sort((p, l) => l.count - p.count)
104
+ };
105
+ });
106
+ return t.sort((c, i) => i.count - c.count), {
107
+ module: s,
108
+ count: t.reduce((c, i) => c + i.count, 0),
109
+ apis: t
110
+ };
111
+ });
112
+ return n.sort((s, u) => u.count - s.count), { package: o, count: n.reduce((s, u) => s + u.count, 0), modules: n };
113
+ });
114
+ return a.sort(
115
+ (o, r) => Number(k(r.package)) - Number(k(o.package)) || r.count - o.count
116
+ ), a;
117
+ }
118
+ function B(e, a, o) {
119
+ const r = e.flatMap((u) => u.findings), n = new Set(r.map(g)), s = /* @__PURE__ */ new Map();
120
+ for (const u of a)
121
+ for (const t of u.findings) {
122
+ if (t.module === void 0)
123
+ throw new Error(
124
+ `Definition ${t.package}/${t.name} has no module. Regenerate its audit-definitions report.`
125
+ );
126
+ const c = { ...t, category: t.category ?? f(t) }, i = g(c);
127
+ !n.has(i) && M(c, o) && s.set(i, { finding: c });
128
+ }
129
+ return { count: s.size, packages: D([...s.values()]) };
130
+ }
131
+ function g(e) {
132
+ return e.kind === "css-property" ? JSON.stringify([e.package, e.kind, e.name]) : e.kind === "css-part" || e.kind === "css-state" || e.kind === "slot" || e.kind === "attribute" || e.kind === "element" ? JSON.stringify([e.package, e.kind, e.memberOf, e.name]) : JSON.stringify([e.package, e.module, e.name, e.memberOf]);
133
+ }
134
+ function U(e, a = !1) {
135
+ const o = new URL(`https://${e}`);
136
+ return !a && o.hostname === "github.com" ? e : o.pathname.slice(1);
137
+ }
138
+ function J(e, a, o) {
139
+ if (o === "apis")
140
+ return w(e, a);
141
+ const r = a === "md", n = [
142
+ r ? "# Deprecation overview" : "Deprecation overview",
143
+ "",
144
+ `${e.count} usages - ${e.repositories.length} repositories - Aggregated: ${new Date(e.aggregatedDate).toISOString().slice(0, 10)}`,
145
+ ""
146
+ ];
147
+ for (const s of e.repositories) {
148
+ const u = s.scanDate === void 0 ? "Unknown" : new Date(s.scanDate).toISOString();
149
+ n.push(
150
+ "",
151
+ ...r ? [
152
+ "<details>",
153
+ `<summary>${s.count} usages - ${N(U(s.repository, !0))} - ${u.slice(0, 10)}</summary>`,
154
+ ""
155
+ ] : [`${s.repository}: ${s.count} usages; selected scan ${u}`]
156
+ ), n.push(
157
+ `> ${[
158
+ `Distinct APIs: ${s.apiCount}`,
159
+ `Branch: ${r ? d(s.branch ?? "Unknown") : s.branch ?? "Unknown"}`,
160
+ `Commit: ${r ? `[\`${s.ref.slice(0, 6)}\`](https://${s.repository}/tree/${encodeURIComponent(s.ref)})` : s.ref}`,
161
+ `Scanner version: ${r ? d(s.scannerVersion ?? "Unknown") : s.scannerVersion ?? "Unknown"}`
162
+ ].join(" | ")}`,
163
+ ""
164
+ ), s.categories.length === 0 ? n.push("No matching deprecated usages.") : r && n.push("| Category | Package | Usages |", "| --- | --- | ---: |");
165
+ for (const t of s.categories) {
166
+ if (r && t.packages.length === 1) {
167
+ n.push(
168
+ `| **${d(t.label)}** | ${d(t.packages[0].displayName ?? t.packages[0].package)} | **${t.count}** |`
169
+ );
170
+ continue;
171
+ }
172
+ n.push(
173
+ r ? `| **${d(t.label)}** | | **${t.count}** |` : ` ${t.label} (${t.count})`
174
+ );
175
+ for (const c of t.packages)
176
+ n.push(
177
+ r ? `| | ${d(c.displayName ?? c.package)} | ${c.count} |` : ` ${c.displayName ?? c.package} (${c.count})`
178
+ );
179
+ }
180
+ r && n.push("", "</details>");
181
+ }
182
+ return o === "all" && n.push("", w(e, a)), n.join(`
183
+ `);
184
+ }
185
+ function d(e) {
186
+ return N(e).replaceAll("|", "&#124;").replaceAll(/\r?\n/gu, " ");
187
+ }
188
+ function N(e) {
189
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
190
+ }
191
+ function w(e, a, o = "Deprecated API usages") {
192
+ const r = a === "md", n = [r ? `# ${o} (${e.count})` : `${o} (${e.count})`];
193
+ for (const [s, { label: u }] of Object.entries(A)) {
194
+ const t = e.packages.flatMap((i) => {
195
+ const m = i.modules.flatMap((p) => {
196
+ const l = p.apis.filter(($) => $.category === s);
197
+ return l.length === 0 ? [] : [{ ...p, apis: l, count: l.reduce(($, O) => $ + O.count, 0) }];
198
+ });
199
+ return m.length === 0 ? [] : [{ ...i, modules: m, count: m.reduce((p, l) => p + l.count, 0) }];
200
+ });
201
+ if (t.length === 0)
202
+ continue;
203
+ const c = t.reduce((i, m) => i + m.count, 0);
204
+ n.push(
205
+ "",
206
+ r ? `## ${u} (${c})` : `${u} (${c})`,
207
+ ...F(t, r)
208
+ );
209
+ }
210
+ return e.unused !== void 0 && n.push("", w(e.unused, a, "Deprecated APIs with zero detected usages")), n.join(`
211
+ `);
212
+ }
213
+ function F(e, a) {
214
+ const o = [], r = e.flatMap(
215
+ (n) => [
216
+ ...Map.groupBy(n.modules, (s) => C(n.package, s.module))
217
+ ].map(([s, u]) => ({
218
+ ...n,
219
+ displayName: s,
220
+ modules: u,
221
+ count: u.reduce((t, c) => t + c.count, 0)
222
+ }))
223
+ );
224
+ for (const n of r) {
225
+ if (o.push(
226
+ "",
227
+ a ? `### ${n.displayName === n.package ? `\`${n.package}\`` : n.displayName} (${n.count})` : `${n.displayName} (${n.count})`
228
+ ), a) {
229
+ o.push(...V(n.modules));
230
+ continue;
231
+ }
232
+ for (const s of n.modules) {
233
+ const u = s.module ?? "Unknown module";
234
+ o.push(` ${u} (${s.count})`);
235
+ for (const t of s.apis) {
236
+ o.push(` ${y(t)}${h(t.kind)} (${t.count})`);
237
+ for (const { repository: c, count: i } of t.repositories)
238
+ o.push(` ${c} (${i})`);
239
+ }
240
+ }
241
+ }
242
+ return o;
243
+ }
244
+ function x(e, a, o = "") {
245
+ const r = `${y(e)}${h(e.kind)}`;
246
+ return a ? [
247
+ `${o}- \`${y(e)}\`${h(e.kind)} (${e.count})`,
248
+ ...e.repositories.map(({ repository: n, count: s }) => `${o} - \`${n}\` (${s})`)
249
+ ] : [
250
+ `${o}${r} (${e.count})`,
251
+ ...e.repositories.map(({ repository: n, count: s }) => `${o} ${n} (${s})`)
252
+ ];
253
+ }
254
+ function V(e) {
255
+ const a = /* @__PURE__ */ new Map();
256
+ for (const o of e) {
257
+ let r = a;
258
+ const n = o.module === void 0 ? [void 0] : o.module.split("/");
259
+ for (const [s, u] of n.entries()) {
260
+ let t = r.get(u);
261
+ t === void 0 && (t = { name: u, count: 0, children: /* @__PURE__ */ new Map(), apis: [] }, r.set(u, t)), t.count += o.count, s === n.length - 1 && (t.apis = o.apis), r = t.children;
262
+ }
263
+ }
264
+ return [...a.values()].sort((o, r) => r.count - o.count).flatMap((o) => S(o, 0));
265
+ }
266
+ function S(e, a) {
267
+ let o = e, r = o.name ?? "Unknown module";
268
+ for (; o.children.size === 1 && o.apis.length === 0; )
269
+ o = [...o.children.values()][0], r += `/${o.name}`;
270
+ o.children.size > 0 && (r += "/");
271
+ const n = " ".repeat(a), s = [
272
+ ...[...o.children.values()].map((t) => ({
273
+ count: t.count,
274
+ lines: S(t, a + 1)
275
+ })),
276
+ ...o.apis.map((t) => ({
277
+ count: t.count,
278
+ lines: x(t, !0, n)
279
+ }))
280
+ ];
281
+ s.sort((t, c) => c.count - t.count);
282
+ const u = s.flatMap(({ lines: t }) => t);
283
+ return a === 0 ? [
284
+ "",
285
+ "<details>",
286
+ `<summary><code>${r.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")}</code> (${e.count})</summary>`,
287
+ "",
288
+ ...u,
289
+ "",
290
+ "</details>"
291
+ ] : [`${" ".repeat(a - 1)}- \`${r}\` (${e.count})`, ...u];
292
+ }
293
+ async function v(e, a) {
294
+ let o;
295
+ try {
296
+ o = b(await P(e, "utf8"));
297
+ } catch (r) {
298
+ throw new Error(`Failed to read audit-${a} report: ${e}`, { cause: r });
299
+ }
300
+ if (o.auditKind !== a)
301
+ throw new Error(`Invalid audit-${a} report: ${e}`);
302
+ return o;
303
+ }
304
+ export {
305
+ j as aggregateUsages,
306
+ G as aggregateUsagesFromFiles
307
+ };