@arcgis/codemod 6.0.0-next.6 → 6.0.0-next.7

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,160 +1,174 @@
1
- var N = (a, o) => (o = Symbol[a]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + a), h = (a) => {
1
+ var D = (a, o) => (o = Symbol[a]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + a), y = (a) => {
2
2
  throw TypeError(a);
3
3
  };
4
- var D = (a, o, t) => {
4
+ var P = (a, o, c) => {
5
5
  if (o != null) {
6
- typeof o != "object" && typeof o != "function" && h("Object expected");
7
- var c, e;
8
- t && (c = o[N("asyncDispose")]), c === void 0 && (c = o[N("dispose")], t && (e = c)), typeof c != "function" && h("Object not disposable"), e && (c = 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
- e.call(this);
11
- } catch (i) {
12
- return Promise.reject(i);
10
+ i.call(this);
11
+ } catch (e) {
12
+ return Promise.reject(e);
13
13
  }
14
- }), a.push([t, c, o]);
15
- } else t && a.push([t]);
14
+ }), a.push([c, t, o]);
15
+ } else c && a.push([c]);
16
16
  return o;
17
- }, w = (a, o, t) => {
18
- var c = typeof SuppressedError == "function" ? SuppressedError : function(s, r, m, d) {
19
- return d = Error(m), d.name = "SuppressedError", d.error = s, d.suppressed = r, d;
20
- }, e = (s) => o = t ? new c(s, o, "An error was suppressed during disposal") : (t = !0, s), i = (s) => {
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
21
  for (; s = a.pop(); )
22
22
  try {
23
- var r = s[1] && s[1].call(s[2]);
24
- if (s[0]) return Promise.resolve(r).then(i, (m) => (e(m), i()));
25
- } catch (m) {
26
- e(m);
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
+ } catch (r) {
26
+ i(r);
27
27
  }
28
- if (t) throw o;
28
+ if (c) throw o;
29
29
  };
30
- return i();
30
+ return e();
31
31
  };
