@arcgis/codemod 6.0.0-next.3 → 6.0.0-next.31

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