@arcgis/codemod 5.2.0-next.99 → 6.0.0-next.0

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.
@@ -0,0 +1,404 @@
1
+ var C = (t, o) => (o = Symbol[t]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + t), I = (t) => {
2
+ throw TypeError(t);
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() {
9
+ try {
10
+ r.call(this);
11
+ } catch (a) {
12
+ return Promise.reject(a);
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(); )
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);
27
+ }
28
+ if (e) throw o;
29
+ };
30
+ return a();
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)}
46
+ `);
47
+ return;
48
+ }
49
+ if (o === "md") {
50
+ process.stdout.write(`${ue(t)}
51
+ `);
52
+ return;
53
+ }
54
+ process.stdout.write(`${ae(t)}
55
+ `);
56
+ }
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})`);
63
+ }
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}`);
76
+ }
77
+ }
78
+ }
79
+ return n.join(`
80
+ `);
81
+ }
82
+ function L(t) {
83
+ const o = [...t].flatMap(
84
+ ([e, n]) => n.map((r) => ({ ...r, packageName: e }))
85
+ );
86
+ return ee(o, ({ packageName: e, usage: n }) => ({
87
+ packageName: e,
88
+ api: n.name,
89
+ reason: n.reason
90
+ }));
91
+ }
92
+ function J(t, o) {
93
+ return w(["bold", "yellow"], `${t} (${o})`);
94
+ }
95
+ function M(t) {
96
+ return w("blue", t);
97
+ }
98
+ function ie(t) {
99
+ return w(["bold", "white"], t);
100
+ }
101
+ function re(t, o) {
102
+ const e = " ".repeat(o);
103
+ return t.split(/\r?\n/u).map((n) => `${e}${n}`).join(`
104
+ `);
105
+ }
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
109
+ );
110
+ }
111
+ function ce(t) {
112
+ return [...t].sort(([o], [e]) => o.localeCompare(e));
113
+ }
114
+ function le(t, o, e = D()) {
115
+ return JSON.stringify(E(t, o, e), void 0, 2);
116
+ }
117
+ function ue(t, o = D()) {
118
+ return B(E(t, void 0, o));
119
+ }
120
+ function E(t, o, e) {
121
+ const n = L(t);
122
+ return {
123
+ kind: "usages",
124
+ repository: e.repository,
125
+ ref: e.ref,
126
+ 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
135
+ }))
136
+ }))
137
+ },
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
+ )
154
+ };
155
+ }
156
+ async function Me(t, o) {
157
+ await Q(
158
+ {
159
+ meta: {
160
+ needsTypeInformation: !0,
161
+ needsFooter: !1
162
+ },
163
+ run(e) {
164
+ fe(e, o);
165
+ }
166
+ },
167
+ "deprecations audit-usages",
168
+ t
169
+ );
170
+ }
171
+ function fe(t, o) {
172
+ const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [
173
+ ...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 }]] : [];
177
+ })
178
+ ).values()
179
+ ].toSorted((c, m) => m.root.length - c.root.length);
180
+ for (const c of t) {
181
+ var s = [];
182
+ 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(
186
+ "warn",
187
+ y(N),
188
+ `Skipping excluded package \`${c.packageJson?.contents.name ?? c.cwd}\`.`
189
+ ));
190
+ continue;
191
+ }
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)
196
+ 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);
209
+ }
210
+ }
211
+ } catch (l) {
212
+ var u = l, p = !0;
213
+ } finally {
214
+ R(s, u, p);
215
+ }
216
+ }
217
+ const a = me(e, o);
218
+ ne(a, o.outputFormat);
219
+ const i = [...a.values()].flat();
220
+ V(
221
+ "usages",
222
+ i.length,
223
+ new Set(i.map(({ sourceFileName: c }) => c)).size,
224
+ a.size
225
+ );
226
+ }
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)
231
+ continue;
232
+ const a = r.filter(
233
+ ({ usage: i }) => o.category === void 0 || T({ packageName: n, api: i.name, reason: i.reason }) === o.category
234
+ );
235
+ a.length > 0 && e.set(n, a);
236
+ }
237
+ return e;
238
+ }
239
+ function pe(t, o, e, n, r = !1) {
240
+ const a = /* @__PURE__ */ new Map();
241
+ for (const i of o.getSuggestionDiagnostics(t.fileName)) {
242
+ if (i.reportsDeprecated === void 0)
243
+ continue;
244
+ const s = he(t, i.start, i.start + i.length);
245
+ if (
246
+ // 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
249
+ )
250
+ 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)
264
+ });
265
+ }
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
+ }
282
+ }
283
+ f.forEachChild(i, a);
284
+ }
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))];
290
+ }
291
+ function j(t) {
292
+ return [...new Set(t?.declarations?.map((o) => o.getSourceFile().fileName))];
293
+ }
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);
309
+ }
310
+ return e.getDefinitionAtPosition(n, r)?.[0]?.name;
311
+ }
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/");
315
+ }
316
+ function he(t, o, e) {
317
+ let n = t;
318
+ 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;
325
+ }
326
+ }
327
+ function ye(t) {
328
+ return f.isIdentifier(t) || f.isPrivateIdentifier(t) || f.isStringLiteralLike(t) || f.isNumericLiteral(t) ? t.text : t.getText();
329
+ }
330
+ function O(t) {
331
+ const o = t?.find(({ name: e }) => e === "deprecated");
332
+ return o === void 0 ? void 0 : Z(o.text);
333
+ }
334
+ function ke(t, o, e) {
335
+ try {
336
+ return O(t.getQuickInfoAtPosition(o, e)?.tags);
337
+ } catch {
338
+ return;
339
+ }
340
+ }
341
+ function S(t, o) {
342
+ try {
343
+ return O(t?.getJsDocTags(o));
344
+ } catch {
345
+ return;
346
+ }
347
+ }
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))
359
+ 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
365
+ });
366
+ }
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);
371
+ });
372
+ }
373
+ function W(t) {
374
+ const o = H(t), e = "/node_modules/", n = o.lastIndexOf(e);
375
+ if (n === -1)
376
+ return;
377
+ const [r, a] = o.slice(n + e.length).split("/");
378
+ return r.startsWith("@") ? `${r}/${a}` : r;
379
+ }
380
+ function Pe(t, o = [], e) {
381
+ const n = t[0];
382
+ if (n === void 0)
383
+ 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));
388
+ if (a !== void 0)
389
+ return a.name;
390
+ const i = d.dirname(y(n)), s = X(d.dirname(n), i);
391
+ if (s !== i)
392
+ 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("/");
397
+ }
398
+ export {
399
+ Me as auditDeprecatedUsages,
400
+ pe as collectDeprecatedApiUsages,
401
+ Pe as getDeprecationOriginLabel,
402
+ W as getNodeModulesPackageName,
403
+ U as shouldIncludeDeprecation
404
+ };
@@ -0,0 +1,143 @@
1
+ var k = (e, o) => (o = Symbol[e]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + e), N = (e) => {
2
+ throw TypeError(e);
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() {
9
+ try {
10
+ t.call(this);
11
+ } catch (c) {
12
+ return Promise.reject(c);
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(); )
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);
27
+ }
28
+ if (a) throw o;
29
+ };
30
+ return c();
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(
43
+ {
44
+ meta: { needsTypeInformation: !0, needsFooter: !1 },
45
+ run(a) {
46
+ O(a, o);
47
+ }
48
+ },
49
+ "deprecations audit-definitions",
50
+ e
51
+ );
52
+ }
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 = [];
57
+ 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
+ "warn",
62
+ g(d),
63
+ `Skipping excluded package \`${i.packageJson?.contents.name ?? i.cwd}\`.`
64
+ ));
65
+ continue;
66
+ }
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)
72
+ ))
73
+ 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));
76
+ }
77
+ } catch (p) {
78
+ var r = p, m = !0;
79
+ } finally {
80
+ w(n, r, m);
81
+ }
82
+ }
83
+ if (o)
84
+ I(a, c);
85
+ else
86
+ for (const i of a) {
87
+ const f = $(
88
+ "blue",
89
+ `${g(i.sourceFileName)}:${i.line}:${i.column}`
90
+ );
91
+ D("warn", f, `\`${i.name}\` is deprecated.${i.reason ? ` ${i.reason}` : ""}`);
92
+ }
93
+ j(
94
+ "definitions",
95
+ a.length,
96
+ new Set(a.map(({ sourceFileName: i }) => i)).size,
97
+ new Set(a.map(({ package: i }) => i)).size
98
+ );
99
+ }
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
+ });
114
+ }
115
+ P.forEachChild(t, s);
116
+ }
117
+ return s(e), [...a.values()].sort((t, c) => t.line - c.line || t.column - c.column);
118
+ }
119
+ function A(e) {
120
+ return e.name;
121
+ }
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) ?? []
135
+ }))
136
+ };
137
+ process.stdout.write(`${JSON.stringify(s, void 0, 2)}
138
+ `);
139
+ }
140
+ export {
141
+ V as auditDeprecatedDefinitions,
142
+ z as collectDeprecatedApiDefinitions
143
+ };
@@ -0,0 +1,11 @@
1
+ import { path as e } from "@arcgis/node-toolkit/path";
2
+ function n(t) {
3
+ return o(t.getFilePath());
4
+ }
5
+ function o(t) {
6
+ return e.relative(process.cwd(), t);
7
+ }
8
+ export {
9
+ n as a,
10
+ o as f
11
+ };
@@ -0,0 +1,39 @@
1
+ import { log as r } from "@arcgis/toolkit/log";
2
+ import { writeFile as s } from "node:fs/promises";
3
+ import { f } from "./log.js";
4
+ async function h(n, a) {
5
+ const o = /* @__PURE__ */ new Set();
6
+ for (const i of n) {
7
+ const e = i.packageJson;
8
+ if (e === void 0 || o.has(e.filePath))
9
+ continue;
10
+ o.add(e.filePath);
11
+ const c = e.contents;
12
+ try {
13
+ const t = await a(c, e.filePath);
14
+ c !== t && await s(e.filePath, `${JSON.stringify(t, null, 2)}
15
+ `, "utf8");
16
+ } catch (t) {
17
+ process.exitCode = 1, r(
18
+ "error",
19
+ f(e.filePath),
20
+ `Error occurred while migrating: ${String(t)}`,
21
+ typeof t == "object" && t !== null && "stack" in t ? { detail: { stack: t.stack } } : void 0
22
+ );
23
+ }
24
+ }
25
+ }
26
+ function u(n, a) {
27
+ for (const o of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
28
+ const i = n[o];
29
+ if (i) {
30
+ const e = a(i, o);
31
+ e !== i && (n = { ...n, [o]: e });
32
+ }
33
+ }
34
+ return n;
35
+ }
36
+ export {
37
+ u as a,
38
+ h as f
39
+ };