32
- import { log as y } from "@arcgis/toolkit/log";
33
- import { path as $ } from "@arcgis/node-toolkit/path";
34
- import { styleText as b } from "node:util";
35
- import P from "typescript";
36
- import { f as u } from "./log.js";
37
- import { r as x } from "./cli.js";
38
- import { c as J } from "./useProjectInstance.js";
39
- import { g as O, e as S, a as v, b as C, p as T, d as A, f as K, h as R, j } from "./classification.js";
40
- import { loadCodeowners as M } from "@arcgis/node-toolkit/codeowners";
41
- import { s as E, d as z, g as F, b as I } from "./hardcodedBehavior.js";
42
- async function oe(a, o) {
43
- await x(
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
+ import { loadCodeowners as F } from "@arcgis/node-toolkit/codeowners";
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(
44
46
  {
45
- meta: { needsTypeInformation: !0, needsFooter: !1 },
46
- run(t) {
47
- L(t, o);
47
+ meta: { needsTypeInformation: !0, needsFooter: !1, includeComponentFiles: !0 },
48
+ async run(t) {
49
+ await H(t, o, c);
48
50
  }
49
51
  },
50
52
  "deprecations audit-definitions",
51
53
  a
52
54
  );
53
55
  }
54
- function L(a, o) {
55
- const t = [], c = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set(), i = O();
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 = $();
56
58
  for (const n of a) {
57
- var s = [];
59
+ var d = [];
58
60
  try {
59
- if (E(n.packageJson?.contents.name)) {
60
- const p = n.packageJson?.filePath;
61
- p !== void 0 && !e.has(p) && (e.add(p), y(
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(
62
64
  "warn",
63
- u(p),
65
+ h(m),
64
66
  `Skipping excluded package \`${n.packageJson?.contents.name ?? n.cwd}\`.`
65
67
  ));
66
68
  continue;
67
69
  }
68
- const l = D(s, J(n, !1));
69
- const f = n.packageJson?.contents.name ?? u(n.cwd);
70
- for (const p of l.getCodemodFiles()) {
71
- if (z(
72
- S(p.compilerNode.fileName, i.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)
73
82
  ))
74
83
  continue;
75
- const g = $.dirname(p.compilerNode.fileName), k = c.get(g) ?? F(g, f);
76
- c.set(g, k), t.push(...Q(p.compilerNode, k));
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));
77
86
  }
78
- } catch (r) {
79
- var m = r, d = !0;
87
+ } catch (l) {
88
+ var x = l, C = !0;
80
89
  } finally {
81
- w(s, m, d);
90
+ v(d, x, C);
82
91
  }
83
92
  }
84
93
  if (o)
85
- q(t, i);
94
+ Y(t, r, c);
86
95
  else
87
96
  for (const n of t) {
88
- const l = b(
97
+ const m = R(
89
98
  "blue",
90
- `${u(n.sourceFileName)}:${n.line}:${n.column}`
91
- ), f = v({
92
- api: n.name,
99
+ `${h(n.sourceFileName)}:${n.line}:${n.column}`
100
+ ), g = L({
101
+ name: n.name,
93
102
  memberOf: n.memberOf,
94
- apiKind: n.apiKind
95
- }), p = C(n.apiKind, "parentheses");
96
- y("warn", l, `\`${f}\`${p} is deprecated.${n.reason ? ` ${n.reason}` : ""}`);
103
+ kind: n.kind
104
+ }), u = z(n.kind, "parentheses");
105
+ b("warn", m, `\`${g}\`${u} is deprecated.${n.reason ? ` ${n.reason}` : ""}`);
97
106
  }
98
- T(
107
+ j(
99
108
  "definitions",
100
109
  t.length,
101
110
  new Set(t.map(({ sourceFileName: n }) => n)).size,
102
111
  new Set(t.map(({ package: n }) => n)).size
103
112
  );
104
113
  }
105
- function Q(a, o) {
106
- const t = /* @__PURE__ */ new Map(), c = A([a.fileName], o);
107
- function e(i) {
108
- const s = P.getJSDocDeprecatedTag(i), r = W(i);
109
- if (s !== void 0 && r !== void 0) {
110
- const m = r.getStart(a), { line: d, character: n } = a.getLineAndCharacterOfPosition(m);
111
- t.set(`${m}:${r.getWidth(a)}`, {
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)}`, {
112
121
  package: o,
113
- module: c,
114
- name: j(i, r.getText(a)),
115
- ...R(i),
116
- reason: s.comment === void 0 ? void 0 : I(s.comment),
122
+ module: t,
123
+ name: V(e, p.getText(a)),
124
+ ...Q(e),
125
+ reason: s.comment === void 0 ? void 0 : G(s.comment),
117
126
  sourceFileName: a.fileName,
118
127
  line: d + 1,
119
- column: n + 1
128
+ column: l + 1
120
129
  });
121
130
  }
122
- P.forEachChild(i, e);
131
+ S.forEachChild(e, i);
123
132
  }
124
- return e(a), [...t.values()].sort((i, s) => i.line - s.line || i.column - s.column);
133
+ return i(a), [...c.values()].sort((e, s) => e.line - s.line || e.column - s.column);
125
134
  }
126
- function W(a) {
135
+ function X(a) {
127
136
  return a.name;
128
137
  }
129
- function q(a, o) {
130
- const t = M(), c = {
131
- kind: "definitions",
138
+ function Y(a, o, c) {
139
+ const t = F(), i = {
140
+ auditKind: "definitions",
132
141
  repository: o.repository,
133
142
  ref: o.ref,
143
+ branch: o.branch,
144
+ scannerVersion: E,
145
+ scanDate: Date.now(),
146
+ complete: c,
134
147
  findings: a.map((e) => ({
135
148
  package: e.package,
136
- api: e.name,
149
+ name: e.name,
137
150
  module: e.module,
138
- apiKind: e.apiKind,
151
+ kind: e.kind,
139
152
  memberOf: e.memberOf,
153
+ provenance: e.provenance,
140
154
  category: K({
141
155
  package: e.package,
142
- api: e.name,
156
+ name: e.name,
143
157
  memberOf: e.memberOf,
144
158
  module: e.module,
145
- reason: e.reason ?? null
159
+ deprecated: e.reason ?? !0
146
160
  }),
147
- reason: e.reason ?? null,
148
- file: S(e.sourceFileName, o.repositoryRoot),
161
+ deprecated: e.reason ?? !0,
162
+ file: w(e.sourceFileName, o.repositoryRoot),
149
163
  line: e.line,
150
164
  column: e.column,
151
165
  codeowners: t?.getOwners(e.sourceFileName) ?? []
152
166
  }))
153
167
  };
154
- process.stdout.write(`${JSON.stringify(c, void 0, 2)}
168
+ process.stdout.write(`${JSON.stringify(i, void 0, 2)}
155
169
  `);
156
170
  }
157
171
  export {
158
- oe as auditDeprecatedDefinitions,
159
- Q as collectDeprecatedApiDefinitions
172
+ pe as auditDeprecatedDefinitions,
173
+ U as collectDeprecatedApiDefinitions
160
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
+ };