@arcgis/codemod 6.0.0-next.11 → 6.0.0-next.13

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