@arcgis/codemod 6.0.0-next.2 → 6.0.0-next.20

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