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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,404 +1,689 @@
1
- var C = (t, o) => (o = Symbol[t]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + t), I = (t) => {
2
- throw TypeError(t);
1
+ var Q = (n, e) => (e = Symbol[n]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + n), V = (n) => {
2
+ throw TypeError(n);
3
3
  };
4
- var F = (t, o, e) => {
5
- if (o != null) {
6
- typeof o != "object" && typeof o != "function" && I("Object expected");
7
- var n, r;
8
- e && (n = o[C("asyncDispose")]), n === void 0 && (n = o[C("dispose")], e && (r = n)), typeof n != "function" && I("Object not disposable"), r && (n = function() {
4
+ var G = (n, e, o) => {
5
+ if (e != null) {
6
+ typeof e != "object" && typeof e != "function" && V("Object expected");
7
+ var t, i;
8
+ o && (t = e[Q("asyncDispose")]), t === void 0 && (t = e[Q("dispose")], o && (i = t)), typeof t != "function" && V("Object not disposable"), i && (t = function() {
9
9
  try {
10
- r.call(this);
10
+ i.call(this);
11
11
  } catch (a) {
12
12
  return Promise.reject(a);
13
13
  }
14
- }), t.push([e, n, o]);
15
- } else e && t.push([e]);
16
- return o;
17
- }, R = (t, o, e) => {
18
- var n = typeof SuppressedError == "function" ? SuppressedError : function(i, s, l, u) {
19
- return u = Error(l), u.name = "SuppressedError", u.error = i, u.suppressed = s, u;
20
- }, r = (i) => o = e ? new n(i, o, "An error was suppressed during disposal") : (e = !0, i), a = (i) => {
21
- for (; i = t.pop(); )
14
+ }), n.push([o, t, e]);
15
+ } else o && n.push([o]);
16
+ return e;
17
+ }, _ = (n, e, o) => {
18
+ var t = typeof SuppressedError == "function" ? SuppressedError : function(s, l, d, m) {
19
+ return m = Error(d), m.name = "SuppressedError", m.error = s, m.suppressed = l, m;
20
+ }, i = (s) => e = o ? new t(s, e, "An error was suppressed during disposal") : (o = !0, s), a = (s) => {
21
+ for (; s = n.pop(); )
22
22
  try {
23
- var s = i[1] && i[1].call(i[2]);
24
- if (i[0]) return Promise.resolve(s).then(a, (l) => (r(l), a()));
25
- } catch (l) {
26
- r(l);
23
+ var l = s[1] && s[1].call(s[2]);
24
+ if (s[0]) return Promise.resolve(l).then(a, (d) => (i(d), a()));
25
+ } catch (d) {
26
+ i(d);
27
27
  }
28
- if (e) throw o;
28
+ if (o) throw e;
29
29
  };
30
30
  return a();
31
31
  };
32
- import { c as _ } from "./useProjectInstance.js";
33
- import { d as P, r as Q } from "./cli.js";
34
- import { f as y } from "./log.js";
35
- import { path as d, toPosixPathSeparators as H } from "@arcgis/node-toolkit/path";
36
- import { log as q } from "@arcgis/toolkit/log";
37
- import f from "typescript";
38
- import { g as D, a as G, s as K, p as V, b as X, c as Y, d as Z } from "./hardcodedBehavior.js";
39
- import { f as B, c as T, g as ee, i as te } from "./format.js";
40
- import { styleText as w } from "node:util";
41
- import { loadCodeowners as oe } from "@arcgis/node-toolkit/codeowners";
42
- function ne(t, o) {
43
- if (o === "json") {
44
- const e = D();
45
- process.stdout.write(`${le(t, oe(), e)}
32
+ import { c as me } from "./useProjectInstance.js";
33
+ import { d as I, r as de, i as pe, a as ue, b as fe } from "./cli.js";
34
+ import { f as $ } from "./log.js";
35
+ import { path as P, toPosixPathSeparators as ge } from "@arcgis/node-toolkit/path";
36
+ import { log as xe } from "@arcgis/toolkit/log";
37
+ import { forEachWithConcurrency as ve } from "@arcgis/toolkit/promise";
38
+ import c from "typescript";
39
+ import { s as he, g as C, a as ye, p as we } from "./artifact.js";
40
+ import { loadCodeowners as te } from "@arcgis/node-toolkit/codeowners";
41
+ import { c as q, s as Ne, l as Se, a as ne, g as oe, b as be, d as Ae, e as ke } from "./componentAudit.js";
42
+ import { g as Pe, a as J, c as se, b as De, d as Ce, e as L, f as H, h as Ee } from "./classification.js";
43
+ import { styleText as M } from "node:util";
44
+ import { f as $e } from "./format.js";
45
+ import { readFile as Oe } from "node:fs/promises";
46
+ function Te(n, e, o) {
47
+ if (e === "json") {
48
+ if (o !== void 0) {
49
+ process.stdout.write(`${JSON.stringify(o, void 0, 2)}
50
+ `);
51
+ return;
52
+ }
53
+ const t = C();
54
+ process.stdout.write(`${Fe(n, te(), t)}
46
55
  `);
47
56
  return;
48
57
  }
49
- if (o === "md") {
50
- process.stdout.write(`${ue(t)}
58
+ if (e === "md") {
59
+ process.stdout.write(`${Ue(n)}
51
60
  `);
52
61
  return;
53
62
  }
54
- process.stdout.write(`${ae(t)}
63
+ process.stdout.write(`${Ie(n)}
55
64
  `);
56
65
  }
57
- function ae(t) {
58
- const o = L(t), e = o.reduce((r, a) => r + a.count, 0), n = [J("Deprecation summary", e)];
59
- for (const { categoryName: r, count: a, packages: i } of o) {
60
- n.push(`${P[r].label} (${a})`);
61
- for (const { packageName: s, count: l } of i)
62
- n.push(` ${M(s)} (${l})`);
66
+ function Ie(n) {
67
+ const e = ie(n), o = e.reduce((i, a) => i + a.count, 0), t = [X("Deprecation summary", o)];
68
+ for (const { categoryName: i, count: a, packages: s } of e) {
69
+ t.push(`${I[i].label} (${a})`);
70
+ for (const { displayName: l, count: d } of s)
71
+ t.push(` ${Y(l)} (${d})`);
63
72
  }
64
- n.push("", "", J("Deprecation details", e));
65
- for (const { categoryName: r, count: a, packages: i } of o) {
66
- const s = P[r];
67
- n.push("", `${s.label} (${a})`), "description" in s && n.push(` ${s.description}`);
68
- for (const { packageName: l, count: u, apis: p } of i) {
69
- n.push("", ` ${M(l)} (${u})`);
70
- for (const { api: c, reasons: m, items: g } of p) {
71
- n.push(` ${ie(c)} (${g.length})`);
72
- for (const v of m)
73
- n.push(re(v, 6));
74
- for (const { sourceFileName: v, usage: h } of se(g))
75
- n.push(` ${y(v)}:${h.line}:${h.column}`);
73
+ t.push("", "", X("Deprecation details", o));
74
+ for (const { categoryName: i, count: a, packages: s } of e) {
75
+ const l = I[i];
76
+ t.push("", `${l.label} (${a})`), "description" in l && t.push(` ${l.description}`);
77
+ for (const { displayName: d, count: m, apis: f } of s) {
78
+ t.push("", ` ${Y(d)} (${m})`);
79
+ for (const { name: r, reasons: p, items: x } of f) {
80
+ const h = x[0].usage, u = De({ name: r, memberOf: h.memberOf, kind: h.kind });
81
+ t.push(` ${Le(u)}${Ce(h.kind)} (${x.length})`);
82
+ for (const y of p)
83
+ t.push(Je(y, 6));
84
+ for (const { sourceFileName: y, usage: w } of Me(x))
85
+ t.push(` ${$(y)}:${w.line}:${w.column}`);
76
86
  }
77
87
  }
78
88
  }
79
- return n.join(`
89
+ return t.join(`
80
90
  `);
81
91
  }
82
- function L(t) {
83
- const o = [...t].flatMap(
84
- ([e, n]) => n.map((r) => ({ ...r, packageName: e }))
92
+ function ie(n) {
93
+ const e = [...n].flatMap(
94
+ ([o, t]) => t.map((i) => ({ ...i, packageName: o }))
85
95
  );
86
- return ee(o, ({ packageName: e, usage: n }) => ({
87
- packageName: e,
88
- api: n.name,
89
- reason: n.reason
96
+ return Pe(e, ({ packageName: o, usage: t }) => ({
97
+ package: o,
98
+ name: t.name,
99
+ kind: t.kind,
100
+ category: t.category,
101
+ memberOf: t.memberOf,
102
+ module: t.module ?? J(t.originFileNames, o),
103
+ deprecated: t.reason ?? !0
90
104
  }));
91
105
  }
92
- function J(t, o) {
93
- return w(["bold", "yellow"], `${t} (${o})`);
106
+ function X(n, e) {
107
+ return M(["bold", "yellow"], `${n} (${e})`);
94
108
  }
95
- function M(t) {
96
- return w("blue", t);
109
+ function Y(n) {
110
+ return M("blue", n);
97
111
  }
98
- function ie(t) {
99
- return w(["bold", "white"], t);
112
+ function Le(n) {
113
+ return M(["bold", "white"], n);
100
114
  }
101
- function re(t, o) {
102
- const e = " ".repeat(o);
103
- return t.split(/\r?\n/u).map((n) => `${e}${n}`).join(`
115
+ function Je(n, e) {
116
+ const o = " ".repeat(e);
117
+ return n.split(/\r?\n/u).map((t) => `${o}${t}`).join(`
104
118
  `);
105
119
  }
106
- function se(t) {
107
- return t.toSorted(
108
- (o, e) => o.sourceFileName.localeCompare(e.sourceFileName) || o.usage.line - e.usage.line || o.usage.column - e.usage.column
120
+ function Me(n) {
121
+ return n.toSorted(
122
+ (e, o) => e.sourceFileName.localeCompare(o.sourceFileName) || e.usage.line - o.usage.line || e.usage.column - o.usage.column
109
123
  );
110
124
  }
111
- function ce(t) {
112
- return [...t].sort(([o], [e]) => o.localeCompare(e));
125
+ function Re(n) {
126
+ return [...n].sort(([e], [o]) => e.localeCompare(o));
113
127
  }
114
- function le(t, o, e = D()) {
115
- return JSON.stringify(E(t, o, e), void 0, 2);
128
+ function Fe(n, e, o = C()) {
129
+ return JSON.stringify(R(n, e, o), void 0, 2);
116
130
  }
117
- function ue(t, o = D()) {
118
- return B(E(t, void 0, o));
131
+ function Ue(n, e = C()) {
132
+ return $e(R(n, void 0, e));
119
133
  }
120
- function E(t, o, e) {
121
- const n = L(t);
134
+ function R(n, e, o, t) {
135
+ const i = ie(n);
122
136
  return {
123
- kind: "usages",
124
- repository: e.repository,
125
- ref: e.ref,
137
+ auditKind: "usages",
138
+ repository: o.repository,
139
+ ref: o.ref,
140
+ branch: o.branch,
141
+ scannerVersion: he,
142
+ scanDate: Date.now(),
143
+ ...t === void 0 ? {} : { complete: t },
126
144
  summary: {
127
- total: n.reduce((a, { count: i }) => a + i, 0),
128
- categories: n.map(({ categoryName: a, count: i, packages: s }) => ({
129
- category: a,
130
- label: P[a].label,
131
- count: i,
132
- packages: s.map(({ packageName: l, count: u }) => ({
133
- package: l,
134
- count: u
145
+ total: i.reduce((s, { count: l }) => s + l, 0),
146
+ categories: i.map(({ categoryName: s, count: l, packages: d }) => ({
147
+ category: s,
148
+ label: I[s].label,
149
+ count: l,
150
+ packages: d.map(({ packageName: m, displayName: f, count: r }) => ({
151
+ package: m,
152
+ ...f === m ? {} : { displayName: f },
153
+ count: r
135
154
  }))
136
155
  }))
137
156
  },
138
- findings: ce(t).flatMap(
139
- ([a, i]) => i.map((s) => ({
140
- category: T({
141
- packageName: a,
142
- api: s.usage.name,
143
- reason: s.usage.reason
144
- }),
145
- package: a,
146
- api: s.usage.name,
147
- reason: s.usage.reason ?? null,
148
- file: G(s.sourceFileName, e.repositoryRoot),
149
- line: s.usage.line,
150
- column: s.usage.column,
151
- codeowners: o?.getOwners(s.sourceFileName) ?? []
152
- }))
153
- )
157
+ findings: ze(n, e, o)
154
158
  };
155
159
  }
156
- async function Me(t, o) {
157
- await Q(
160
+ function ze(n, e, o) {
161
+ return Re(n).flatMap(
162
+ ([t, i]) => i.map((a) => {
163
+ const s = a.usage.module ?? J(a.usage.originFileNames, t), l = {
164
+ package: t,
165
+ name: a.usage.name,
166
+ category: a.usage.category,
167
+ memberOf: a.usage.memberOf,
168
+ module: s,
169
+ deprecated: a.usage.reason ?? !0
170
+ };
171
+ return {
172
+ ...l,
173
+ category: se(l),
174
+ kind: a.usage.kind,
175
+ memberOf: a.usage.memberOf,
176
+ file: ye(a.sourceFileName, o.repositoryRoot),
177
+ line: a.usage.line,
178
+ column: a.usage.column,
179
+ codeowners: e?.getOwners(a.sourceFileName) ?? []
180
+ };
181
+ })
182
+ );
183
+ }
184
+ function Z(n, e, o) {
185
+ if (!e.hasDeprecatedApis)
186
+ return [];
187
+ const t = "getLineAndCharacterOfPosition" in n ? (r) => n.getLineAndCharacterOfPosition(r) : We(n.text), i = /* @__PURE__ */ new Map();
188
+ for (const [r, p] of e.cssVariables)
189
+ for (let x = n.text.indexOf(r); x !== -1; x = n.text.indexOf(r, x + r.length))
190
+ s(p, x, r.length);
191
+ const a = P.extname(n.fileName).slice(1).toLowerCase();
192
+ return a === "html" ? Ke(
193
+ n.text,
194
+ (r, p, x) => {
195
+ d(
196
+ r,
197
+ p,
198
+ x.map(({ name: h, start: u }) => ({ name: h, start: u }))
199
+ );
200
+ },
201
+ (r, p) => ee(r, p, m)
202
+ ) : a === "css" || a === "scss" || a === "sass" ? ee(n.text, 0, m, a !== "css") : "kind" in n && f(n, n), [...i.values()].sort((r, p) => r.usage.start - p.usage.start);
203
+ function s(r, p, x) {
204
+ const { line: h, character: u } = t(p);
205
+ i.set(JSON.stringify([r.package, r.kind, r.memberOf, r.name, p]), {
206
+ packageName: r.package,
207
+ sourceFileName: n.fileName,
208
+ usage: {
209
+ name: r.name,
210
+ kind: r.kind,
211
+ memberOf: r.kind === "css-property" ? void 0 : r.memberOf,
212
+ module: r.module,
213
+ reason: r.reason,
214
+ originFileNames: [r.sourceFileName],
215
+ start: p,
216
+ length: x,
217
+ line: h + 1,
218
+ column: u + 1
219
+ }
220
+ });
221
+ }
222
+ function l(r, p, x) {
223
+ const h = e.components.get(r);
224
+ return h?.length === 1 ? h[0].definitions.find(
225
+ (u) => u.kind === p && u.name === x && (p === "element" || u.memberOf === r)
226
+ ) : void 0;
227
+ }
228
+ function d(r, p, x) {
229
+ const h = l(r, "element", r);
230
+ h !== void 0 && s(h, p, r.length);
231
+ for (const u of x) {
232
+ const y = l(r, "attribute", u.name);
233
+ y !== void 0 && s(y, u.start, u.name.length);
234
+ }
235
+ }
236
+ function m(r, p, x, h) {
237
+ const u = l(r, p, x);
238
+ u !== void 0 && s(u, h, x.length);
239
+ }
240
+ function f(r, p) {
241
+ if (c.isJsxOpeningElement(r) || c.isJsxSelfClosingElement(r)) {
242
+ const x = r.tagName.getText(p), h = r.attributes.properties.filter(c.isJsxAttribute);
243
+ if (d(
244
+ x,
245
+ r.tagName.getStart(p),
246
+ h.map((u) => ({
247
+ name: u.name.getText(p),
248
+ start: u.name.getStart(p)
249
+ }))
250
+ ), /^[a-z][\w-]*$/u.test(x)) {
251
+ const u = h.find((v) => v.name.getText(p) === "slot"), y = u?.initializer, w = y !== void 0 && c.isJsxExpression(y) ? y.expression : y, E = u === void 0 ? -1 : r.attributes.properties.indexOf(u), g = r.attributes.properties.slice(E + 1).some(c.isJsxSpreadAttribute);
252
+ if (w !== void 0 && (c.isStringLiteral(w) || c.isNoSubstitutionTemplateLiteral(w)) && !g) {
253
+ const v = je(c.isJsxOpeningElement(r) ? r.parent : r, o), N = v === void 0 ? void 0 : l(v, "slot", w.text);
254
+ N !== void 0 && s(N, w.getStart(p) + 1, w.getWidth(p) - 2);
255
+ }
256
+ }
257
+ }
258
+ c.forEachChild(r, (x) => f(x, p));
259
+ }
260
+ }
261
+ function We(n) {
262
+ const e = [
263
+ 0,
264
+ ...Array.from(n.matchAll(/\r\n|[\r\n\u2028\u2029]/gu), (o) => o.index + o[0].length)
265
+ ];
266
+ return (o) => {
267
+ let t = 0, i = e.length;
268
+ for (; t + 1 < i; ) {
269
+ const a = Math.floor((t + i) / 2);
270
+ e[a] <= o ? t = a : i = a;
271
+ }
272
+ return { line: t, character: o - e[t] };
273
+ };
274
+ }
275
+ function je(n, e) {
276
+ let o = n;
277
+ for (let t = o.parent; t !== void 0; o = t, t = t.parent) {
278
+ if (c.isJsxElement(t))
279
+ return t.openingElement.tagName.getText();
280
+ if (!(c.isJsxFragment(t) || c.isJsxExpression(t) || c.isParenthesizedExpression(t)) && !(c.isConditionalExpression(t) && o !== t.condition) && !(c.isBinaryExpression(t) && (t.operatorToken.kind === c.SyntaxKind.AmpersandAmpersandToken && o === t.right || t.operatorToken.kind === c.SyntaxKind.BarBarToken || t.operatorToken.kind === c.SyntaxKind.QuestionQuestionToken))) {
281
+ if (c.isReturnStatement(t)) {
282
+ const i = c.findAncestor(t, c.isFunctionLike);
283
+ if (i === void 0 || !c.isArrowFunction(i) && !c.isFunctionExpression(i))
284
+ return;
285
+ o = i.body, t = i;
286
+ }
287
+ if ((c.isArrowFunction(t) || c.isFunctionExpression(t)) && o === t.body) {
288
+ const i = t.parent;
289
+ if (!c.isCallExpression(i) || i.arguments[0] !== t || !c.isPropertyAccessExpression(i.expression) || i.expression.name.text !== "map")
290
+ return;
291
+ const a = i.expression.expression, s = e?.getTypeAtLocation(a);
292
+ if (!c.isArrayLiteralExpression(a) && (s === void 0 || !e.isArrayType(s) && !e.isTupleType(s)))
293
+ return;
294
+ o = t, t = i;
295
+ continue;
296
+ }
297
+ return;
298
+ }
299
+ }
300
+ }
301
+ function ee(n, e, o, t = !1) {
302
+ const i = t ? /\/\*[\s\S]*?(?:\*\/|$)|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\/\/[^\r\n]*/gu : /\/\*[\s\S]*?(?:\*\/|$)|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/gu, a = n.replace(i, (m) => m.replace(/[^\r\n]/gu, " ")), s = [];
303
+ let l = 0, d = 0;
304
+ for (const m of a.matchAll(/[{};]/gu)) {
305
+ const f = m.index;
306
+ if (d > 0) {
307
+ d += m[0] === "{" ? 1 : m[0] === "}" ? -1 : 0, l = f + 1;
308
+ continue;
309
+ }
310
+ if (m[0] === "}")
311
+ s.pop();
312
+ else if (m[0] === "{") {
313
+ const r = a.slice(l, f), p = s.at(-1) ?? [];
314
+ if (/^\s*--[\w-]+\s*:/u.test(r))
315
+ d = 1;
316
+ else if (r.trimStart().startsWith("@"))
317
+ s.push(p);
318
+ else {
319
+ const h = r.split(",").map((u) => u.trim()).flatMap(
320
+ (u) => p.length === 0 ? [u] : p.map(
321
+ (y) => u.includes("&") ? u.replaceAll("&", y) : `${y} ${u}`
322
+ )
323
+ );
324
+ for (const u of r.matchAll(/::part\(\s*([\w\s-]+?)\s*\)|:state\(\s*([\w-]+)\s*\)/gu)) {
325
+ const y = r.lastIndexOf(",", u.index) + 1, w = r.slice(y, u.index), g = (p.length === 0 ? [w] : p.map(
326
+ (S) => w.includes("&") ? w.replaceAll("&", S) : `${S} ${w}`
327
+ )).map(Be);
328
+ if (g.includes(void 0) || new Set(g).size !== 1)
329
+ continue;
330
+ const v = u[1] === void 0 ? "css-state" : "css-part", N = u[1] ?? u[2], A = u.index + u[0].indexOf(N);
331
+ for (const S of N.matchAll(/[\w-]+/gu))
332
+ o(g[0], v, S[0], e + l + A + S.index);
333
+ }
334
+ s.push(h);
335
+ }
336
+ }
337
+ l = f + 1;
338
+ }
339
+ }
340
+ function Be(n) {
341
+ const e = n.replace(/:state\([\w-]+\)/gu, "").trimStart();
342
+ return /(?:^|[\s>+~])([a-z][\w-]*)(?:[.#:][\w-]+|\[[^\]]*\])*$/iu.exec(e)?.[1]?.toLowerCase();
343
+ }
344
+ function Ke(n, e, o) {
345
+ const t = /<!--[\s\S]*?(?:-->|$)|<![^>]*>|<\/?([a-z][\w:-]*)\b((?:"[^"]*"|'[^']*'|[^'">])*)>/giu;
346
+ for (let i = t.exec(n); i !== null; i = t.exec(n)) {
347
+ if (i[1] === void 0 || i[0].startsWith("</"))
348
+ continue;
349
+ const a = i[1].toLowerCase(), s = i.index + 1 + i[1].length, l = [...i[2].matchAll(/([^\s"'<>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/gu)].map(
350
+ (d) => ({ name: d[1].toLowerCase(), start: s + d.index })
351
+ );
352
+ if (e(a, i.index + 1, l), a === "plaintext")
353
+ break;
354
+ if (["script", "style", "textarea", "title", "xmp", "iframe", "noembed", "noframes"].includes(a)) {
355
+ const d = new RegExp(`</${a}\\s*>`, "giu");
356
+ d.lastIndex = t.lastIndex;
357
+ const m = d.exec(n);
358
+ a === "style" && o(n.slice(t.lastIndex, m?.index ?? n.length), t.lastIndex), t.lastIndex = m === null ? n.length : d.lastIndex;
359
+ }
360
+ }
361
+ }
362
+ async function xt(n, e) {
363
+ if (e.reportingUrl && (n || e.esriOnly || e.category || e.packageName))
364
+ throw new Error("Reporting requires a complete, unfiltered repository scan.");
365
+ const o = e.outputFormat === "json" || e.reportingUrl ? process.cwd() === C().repositoryRoot : !1;
366
+ if (e.reportingUrl && !o)
367
+ throw new Error("Reporting requires scanning from the Git repository root.");
368
+ let t = !n && !e.esriOnly && !e.category && !e.packageName;
369
+ (e.outputFormat === "json" || e.reportingUrl) && (t &&= o), await de(
158
370
  {
159
371
  meta: {
160
372
  needsTypeInformation: !0,
161
- needsFooter: !1
373
+ needsFooter: !1,
374
+ includeComponentFiles: !0
162
375
  },
163
- run(e) {
164
- fe(e, o);
376
+ async run(i) {
377
+ await Qe(i, e, t);
165
378
  }
166
379
  },
167
380
  "deprecations audit-usages",
168
- t
381
+ n
169
382
  );
170
383
  }
171
- function fe(t, o) {
172
- const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [
384
+ async function Qe(n, e, o) {
385
+ const t = /* @__PURE__ */ new Map(), i = be("warn", () => {
386
+ o = !1;
387
+ }), a = /* @__PURE__ */ new Map(), s = q([]), l = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), m = [
173
388
  ...new Map(
174
- t.flatMap(({ packageJson: c }) => {
175
- const m = c === void 0 ? void 0 : d.dirname(c.filePath), g = c?.contents.name;
176
- return m !== void 0 && g !== void 0 && k(m, process.cwd()) ? [[m, { root: m, name: g }]] : [];
389
+ n.flatMap(({ packageJson: g }) => {
390
+ const v = g === void 0 ? void 0 : P.dirname(g.filePath), N = g?.contents.name;
391
+ return v !== void 0 && N !== void 0 && O(v, process.cwd()) ? [[v, { root: v, name: N }]] : [];
177
392
  })
178
393
  ).values()
179
- ].toSorted((c, m) => m.root.length - c.root.length);
180
- for (const c of t) {
181
- var s = [];
394
+ ].toSorted((g, v) => v.root.length - g.root.length);
395
+ for (const g of n) {
396
+ var u = [];
182
397
  try {
183
- if (K(c.packageJson?.contents.name)) {
184
- const N = c.packageJson?.filePath;
185
- N !== void 0 && !n.has(N) && (n.add(N), q(
398
+ if (Ne(g.packageJson?.contents.name)) {
399
+ const b = g.packageJson?.filePath;
400
+ b !== void 0 && !d.has(b) && (d.add(b), xe(
186
401
  "warn",
187
- y(N),
188
- `Skipping excluded package \`${c.packageJson?.contents.name ?? c.cwd}\`.`
402
+ $(b),
403
+ `Skipping excluded package \`${g.packageJson?.contents.name ?? g.cwd}\`.`
189
404
  ));
190
405
  continue;
191
406
  }
192
- const m = F(s, _(c, !1));
193
- const g = m.tsMorph.getLanguageService().compilerObject;
194
- const v = g.getProgram()?.getTypeChecker();
195
- if (v === void 0)
407
+ if (g.filePaths.length === 0)
196
408
  continue;
197
- const h = c.packageJson === void 0 ? void 0 : d.dirname(c.packageJson.filePath);
198
- for (const N of m.getCodemodFiles()) {
199
- const A = N.compilerNode;
200
- for (const b of pe(
201
- A,
202
- g,
203
- v,
204
- h,
205
- o.esriOnly
206
- )) {
207
- const $ = Pe(b.originFileNames, r, h), x = e.get($) ?? [];
208
- x.push({ sourceFileName: A.fileName, usage: b }), e.set($, x);
409
+ const v = await x(g.packageJson);
410
+ const N = g.packageJson === void 0 ? void 0 : P.dirname(g.packageJson.filePath);
411
+ const A = G(u, g.filePaths.some(pe) ? me(g, !1) : void 0);
412
+ const S = A?.tsMorph.getLanguageService().compilerObject;
413
+ const D = S?.getProgram()?.getTypeChecker();
414
+ for (const b of A?.getCodemodFiles() ?? []) {
415
+ const k = b.compilerNode;
416
+ if (S !== void 0 && D !== void 0) {
417
+ const le = Ge(
418
+ k,
419
+ S,
420
+ D,
421
+ N,
422
+ e.esriOnly
423
+ );
424
+ for (const j of le) {
425
+ const B = et(j.originFileNames, m, N), K = t.get(B) ?? [];
426
+ K.push({ sourceFileName: k.fileName, usage: j }), t.set(B, K);
427
+ }
209
428
  }
429
+ h(Z(k, v, D)), l.add(k.fileName);
210
430
  }
211
- } catch (l) {
212
- var u = l, p = !0;
431
+ v.hasDeprecatedApis && await ve(g.filePaths, 8, async (b) => {
432
+ if (l.has(b))
433
+ return;
434
+ const k = await Oe(b, "utf8");
435
+ h(Z({ fileName: b, text: k }, v)), l.add(b);
436
+ });
437
+ } catch (y) {
438
+ var w = y, E = !0;
213
439
  } finally {
214
- R(s, u, p);
440
+ _(u, w, E);
215
441
  }
216
442
  }
217
- const a = me(e, o);
218
- ne(a, o.outputFormat);
219
- const i = [...a.values()].flat();
220
- V(
443
+ const f = Ve(t, e), r = e.reportingUrl || e.outputFormat === "json" ? R(f, te(), C(), o) : void 0;
444
+ Te(f, e.outputFormat, r);
445
+ const p = [...f.values()].flat();
446
+ we(
221
447
  "usages",
222
- i.length,
223
- new Set(i.map(({ sourceFileName: c }) => c)).size,
224
- a.size
225
- );
448
+ p.length,
449
+ new Set(p.map(({ sourceFileName: g }) => g)).size,
450
+ f.size
451
+ ), e.reportingUrl && r !== void 0 && await ue(r, e.reportingUrl);
452
+ async function x(g) {
453
+ if (g === void 0)
454
+ return s;
455
+ let v = a.get(g.filePath);
456
+ return v === void 0 && (v = q(
457
+ await Se(g, i, e.esriOnly)
458
+ ), a.set(g.filePath, v)), v;
459
+ }
460
+ function h(g) {
461
+ for (const { packageName: v, sourceFileName: N, usage: A } of g) {
462
+ if (ne(A.name, A.reason))
463
+ continue;
464
+ const S = t.get(v) ?? [], D = S.findIndex(
465
+ (k) => k.sourceFileName === N && k.usage.start === A.start && k.usage.length === A.length
466
+ ), b = { sourceFileName: N, usage: A };
467
+ D === -1 ? S.push(b) : S[D] = b, t.set(v, S);
468
+ }
469
+ }
226
470
  }
227
- function me(t, o) {
228
- const e = /* @__PURE__ */ new Map();
229
- for (const [n, r] of t) {
230
- if (o.packageName !== void 0 && n !== o.packageName)
471
+ function Ve(n, e) {
472
+ const o = /* @__PURE__ */ new Map();
473
+ for (const [t, i] of n) {
474
+ if (e.packageName !== void 0 && t !== e.packageName)
231
475
  continue;
232
- const a = r.filter(
233
- ({ usage: i }) => o.category === void 0 || T({ packageName: n, api: i.name, reason: i.reason }) === o.category
476
+ const a = i.filter(
477
+ ({ usage: s }) => e.category === void 0 || se({
478
+ package: t,
479
+ name: s.name,
480
+ category: s.category,
481
+ memberOf: s.memberOf,
482
+ module: s.module ?? J(s.originFileNames, t),
483
+ deprecated: s.reason ?? !0
484
+ }) === e.category
234
485
  );
235
- a.length > 0 && e.set(n, a);
486
+ a.length > 0 && o.set(t, a);
236
487
  }
237
- return e;
488
+ return o;
238
489
  }
239
- function pe(t, o, e, n, r = !1) {
490
+ function Ge(n, e, o, t, i = !1) {
240
491
  const a = /* @__PURE__ */ new Map();
241
- for (const i of o.getSuggestionDiagnostics(t.fileName)) {
242
- if (i.reportsDeprecated === void 0)
492
+ for (const s of e.getSuggestionDiagnostics(n.fileName)) {
493
+ if (s.reportsDeprecated === void 0)
243
494
  continue;
244
- const s = he(t, i.start, i.start + i.length);
495
+ const l = ae(n, s.start, s.start + s.length);
245
496
  if (
246
497
  // Don't report for imports, only for usages
247
- f.findAncestor(s, f.isImportDeclaration) !== void 0 || // Don't report closing JSX - only for opening
248
- f.findAncestor(s, f.isJsxClosingElement) !== void 0
498
+ c.findAncestor(l, c.isImportDeclaration) !== void 0 || // Don't report closing JSX - only for opening
499
+ c.findAncestor(l, c.isJsxClosingElement) !== void 0
249
500
  )
250
501
  continue;
251
- const l = de(
252
- s,
253
- e,
254
- o,
255
- t.fileName,
256
- i.start
257
- );
258
- U(l, r, n) && z(a, t, {
259
- start: i.start,
260
- length: i.length,
261
- name: Ne(s, e, o, t.fileName, i.start) ?? ye(s),
262
- originFileNames: l,
263
- reason: ke(o, t.fileName, i.start) ?? Se(s, e)
502
+ const d = He(l, o), m = d.reason === void 0 ? [] : F(d.symbol), f = m.length > 0 ? void 0 : e.getDefinitionAtPosition(n.fileName, s.start), r = m.length > 0 ? m : [...new Set(f?.map(({ fileName: p }) => p))];
503
+ z(r, i, t) && U(a, n, {
504
+ start: s.start,
505
+ length: s.length,
506
+ ...Xe(l, d, o, e, f?.[0]),
507
+ originFileNames: r,
508
+ reason: Ze(e, n.fileName, s.start) ?? d.reason
264
509
  });
265
510
  }
266
- return ge(t, e, a, n, r), [...a.values()].toSorted((i, s) => i.start - s.start);
267
- }
268
- function ge(t, o, e, n, r) {
269
- function a(i) {
270
- if (f.isJsxAttribute(i) && f.isIdentifier(i.name)) {
271
- const s = i.parent.parent;
272
- if (f.isJsxOpeningElement(s) || f.isJsxSelfClosingElement(s)) {
273
- const u = o.getContextualType(s.tagName)?.getProperty(i.name.text), p = S(u, o), c = j(u);
274
- p !== void 0 && U(c, r, n) && z(e, t, {
275
- start: i.name.getStart(t),
276
- length: i.name.getWidth(t),
277
- name: i.name.text,
278
- originFileNames: c,
279
- reason: p
280
- });
281
- }
511
+ return _e(n, o, a, t, i), [...a.values()].toSorted((s, l) => s.start - l.start);
512
+ }
513
+ function _e(n, e, o, t, i) {
514
+ function a(s) {
515
+ c.isNewExpression(s) && qe(s, e, o, t, i);
516
+ let l, d;
517
+ if (c.isJsxAttribute(s) && c.isIdentifier(s.name)) {
518
+ const m = s.parent.parent;
519
+ (c.isJsxOpeningElement(m) || c.isJsxSelfClosingElement(m)) && (d = e.getContextualType(m.tagName)?.getProperty(s.name.text), l = s.name);
520
+ } else if ((c.isPropertyAssignment(s) || c.isShorthandPropertyAssignment(s) || c.isMethodDeclaration(s)) && c.isObjectLiteralExpression(s.parent)) {
521
+ const m = c.isComputedPropertyName(s.name) ? T(s.name.expression, e) : s.name.text, f = e.getContextualType(s.parent);
522
+ d = m === void 0 || f === void 0 ? void 0 : e.getNonNullableType(f).getProperty(m), l = s.name;
523
+ } else if (c.isPropertyAccessExpression(s))
524
+ d = e.getSymbolAtLocation(s.name), l = s.name;
525
+ else if (c.isElementAccessExpression(s)) {
526
+ const m = T(s.argumentExpression, e);
527
+ d = m === void 0 ? void 0 : e.getTypeAtLocation(s.expression).getProperty(m), l = s.argumentExpression;
528
+ } else if (c.isBindingElement(s) && c.isObjectBindingPattern(s.parent) && s.dotDotDotToken === void 0) {
529
+ const m = s.propertyName ?? (c.isIdentifier(s.name) ? s.name : void 0), f = m === void 0 ? void 0 : c.isComputedPropertyName(m) ? T(m.expression, e) : m.text;
530
+ d = f === void 0 ? void 0 : e.getTypeAtLocation(s.parent).getProperty(f), l = m;
282
531
  }
283
- f.forEachChild(i, a);
532
+ if ((c.isPropertyAccessExpression(s) || c.isElementAccessExpression(s) || c.isBindingElement(s)) && !d?.declarations?.some(
533
+ (m) => c.isGetAccessorDeclaration(m) || c.isSetAccessorDeclaration(m)
534
+ ) && (d = void 0), d !== void 0 && l !== void 0) {
535
+ const m = ce(d, e), f = F(d);
536
+ m !== void 0 && z(f, i, t) && U(o, n, {
537
+ start: l.getStart(n),
538
+ length: l.getWidth(n),
539
+ name: d.getName(),
540
+ ...L(d.declarations?.[0]),
541
+ originFileNames: f,
542
+ reason: m
543
+ });
544
+ }
545
+ c.forEachChild(s, a);
284
546
  }
285
- a(t);
286
- }
287
- function de(t, o, e, n, r) {
288
- const a = ve(t, o);
289
- return a.length > 0 ? a : [...new Set(e.getDefinitionAtPosition(n, r)?.map(({ fileName: i }) => i))];
547
+ a(n);
290
548
  }
291
- function j(t) {
292
- return [...new Set(t?.declarations?.map((o) => o.getSourceFile().fileName))];
549
+ function qe(n, e, o, t, i) {
550
+ const a = e.getTypeAtLocation(n).getSymbol(), s = a?.declarations?.[0], l = s !== void 0 && (c.isClassDeclaration(s) || c.isInterfaceDeclaration(s)) ? s.name?.text : void 0, d = l === void 0 ? void 0 : Ee.get(l);
551
+ if (d === void 0 || l === void 0)
552
+ return;
553
+ const m = F(a);
554
+ if (!m.some(
555
+ (p) => (W(p) ?? oe(P.dirname(p), "")) === "@arcgis/core"
556
+ ) || !z(m, i, t))
557
+ return;
558
+ const f = c.isPropertyAccessExpression(n.expression) ? n.expression.name : n.expression, r = n.getSourceFile();
559
+ U(o, r, {
560
+ start: f.getStart(r),
561
+ length: f.getWidth(r),
562
+ name: l,
563
+ kind: "class",
564
+ category: "coreViews",
565
+ originFileNames: m,
566
+ reason: `Direct construction with new ${l}() is discouraged. Use \`<${d}>\` instead. In 6.0, directly constructed views will no longer include .ui; use component slots for UI.`
567
+ });
293
568
  }
294
- function ve(t, o) {
295
- let e = o.getSymbolAtLocation(t);
296
- for (; e !== void 0 && (e.flags & f.SymbolFlags.Alias) !== 0; ) {
297
- if (S(e, o) !== void 0)
298
- return j(e);
299
- e = e.declarations === void 0 ? void 0 : o.getImmediateAliasedSymbol(e);
300
- }
301
- return [];
302
- }
303
- function Ne(t, o, e, n, r) {
304
- let a = o.getSymbolAtLocation(t);
305
- for (; a !== void 0 && (a.flags & f.SymbolFlags.Alias) !== 0; ) {
306
- if (S(a, o) !== void 0)
307
- return a.getName();
308
- a = a.declarations === void 0 ? void 0 : o.getImmediateAliasedSymbol(a);
569
+ function T(n, e) {
570
+ const o = e.getTypeAtLocation(n);
571
+ return o.isStringLiteral() || o.isNumberLiteral() ? String(o.value) : void 0;
572
+ }
573
+ function He(n, e) {
574
+ let o = e.getSymbolAtLocation(n);
575
+ for (; o !== void 0 && (o.flags & c.SymbolFlags.Alias) !== 0; ) {
576
+ const t = ce(o, e);
577
+ if (t !== void 0)
578
+ return { symbol: o, reason: t };
579
+ o = o.declarations === void 0 ? void 0 : e.getImmediateAliasedSymbol(o);
309
580
  }
310
- return e.getDefinitionAtPosition(n, r)?.[0]?.name;
581
+ return { symbol: o, reason: void 0 };
582
+ }
583
+ function F(n) {
584
+ return [...new Set(n?.declarations?.map((e) => e.getSourceFile().fileName))];
585
+ }
586
+ function Xe(n, e, o, t, i) {
587
+ if (e.reason !== void 0)
588
+ return {
589
+ name: H(e.symbol.declarations?.[0], e.symbol.getName()),
590
+ ...L(e.symbol.declarations?.[0])
591
+ };
592
+ const a = i === void 0 ? void 0 : t.getProgram()?.getSourceFile(i.fileName), s = i === void 0 || a === void 0 ? void 0 : ae(
593
+ a,
594
+ i.textSpan.start,
595
+ i.textSpan.start + i.textSpan.length
596
+ ), l = (s === void 0 ? void 0 : o.getSymbolAtLocation(s)?.declarations?.[0]) ?? e.symbol?.declarations?.[0], d = i?.name;
597
+ return {
598
+ name: d === void 0 ? Ye(n) : H(l, d),
599
+ ...L(l)
600
+ };
311
601
  }
312
- function k(t, o) {
313
- const e = d.relative(o, t);
314
- return e !== "" && !e.startsWith("../") && !d.isAbsolute(e) && e !== "node_modules" && !e.startsWith("node_modules/");
602
+ function O(n, e) {
603
+ const o = P.relative(e, n);
604
+ return o !== "" && !o.startsWith("../") && !P.isAbsolute(o) && o !== "node_modules" && !o.startsWith("node_modules/");
315
605
  }
316
- function he(t, o, e) {
317
- let n = t;
606
+ function ae(n, e, o) {
607
+ let t = n;
318
608
  for (; ; ) {
319
- let r;
320
- if (f.forEachChild(n, (a) => {
321
- r === void 0 && a.getStart(t) <= o && a.getEnd() >= e && (r = a);
322
- }), r === void 0)
323
- return n;
324
- n = r;
609
+ let i;
610
+ if (c.forEachChild(t, (a) => {
611
+ i === void 0 && a.getStart(n) <= e && a.getEnd() >= o && (i = a);
612
+ }), i === void 0)
613
+ return t;
614
+ t = i;
325
615
  }
326
616
  }
327
- function ye(t) {
328
- return f.isIdentifier(t) || f.isPrivateIdentifier(t) || f.isStringLiteralLike(t) || f.isNumericLiteral(t) ? t.text : t.getText();
617
+ function Ye(n) {
618
+ return c.isIdentifier(n) || c.isPrivateIdentifier(n) || c.isStringLiteralLike(n) || c.isNumericLiteral(n) ? n.text : n.getText();
329
619
  }
330
- function O(t) {
331
- const o = t?.find(({ name: e }) => e === "deprecated");
332
- return o === void 0 ? void 0 : Z(o.text);
620
+ function re(n) {
621
+ const e = n?.find(({ name: o }) => o === "deprecated");
622
+ return e === void 0 ? void 0 : ke(e.text) ?? "";
333
623
  }
334
- function ke(t, o, e) {
624
+ function Ze(n, e, o) {
335
625
  try {
336
- return O(t.getQuickInfoAtPosition(o, e)?.tags);
626
+ return re(n.getQuickInfoAtPosition(e, o)?.tags);
337
627
  } catch {
338
628
  return;
339
629
  }
340
630
  }
341
- function S(t, o) {
631
+ function ce(n, e) {
342
632
  try {
343
- return O(t?.getJsDocTags(o));
633
+ const o = re(n?.getJsDocTags(e));
634
+ if (o !== void 0)
635
+ return o;
636
+ const t = n?.declarations?.filter((i) => c.isGetAccessorDeclaration(i) || c.isSetAccessorDeclaration(i)).map((i) => c.getJSDocDeprecatedTag(i)).find((i) => i !== void 0);
637
+ return t === void 0 ? void 0 : t.comment === void 0 ? "" : Ae(t.comment);
344
638
  } catch {
345
639
  return;
346
640
  }
347
641
  }
348
- function Se(t, o) {
349
- let e = o.getSymbolAtLocation(t);
350
- for (; e !== void 0 && (e.flags & f.SymbolFlags.Alias) !== 0; ) {
351
- const n = S(e, o);
352
- if (n !== void 0)
353
- return n;
354
- e = e.declarations === void 0 ? void 0 : o.getImmediateAliasedSymbol(e);
355
- }
356
- }
357
- function z(t, o, e) {
358
- if (Y(e.name, e.reason))
642
+ function U(n, e, o) {
643
+ if (ne(o.name, o.reason))
359
644
  return;
360
- const { line: n, character: r } = o.getLineAndCharacterOfPosition(e.start);
361
- t.set(`${e.start}:${e.length}`, {
362
- ...e,
363
- line: n + 1,
364
- column: r + 1
645
+ const { line: t, character: i } = e.getLineAndCharacterOfPosition(o.start);
646
+ n.set(`${o.start}:${o.length}`, {
647
+ ...o,
648
+ line: t + 1,
649
+ column: i + 1
365
650
  });
366
651
  }
367
- function U(t, o, e) {
368
- return t.some((n) => e !== void 0 && k(n, e)) ? !1 : !o || t.some((n) => {
369
- const r = W(n);
370
- return r === void 0 ? e === void 0 || !k(n, e) : te(r);
652
+ function z(n, e, o) {
653
+ return n.some((t) => o !== void 0 && O(t, o)) ? !1 : !e || n.some((t) => {
654
+ const i = W(t);
655
+ return i === void 0 ? o === void 0 || !O(t, o) : fe(i);
371
656
  });
372
657
  }
373
- function W(t) {
374
- const o = H(t), e = "/node_modules/", n = o.lastIndexOf(e);
375
- if (n === -1)
658
+ function W(n) {
659
+ const e = ge(n), o = "/node_modules/", t = e.lastIndexOf(o);
660
+ if (t === -1)
376
661
  return;
377
- const [r, a] = o.slice(n + e.length).split("/");
378
- return r.startsWith("@") ? `${r}/${a}` : r;
662
+ const [i, a] = e.slice(t + o.length).split("/");
663
+ return i.startsWith("@") ? `${i}/${a}` : i;
379
664
  }
380
- function Pe(t, o = [], e) {
381
- const n = t[0];
382
- if (n === void 0)
665
+ function et(n, e = [], o) {
666
+ const t = n[0];
667
+ if (t === void 0)
383
668
  return "unknown package";
384
- const r = W(n);
385
- if (r !== void 0)
386
- return r;
387
- const a = o.find(({ root: c }) => k(n, c));
669
+ const i = W(t);
670
+ if (i !== void 0)
671
+ return i;
672
+ const a = e.find(({ root: r }) => O(t, r));
388
673
  if (a !== void 0)
389
674
  return a.name;
390
- const i = d.dirname(y(n)), s = X(d.dirname(n), i);
391
- if (s !== i)
675
+ const s = P.dirname($(t)), l = oe(P.dirname(t), s);
676
+ if (l !== s)
677
+ return l;
678
+ if (o === void 0)
392
679
  return s;
393
- if (e === void 0)
394
- return i;
395
- const u = d.relative(e, n).split("/"), p = u.findIndex((c) => c !== "..");
396
- return p < 1 ? d.dirname(y(n)) : u.slice(0, p * 2).join("/");
680
+ const m = P.relative(o, t).split("/"), f = m.findIndex((r) => r !== "..");
681
+ return f < 1 ? P.dirname($(t)) : m.slice(0, f * 2).join("/");
397
682
  }
398
683
  export {
399
- Me as auditDeprecatedUsages,
400
- pe as collectDeprecatedApiUsages,
401
- Pe as getDeprecationOriginLabel,
684
+ xt as auditDeprecatedUsages,
685
+ Ge as collectDeprecatedApiUsages,
686
+ et as getDeprecationOriginLabel,
402
687
  W as getNodeModulesPackageName,
403
- U as shouldIncludeDeprecation
688
+ z as shouldIncludeDeprecation
404
689
  };