@arcgis/codemod 6.0.0-next.1 → 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,21 +1,22 @@
1
- import { log as g } from "@arcgis/toolkit/log";
2
- import { Command as Q, InvalidArgumentError as K } from "@commander-js/extra-typings";
3
- import { stat as q, realpath as B } from "node:fs/promises";
4
- import { path as i, getCwd as R, toPosixPathSeparators as T } from "@arcgis/node-toolkit/path";
5
- import { asyncFindPath as N, existsAsync as A } from "@arcgis/node-toolkit/file";
1
+ import { log as m } from "@arcgis/toolkit/log";
2
+ import { Command as ne, InvalidArgumentError as F } from "@commander-js/extra-typings";
3
+ import { stat as V, realpath as Q } from "node:fs/promises";
4
+ import { path as n, getCwd as N, toPosixPathSeparators as _ } from "@arcgis/node-toolkit/path";
5
+ import { asyncFindPath as W, existsAsync as G } from "@arcgis/node-toolkit/file";
6
6
  import "ts-morph";
7
- import c from "typescript";
8
- import { asyncRetrievePackageJson as $ } from "@arcgis/node-toolkit/packageJson";
9
- import { glob as z } from "tinyglobby";
10
- import { gitIgnoreFileToGlobs as H } from "@arcgis/node-toolkit/glob";
11
- import { identity as _ } from "@arcgis/toolkit/function";
12
- import { styleText as D } from "node:util";
13
- const X = (t, e, s) => {
14
- const o = t[e];
15
- return o ? typeof o == "function" ? o() : Promise.resolve(o) : new Promise((n, l) => {
16
- (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(l.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + e + (e.split("/").length !== s ? ". Note that variables only represent file names one level deep." : ""))));
7
+ import d from "typescript";
8
+ import { asyncRetrievePackageJson as ie } from "@arcgis/node-toolkit/packageJson";
9
+ import { glob as X } from "tinyglobby";
10
+ import { gitIgnoreFileToGlobs as Y } from "@arcgis/node-toolkit/glob";
11
+ import { identity as q } from "@arcgis/toolkit/function";
12
+ import { styleText as J } from "node:util";
13
+ import { randomUUID as ae } from "node:crypto";
14
+ const ce = (t, e, o) => {
15
+ const s = t[e];
16
+ return s ? typeof s == "function" ? s() : Promise.resolve(s) : new Promise((r, l) => {
17
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(l.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + e + (e.split("/").length !== o ? ". Note that variables only represent file names one level deep." : ""))));
17
18
  });
18
- }, xe = {
19
+ }, We = {
19
20
  allowImportingTsExtensions: !0,
20
21
  allowJs: !0,
21
22
  allowArbitraryExtensions: !0,
@@ -25,81 +26,89 @@ const X = (t, e, s) => {
25
26
  forceConsistentCasingInFileNames: !1,
26
27
  isolatedModules: !1,
27
28
  isolatedDeclarations: !1,
28
- jsx: c.JsxEmit.Preserve,
29
+ jsx: d.JsxEmit.Preserve,
29
30
  lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
30
- module: c.ModuleKind.ESNext,
31
- moduleResolution: c.ModuleResolutionKind.Bundler,
32
- moduleDetection: c.ModuleDetectionKind.Auto,
31
+ module: d.ModuleKind.ESNext,
32
+ moduleResolution: d.ModuleResolutionKind.Bundler,
33
+ moduleDetection: d.ModuleDetectionKind.Auto,
33
34
  strict: !1,
34
- target: c.ScriptTarget.ESNext,
35
+ target: d.ScriptTarget.ESNext,
35
36
  resolveJsonModule: !0,
36
37
  esModuleInterop: !0
37
- }, P = {
38
+ }, v = {
38
39
  codemod: void 0,
39
40
  codemodName: void 0,
40
41
  projectsData: void 0,
41
42
  project: void 0
42
- };
43
- async function Y() {
44
- const { ignorePatterns: t, globRoot: e } = await Z(), s = await ee(e);
45
- return t.push(...s), { ignorePatterns: t, globRoot: e };
43
+ }, Z = [
44
+ // Hardcoded ignores in TypeScript
45
+ "**/node_modules/**",
46
+ "**/bower_components/**",
47
+ "**/jspm_packages/**",
48
+ // Default build output folder in bundlers
49
+ "**/dist/**"
50
+ ];
51
+ async function de() {
52
+ const { ignorePatterns: t, globRoot: e, hasIgnoreFiles: o } = await le(), s = await ue(e);
53
+ return t.push(...s.ignorePatterns), !o && !s.hasIgnoreFiles && t.push(...Z), { ignorePatterns: t, globRoot: e };
46
54
  }
47
- async function Z() {
48
- const t = [], e = await N(".git"), s = e === void 0 ? void 0 : i.dirname(e);
49
- let o, n = R(), l = i.dirname(n);
55
+ async function le() {
56
+ const t = [];
57
+ let e = !1;
58
+ const o = await W(".git"), s = o === void 0 ? void 0 : n.dirname(o);
59
+ let r, l = N(), p = n.dirname(l);
50
60
  do {
51
- if (o = l, s !== void 0 && o !== s && !o.startsWith(`${s}/`))
61
+ if (r = p, s !== void 0 && r !== s && !r.startsWith(`${s}/`))
52
62
  break;
53
- const w = i.join(o, ".gitignore");
54
- if (await A(w)) {
55
- n = i.dirname(w);
56
- const y = i.relative(n, R()).split("/"), v = H(w);
57
- for (const p of v) {
58
- const u = p.startsWith("!") ? p.slice(1) : p, h = u.search(/[*?[]/u), x = h === -1 ? u : u.slice(0, h), r = x.split("/"), d = h !== -1 && !x.endsWith("/");
59
- let a = !0;
60
- const f = Math.min(y.length, r.length);
61
- for (let m = 0; m < f; m++) {
62
- const C = r[m];
63
- if (!(d && m === r.length - 1 ? y[m].startsWith(C) : y[m] === C) && C !== "") {
64
- a = !1;
63
+ const w = n.join(r, ".gitignore");
64
+ if (await G(w)) {
65
+ e = !0, l = n.dirname(w);
66
+ const x = n.relative(l, N()).split("/"), D = Y(w);
67
+ for (const g of D) {
68
+ const b = g.startsWith("!") ? g.slice(1) : g, f = b.search(/[*?[]/u), h = f === -1 ? b : b.slice(0, f), j = h.split("/"), y = f !== -1 && !h.endsWith("/");
69
+ let S = !0;
70
+ const i = Math.min(x.length, j.length);
71
+ for (let c = 0; c < i; c++) {
72
+ const a = j[c];
73
+ if (!(y && c === j.length - 1 ? x[c].startsWith(a) : x[c] === a) && a !== "") {
74
+ S = !1;
65
75
  break;
66
76
  }
67
77
  }
68
- a && (p.startsWith("!") || t.push(p));
78
+ S && (g.startsWith("!") || t.push(g));
69
79
  }
70
80
  }
71
- l = i.dirname(o);
72
- } while (l !== o);
73
- return { ignorePatterns: t, globRoot: n };
81
+ p = n.dirname(r);
82
+ } while (p !== r);
83
+ return { ignorePatterns: t, globRoot: l, hasIgnoreFiles: e };
74
84
  }
75
- async function ee(t) {
76
- return (await z("**/.gitignore", {
77
- cwd: R(),
85
+ async function ue(t) {
86
+ const e = await X("**/.gitignore", {
87
+ cwd: N(),
78
88
  // Gitignore files are unlikely to be symbolic links
79
89
  followSymbolicLinks: !1,
80
90
  // Don't look for ignore files in these places for speed:
81
- ignore: [
82
- // Hardcoded ignores in TypeScript
83
- "**/node_modules/**",
84
- "**/bower_components/**",
85
- "**/jspm_packages/**",
86
- // Default build output folder in bundlers
87
- "**/dist/**"
88
- ],
91
+ ignore: Z,
89
92
  // Not applicable for our glob pattern
90
93
  expandDirectories: !1
91
- })).flatMap((s) => {
92
- const o = i.relative(t, i.dirname(s)), n = H(s), l = [];
93
- for (const w of n)
94
- w.startsWith("!") || l.push(i.join(o, w));
95
- return l;
96
94
  });
95
+ return { ignorePatterns: e.flatMap((s) => {
96
+ const r = n.relative(t, n.dirname(s)), l = Y(s), p = [];
97
+ for (const w of l)
98
+ w.startsWith("!") || p.push(n.join(r, w));
99
+ return p;
100
+ }), hasIgnoreFiles: e.length > 0 };
97
101
  }
98
- const te = ["js", "jsx", "mjs", "cjs"], oe = ["ts", "tsx", "mts", "cts"], se = ["json"], ie = `**/*.{${[...te, ...oe, ...se].join(",")}}`;
99
- async function re(t) {
100
- const e = await Y(), s = i.join(process.cwd(), ie), o = i.join(i.resolve(e.globRoot), "/"), n = (await z(s, {
101
- cwd: e.globRoot,
102
- ignore: e.ignorePatterns,
102
+ const ee = ["js", "jsx", "mjs", "cjs"], te = ["ts", "tsx", "mts", "cts"], me = /* @__PURE__ */ new Set([...ee, ...te]), pe = ["json"], ge = ["css", "scss", "sass", "html"];
103
+ async function fe(t, e = !1) {
104
+ const o = await de(), r = `**/*.{${[
105
+ ...ee,
106
+ ...te,
107
+ ...pe,
108
+ ...e ? ge : []
109
+ ].join(",")}}`, l = n.join(process.cwd(), r), p = n.join(n.resolve(o.globRoot), "/"), w = (await X(l, {
110
+ cwd: o.globRoot,
111
+ ignore: o.ignorePatterns,
103
112
  // The files we are looking for are unlikely to be symbolic links
104
113
  followSymbolicLinks: !1,
105
114
  // Not applicable for our glob pattern
@@ -108,142 +117,150 @@ async function re(t) {
108
117
  // default behavior). If any tsconfig.json explicitly includes such files,
109
118
  // they will still be codemodded.
110
119
  })).filter(
111
- (r) => r.endsWith(".json") || t === void 0 || o + r === t
120
+ (i) => i.endsWith(".json") || t === void 0 || p + i === t
112
121
  );
113
- let l = i.relative(e.globRoot, process.cwd());
114
- l !== "" && (l += "/");
115
- const w = o.length + l.length, E = [], y = [], v = /* @__PURE__ */ new Set();
116
- for (const r of n) {
117
- const d = o + r;
118
- if (r.endsWith(".json")) {
119
- const a = i.basename(r);
120
- a === "package.json" ? E.push(d) : (a.startsWith("tsconfig.") || a.startsWith("jsconfig.")) && y.push(d);
122
+ let k = n.relative(o.globRoot, process.cwd());
123
+ k !== "" && (k += "/");
124
+ const x = p.length + k.length, D = [], g = [], b = /* @__PURE__ */ new Set();
125
+ for (const i of w) {
126
+ const c = p + i;
127
+ if (i.endsWith(".json")) {
128
+ const a = n.basename(i);
129
+ a === "package.json" ? D.push(c) : (a.startsWith("tsconfig.") || a.startsWith("jsconfig.")) && g.push(c);
121
130
  } else {
122
- const a = r.slice(l.length);
123
- v.add(a);
131
+ const a = i.slice(k.length);
132
+ b.add(a);
124
133
  }
125
134
  }
126
- let p = await N("tsconfig.json", i.dirname(process.cwd()));
127
- p !== void 0 && (p = T(p), y.push(p)), y.sort((r, d) => {
128
- const a = d.split("/").length - r.split("/").length;
135
+ let f = await W("tsconfig.json", n.dirname(process.cwd()));
136
+ f !== void 0 && (f = _(f), g.push(f)), g.sort((i, c) => {
137
+ const a = c.split("/").length - i.split("/").length;
129
138
  if (a !== 0)
130
139
  return a;
131
- const f = i.basename(r), m = i.basename(d);
132
- return f === m ? 0 : f.endsWith("tsconfig.json") ? -1 : m.endsWith("tsconfig.json") ? 1 : f.endsWith("tsconfig.build.json") ? -1 : m.endsWith("tsconfig.build.json") ? 1 : f.localeCompare(m);
140
+ const u = n.basename(i), P = n.basename(c);
141
+ return u === P ? 0 : u.endsWith("tsconfig.json") ? -1 : P.endsWith("tsconfig.json") ? 1 : u.endsWith("tsconfig.build.json") ? -1 : P.endsWith("tsconfig.build.json") ? 1 : u.localeCompare(P);
133
142
  });
134
- let u = await N("package.json");
135
- u !== void 0 && (u = T(u));
136
- const h = [], x = /* @__PURE__ */ new Set();
143
+ let h = await W("package.json");
144
+ h !== void 0 && (h = _(h));
145
+ const j = [
146
+ .../* @__PURE__ */ new Set([...D, ...h === void 0 ? [] : [h]])
147
+ ].sort((i, c) => c.length - i.length), y = [], S = /* @__PURE__ */ new Set();
137
148
  if (await Promise.all(
138
- y.map(async (r) => {
139
- const d = i.relative(process.cwd(), r), a = c.readConfigFile(r, c.sys.readFile);
149
+ g.map(async (i) => {
150
+ const c = n.relative(process.cwd(), i), a = d.readConfigFile(i, d.sys.readFile);
140
151
  if (a.error !== void 0) {
141
- g(
152
+ m(
142
153
  "error",
143
- d,
144
- c.formatDiagnosticsWithColorAndContext([a.error], {
145
- getCanonicalFileName: _,
146
- getCurrentDirectory: c.sys.getCurrentDirectory,
147
- getNewLine: () => c.sys.newLine
154
+ c,
155
+ d.formatDiagnosticsWithColorAndContext([a.error], {
156
+ getCanonicalFileName: q,
157
+ getCurrentDirectory: d.sys.getCurrentDirectory,
158
+ getNewLine: () => d.sys.newLine
148
159
  })
149
160
  );
150
161
  return;
151
162
  }
152
- const f = c.parseJsonConfigFileContent(
163
+ const u = d.parseJsonConfigFileContent(
153
164
  a.config,
154
- c.sys,
155
- i.dirname(r),
165
+ d.sys,
166
+ n.dirname(i),
156
167
  void 0,
157
- r
158
- ), m = 18003;
159
- f.errors.filter((b) => b.code !== m).length > 0 && g(
168
+ i
169
+ ), P = 18003;
170
+ u.errors.filter((I) => I.code !== P).length > 0 && m(
160
171
  "warn",
161
- d,
162
- c.formatDiagnosticsWithColorAndContext(f.errors, {
163
- getCanonicalFileName: _,
164
- getCurrentDirectory: c.sys.getCurrentDirectory,
165
- getNewLine: () => c.sys.newLine
172
+ c,
173
+ d.formatDiagnosticsWithColorAndContext(u.errors, {
174
+ getCanonicalFileName: q,
175
+ getCurrentDirectory: d.sys.getCurrentDirectory,
176
+ getNewLine: () => d.sys.newLine
166
177
  })
167
178
  );
168
- const M = r === p, F = f.fileNames.filter((b) => {
169
- if (t !== void 0 && b !== t)
179
+ const se = i === f, U = u.fileNames.filter((I) => {
180
+ if (t !== void 0 && I !== t)
170
181
  return !1;
171
- const S = b.slice(w);
172
- return v.delete(S) ? (x.add(S), !0) : x.has(S) || S.endsWith(".json") || b.includes("node_modules") ? !1 : !M;
182
+ const O = I.slice(x);
183
+ return b.delete(O) ? (S.add(O), !0) : S.has(O) || O.endsWith(".json") || I.includes("node_modules") ? !1 : !se;
173
184
  });
174
- if (F.length === 0)
185
+ if (U.length === 0)
175
186
  return;
176
- const O = i.dirname(r);
177
- let j = O, k = u;
178
- for (; j === e.globRoot || // Stop searching outside repository root
179
- j.startsWith(`${e.globRoot}/`); ) {
180
- const b = i.join(j, "package.json");
181
- if (E.includes(b)) {
182
- k = b;
183
- break;
184
- }
185
- if (j === e.globRoot)
186
- break;
187
- j = i.dirname(j);
188
- }
189
- const L = k === void 0 ? void 0 : { filePath: k, contents: await $(i.dirname(k)) }, V = {
190
- typeScriptConfig: {
191
- filePath: r,
192
- compilerOptions: f.options
193
- },
194
- packageJson: L,
195
- logName: D("blue", L?.contents?.name ?? O),
196
- cwd: O,
197
- filePaths: F
198
- };
199
- h.push(V);
187
+ const L = n.dirname(i), re = H(L, j) ?? h;
188
+ y.push(
189
+ await K(U, L, re, {
190
+ filePath: i,
191
+ compilerOptions: u.options
192
+ })
193
+ );
200
194
  })
201
- ), v.size > 0) {
202
- const r = u === void 0 ? void 0 : {
203
- filePath: u,
204
- contents: await $(i.dirname(u))
205
- };
206
- h.push({
207
- typeScriptConfig: void 0,
208
- packageJson: r,
209
- cwd: process.cwd(),
210
- logName: D("blue", r?.contents?.name ?? process.cwd()),
211
- filePaths: Array.from(v).map((d) => i.join(process.cwd(), d))
212
- });
195
+ ), b.size > 0) {
196
+ const i = [...b].map((a) => n.join(process.cwd(), a)), c = Map.groupBy(i, (a) => H(a, j));
197
+ y.push(
198
+ ...await Promise.all(
199
+ [...c].map(async ([a, u]) => await K(u, process.cwd(), a))
200
+ )
201
+ );
213
202
  }
214
- return h.sort((r, d) => r.cwd.localeCompare(d.cwd)), P.projectsData = h, h;
203
+ return y.sort((i, c) => i.cwd.localeCompare(c.cwd)), v.projectsData = y, y;
204
+ }
205
+ function Te(t) {
206
+ const e = n.extname(t).slice(1);
207
+ return me.has(e);
208
+ }
209
+ function H(t, e) {
210
+ return e.find((o) => {
211
+ const s = n.dirname(o);
212
+ return t === s || t.startsWith(`${s}/`);
213
+ });
215
214
  }
216
- function ne() {
217
- P.codemod.meta.needsFooter && (P.codemod.meta.needsFooter = !1, process.exitCode !== void 0 && process.exitCode !== 0 ? g(
215
+ async function K(t, e, o, s) {
216
+ const r = o === void 0 ? void 0 : {
217
+ filePath: o,
218
+ contents: await ie(n.dirname(o))
219
+ };
220
+ return {
221
+ typeScriptConfig: s,
222
+ packageJson: r,
223
+ cwd: e,
224
+ filePaths: t,
225
+ logName: J("blue", r?.contents.name ?? e)
226
+ };
227
+ }
228
+ function he() {
229
+ v.codemod.meta.needsFooter && (v.codemod.meta.needsFooter = !1, process.exitCode !== void 0 && process.exitCode !== 0 ? m(
218
230
  "warn",
219
- P.codemodName,
231
+ v.codemodName,
220
232
  "One or more exceptions occurred during the codemod run. Please review the output above."
221
- ) : g(
233
+ ) : m(
222
234
  "info",
223
- P.codemodName,
224
- `${D("green", "Codemod completed successfully.")} Recommended next steps:
235
+ v.codemodName,
236
+ `${J("green", "Codemod completed successfully.")} Recommended next steps:
225
237
  - Review the codemod changes.
226
238
  - If your project uses ESLint, run ESLint autofix on the changed files.
227
239
  - If your project uses Prettier, run Prettier on the changed files.
228
240
  - If your project uses TypeScript, run type checking to ensure there are no type errors.`
229
241
  ));
230
242
  }
231
- async function ae(t, e, s) {
232
- P.codemod = t, P.codemodName = e;
233
- const o = await re(s);
234
- if (o.length === 0) {
235
- g("error", e, `Failed to find any .js or .ts files in ${process.cwd()} to run the codemod on.`), process.exitCode = 1;
243
+ async function we(t, e, o) {
244
+ v.codemod = t, v.codemodName = e;
245
+ const s = await fe(o, t.meta.includeComponentFiles);
246
+ if (s.length === 0) {
247
+ const r = t.meta.includeComponentFiles ? "source files or component manifests" : ".js or .ts files";
248
+ m("error", e, `Failed to find any ${r} in ${process.cwd()} to run the codemod on.`), process.exitCode = 1;
236
249
  return;
237
250
  }
238
- await t.run(o), ne();
251
+ await t.run(s), he();
239
252
  }
240
- const W = {
253
+ const E = {
254
+ coreViews: {
255
+ label: "@arcgis/core views and UI - highest priority",
256
+ description: "Use map components and slots instead. Directly constructed views will no longer include .ui (like zoom buttons) in 6.0."
257
+ },
241
258
  coreWidgets: {
242
259
  label: "@arcgis/core widgets - high priority",
243
260
  description: "WebGIS platform priority"
244
261
  },
245
262
  coreGeometryEngine: {
246
- label: "@arcgis/core geometry engine - high priority",
263
+ label: "@arcgis/core geometry engine and projection - high priority",
247
264
  description: "WebGIS platform priority"
248
265
  },
249
266
  codemod: {
@@ -254,7 +271,9 @@ const W = {
254
271
  label: "Calcite components",
255
272
  description: "This does not include visual breaking changes. See complete list in https://confluencewikidev.esri.com/spaces/Calcite/pages/464553094/Calcite+6.0+-+Breaking+Change+Release+February"
256
273
  },
257
- arcgisCoreComponents: { label: "Maps SDK for JavaScript" },
274
+ arcgisCore: { label: "@arcgis/core" },
275
+ arcgisComponents: { label: "WebGIS SDK components" },
276
+ arcgisSupport: { label: "WebGIS SDK support packages" },
258
277
  otherEsri: { label: "Other Esri and ArcGIS packages" },
259
278
  coreIntl: {
260
279
  label: "@arcgis/core translation utils",
@@ -264,36 +283,85 @@ const W = {
264
283
  label: "Non-Esri packages and web platform - low priority",
265
284
  description: "These deprecations do not block updating Esri packages and are not tied to an ArcGIS release."
266
285
  }
267
- }, I = new Q();
268
- I.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
269
- I.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(async (t, e) => {
270
- const s = await G(e);
271
- let o;
286
+ }, R = "https://webgis.esri.com/api/deprecations";
287
+ async function $e(t, e) {
288
+ const o = ae();
289
+ process.stderr.write(`Submitting deprecation report (${o}).
290
+ `);
291
+ let s;
272
292
  try {
273
- o = await X(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod.js"), "./codemods/geometry-operator-renames/codemod.ts": () => import("./codemod2.js"), "./codemods/lumina-component-extras-improvements/codemod.ts": () => import("./codemod3.js"), "./codemods/lumina-toolkit/codemod.ts": () => import("./codemod4.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod5.js"), "./codemods/normalize-calcite-icon-names/codemod.ts": () => import("./codemod6.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod7.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod8.js") }), `./codemods/${t}/codemod.ts`, 4);
274
- } catch (n) {
293
+ s = await fetch(e, {
294
+ method: "POST",
295
+ headers: { "Content-Type": "application/json" },
296
+ body: JSON.stringify({
297
+ submissionId: o,
298
+ report: t
299
+ }),
300
+ signal: AbortSignal.timeout(12e4),
301
+ redirect: "error"
302
+ });
303
+ } catch (l) {
304
+ throw new Error(`Deprecation reporting failed; check submission ${o} before retrying.`, {
305
+ cause: l
306
+ });
307
+ }
308
+ if (!s.ok)
309
+ throw new Error(`Deprecation reporting failed: HTTP ${s.status}. Submission ID: ${o}`);
310
+ const r = await s.json();
311
+ if (typeof r != "object" || r === null || !("submissionId" in r) || r.submissionId !== o)
312
+ throw new Error(`Invalid collector acknowledgement. Check submission ${o} before retrying.`);
313
+ process.stderr.write(`Deprecation report submitted to ${e} (${o}).
314
+ `);
315
+ }
316
+ const be = /(?:esri|arcgis)/iu, T = ["all", "repositories", "apis"], Ge = "@arcgis/codemod", Je = {
317
+ usages: "Refactor-out deprecated API usages",
318
+ definitions: "Remove deprecated APIs in next breaking changes release"
319
+ }, Me = {
320
+ usages: "The following deprecated APIs are used in files owned by assigned CODEOWNERS. Refactor them before the APIs are removed.",
321
+ definitions: "The following deprecated APIs are owned by assigned CODEOWNERS. Remove them in the next breaking changes release."
322
+ }, Ue = "This issue is autogenerated and updated regularly based on remaining items. Feel free to add comments and labels, update assignees, set milestone, or create sub-issues. Close it once completed. A new issue will be created if new findings are detected.", Le = "Task", _e = "deprecations sync-issues";
323
+ function qe(t) {
324
+ return be.test(t);
325
+ }
326
+ const A = new ne();
327
+ A.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
328
+ A.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(async (t, e) => {
329
+ const o = await M(e);
330
+ let s;
331
+ try {
332
+ s = await ce(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod.js"), "./codemods/geometry-operator-renames/codemod.ts": () => import("./codemod2.js"), "./codemods/lumina-component-extras-improvements/codemod.ts": () => import("./codemod3.js"), "./codemods/lumina-toolkit/codemod.ts": () => import("./codemod4.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod5.js"), "./codemods/normalize-calcite-icon-names/codemod.ts": () => import("./codemod6.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod7.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod8.js") }), `./codemods/${t}/codemod.ts`, 4);
333
+ } catch (r) {
275
334
  if (
276
335
  // direct Node execution
277
- typeof n == "object" && n !== null && "code" in n && n.code === "ERR_MODULE_NOT_FOUND" && "url" in n && typeof n.url == "string" && n.url.endsWith(`/${t}/codemod.ts`) || // Vite build execution
278
- String(n).includes("Unknown variable dynamic import:")
336
+ typeof r == "object" && r !== null && "code" in r && r.code === "ERR_MODULE_NOT_FOUND" && "url" in r && typeof r.url == "string" && r.url.endsWith(`/${t}/codemod.ts`) || // Vite build execution
337
+ String(r).includes("Unknown variable dynamic import:")
279
338
  ) {
280
- g("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
339
+ m("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
281
340
  return;
282
341
  } else
283
- throw n;
342
+ throw r;
284
343
  }
285
- if (typeof o.codemod != "object" || o.codemod === null) {
286
- g("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
344
+ if (typeof s.codemod != "object" || s.codemod === null) {
345
+ m("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
287
346
  return;
288
347
  }
289
- await ae(o.codemod, D("blue", t), s);
348
+ await we(s.codemod, J("blue", t), o);
290
349
  });
291
- const J = I.command("deprecations").description("Audit and report deprecated APIs");
292
- J.command("audit-usages").description("Report deprecated API usages").argument("[path]", "Directory to audit", process.cwd()).option("--esri-only", "Only report usages of deprecated APIs from Esri and ArcGIS packages", !1).option(
350
+ const C = A.command("deprecations").description(
351
+ `Audit and report deprecated APIs.
352
+
353
+ Documentation: https://webgis.esri.com/references/codemod/deprecations`
354
+ );
355
+ C.command("audit-usages").description(
356
+ "Report deprecated API usages. Documentation: https://webgis.esri.com/references/codemod/deprecations#audit-usages"
357
+ ).argument("[path]", "Directory to audit", process.cwd()).option("--esri-only", "Only report usages of deprecated APIs from Esri and ArcGIS packages", !1).option(
293
358
  "--category <category>",
294
- `Only report usages in a category. Available categories: ${Object.keys(W).join(", ")}`,
295
- de
359
+ `Only report usages in a category. Available categories: ${Object.keys(E).join(", ")}`,
360
+ oe
296
361
  ).option("--package <package-name>", "Only report usages of deprecated APIs from this package").option(
362
+ "--report [url]",
363
+ `Submit a complete repository scan to the WebGIS collector (default: ${R})`
364
+ ).option(
297
365
  "--json",
298
366
  "Output results as JSON. Example: npx @arcgis/codemod deprecations audit-usages --json > usages.json",
299
367
  !1
@@ -303,26 +371,88 @@ J.command("audit-usages").description("Report deprecated API usages").argument("
303
371
  !1
304
372
  ).action(async (t, e) => {
305
373
  if (e.json && e.md) {
306
- g("error", "@arcgis/codemod", "The --json and --md options cannot be used together."), process.exitCode = 1;
374
+ m("error", "@arcgis/codemod", "The --json and --md options cannot be used together."), process.exitCode = 1;
307
375
  return;
308
376
  }
309
- const s = await G(t), { auditDeprecatedUsages: o } = await import("./index.js"), n = e.md ? "md" : e.json ? "json" : "text";
310
- await o(s, {
377
+ const o = await M(t), { auditDeprecatedUsages: s } = await import("./index.js"), r = e.md ? "md" : e.json ? "json" : "text";
378
+ await s(o, {
311
379
  esriOnly: e.esriOnly,
312
- outputFormat: n,
380
+ outputFormat: r,
313
381
  category: e.category,
314
- packageName: e.package
382
+ packageName: e.package,
383
+ reportingUrl: e.report === !0 ? R : e.report || void 0
315
384
  });
316
385
  });
317
- J.command("audit-definitions").description("Report exported APIs marked as deprecated").argument("[path]", "Directory to audit", process.cwd()).option(
386
+ C.command("audit-definitions").description(
387
+ "Report exported APIs marked as deprecated. Documentation: https://webgis.esri.com/references/codemod/deprecations#audit-definitions"
388
+ ).argument("[path]", "Directory to audit", process.cwd()).option(
318
389
  "--json",
319
390
  "Output results as JSON. Example: npx @arcgis/codemod deprecations audit-definitions --json > definitions.json",
320
391
  !1
321
392
  ).action(async (t, e) => {
322
- const s = await G(t), { auditDeprecatedDefinitions: o } = await import("./index2.js");
323
- await o(s, e.json);
393
+ const o = await M(t), { auditDeprecatedDefinitions: s } = await import("./index2.js");
394
+ await s(o, e.json);
324
395
  });
325
- J.command("sync-issues").description(
396
+ C.command("aggregate-usages").description(
397
+ "Aggregate audit-usages reports into repository summaries and an API usage tree. Documentation: https://webgis.esri.com/references/codemod/deprecations#analyze-the-ecosystem"
398
+ ).argument("[reports...]", "Paths to audit-usages JSON files").option(
399
+ "--section <section>",
400
+ `Reports to include in the markdown report: ${T.join(", ")}`,
401
+ ye,
402
+ "all"
403
+ ).option(
404
+ "--remote [url]",
405
+ `Read the latest stored audit per repository from the WebGIS collector (default: ${R})`
406
+ ).option(
407
+ "--repository <repository>",
408
+ "Select a remote repository (host/owner/repo); repeat to select multiple",
409
+ $,
410
+ []
411
+ ).option("--branch <branch>", "Select remote audits from this branch").option("--since <date>", "Select remote audits on or after this ISO date", z).option("--until <date>", "Select remote audits on or before this ISO date", z).option(
412
+ "--definitions <report>",
413
+ "Compare an audit-definitions JSON report to list APIs with zero detected usages. Can be specified multiple times.",
414
+ $,
415
+ []
416
+ ).option("--esri-only", "Only report usages of deprecated APIs from Esri and ArcGIS packages", !1).option(
417
+ "--category <category>",
418
+ `Only report usages in a category. Available categories: ${Object.keys(E).join(", ")}`,
419
+ oe
420
+ ).option("--package <package-name>", "Only report usages of deprecated APIs from this package").option("--json", "Output results as JSON", !1).option("--md", "Output results as Markdown", !1).action(async (t, e) => {
421
+ if (!t.length && !e.remote || !e.remote && (e.repository.length || e.branch || e.since || e.until))
422
+ throw new Error("Provide report files or --remote. Repository, branch, and date selection require --remote.");
423
+ if (e.since && e.until && e.since > e.until)
424
+ throw new Error("--since must not be after --until.");
425
+ if (e.json && e.md) {
426
+ m("error", "@arcgis/codemod", "The --json and --md options cannot be used together."), process.exitCode = 1;
427
+ return;
428
+ }
429
+ const { aggregateUsagesFromFiles: o } = await import("./index3.js");
430
+ await o(
431
+ t,
432
+ e.md ? "md" : e.json ? "json" : "text",
433
+ {
434
+ esriOnly: e.esriOnly,
435
+ category: e.category,
436
+ packageName: e.package,
437
+ section: e.section
438
+ },
439
+ e.definitions,
440
+ e.remote ? {
441
+ url: e.remote === !0 ? R : e.remote,
442
+ repositories: e.repository,
443
+ branch: e.branch,
444
+ since: e.since,
445
+ until: e.until
446
+ } : void 0
447
+ );
448
+ });
449
+ function ye(t) {
450
+ const e = T.find((o) => o === t);
451
+ if (e !== void 0)
452
+ return e;
453
+ throw new F(`Expected one of: ${T.join(", ")}.`);
454
+ }
455
+ C.command("sync-issues").description(
326
456
  `Create or update deprecation audit issues. Requires authenticated gh cli.
327
457
 
328
458
  Existing open issues are updated if out of date (matched by title and invisible comment inside).
@@ -330,51 +460,70 @@ Otherwise, a new issue is created. Assignees are determined based on CODEOWNERS.
330
460
  ).argument(
331
461
  "<audit-json>",
332
462
  "Path to the JSON file as output by the --json flag in the audit-usages or audit-definitions CLI"
333
- ).option("--dry-run", "Print planned issue and comment changes without changing GitHub", !1).option("--offset <number>", "Skip the first number of issue plans", U, 0).option("--limit <number>", "Process at most this many issue plans", U).option(
463
+ ).option("--dry-run", "Print planned issue and comment changes without changing GitHub", !1).option("--close-resolved", "Close stale managed issues after a complete, unfiltered repository-root audit", !1).option("--offset <number>", "Skip the first number of issue plans", B, 0).option("--limit <number>", "Process at most this many issue plans", B).option(
334
464
  "--label <label>",
335
465
  "Label to add to newly created issues. Can be specified multiple times.",
336
- ce,
466
+ $,
337
467
  []
338
468
  ).action(async (t, e) => {
339
- const s = i.resolve(t);
340
- if (!await A(s) || !(await q(s)).isFile()) {
341
- g("error", "@arcgis/codemod", `Failed to find the audit JSON file: ${t}`), process.exitCode = 1;
469
+ const o = n.resolve(t);
470
+ if (!await G(o) || !(await V(o)).isFile()) {
471
+ m("error", "@arcgis/codemod", `Failed to find the audit JSON file: ${t}`), process.exitCode = 1;
342
472
  return;
343
473
  }
344
- const { syncDeprecationIssues: o } = await import("./sync.js");
345
- await o(
346
- await B(s),
347
- e.dryRun,
348
- e.offset,
349
- e.limit,
350
- e.label
351
- );
474
+ const { syncDeprecationIssues: s } = await import("./sync.js");
475
+ await s(await Q(o), e.dryRun, e.offset, e.limit, {
476
+ labels: e.label,
477
+ closeResolved: e.closeResolved
478
+ });
352
479
  });
353
- function ce(t, e) {
480
+ function z(t) {
481
+ const e = new Date(t);
482
+ if (!Number.isFinite(e.getTime()))
483
+ throw new F("Expected an ISO date.");
484
+ return e.toISOString();
485
+ }
486
+ function $(t, e) {
354
487
  return [...e, t];
355
488
  }
356
- function U(t) {
489
+ function B(t) {
357
490
  const e = Number(t);
358
491
  if (!Number.isSafeInteger(e) || e < 0)
359
- throw new K("Expected a non-negative integer.");
492
+ throw new F("Expected a non-negative integer.");
360
493
  return e;
361
494
  }
362
- function de(t) {
363
- if (!Object.hasOwn(W, t))
364
- throw new K(`Expected one of: ${Object.keys(W).join(", ")}.`);
495
+ function oe(t) {
496
+ if (!Object.hasOwn(E, t))
497
+ throw new F(`Expected one of: ${Object.keys(E).join(", ")}.`);
365
498
  return t;
366
499
  }
367
- async function G(t) {
368
- const e = i.resolve(t);
369
- await A(e) || (g("error", "@arcgis/codemod", `Failed to find the target path: ${t}`), process.exit(1));
370
- const s = await B(e), o = (await q(s)).isFile();
371
- return process.chdir(o ? i.dirname(s) : s), o ? s : void 0;
500
+ async function M(t) {
501
+ const e = n.resolve(t);
502
+ await G(e) || (m("error", "@arcgis/codemod", `Failed to find the target path: ${t}`), process.exit(1));
503
+ const o = await Q(e), s = (await V(o)).isFile();
504
+ return process.chdir(s ? n.dirname(o) : o), s ? o : void 0;
372
505
  }
373
- I.parse();
506
+ C.command("sync-markdown").description(
507
+ "Update managed Markdown comments on an existing issue, leaving its body untouched. Requires authenticated gh cli."
508
+ ).argument("<markdown-file>", "Path to the Markdown report").requiredOption("--issue <url>", "HTTPS URL of the existing GitHub issue").option("--dry-run", "Print planned comment changes without changing GitHub", !1).action(async (t, e) => {
509
+ const { syncMarkdown: o } = await import("./syncMarkdown.js");
510
+ await o(n.resolve(t), e.issue, e.dryRun);
511
+ });
512
+ A.parse();
374
513
  export {
375
- xe as a,
376
- W as d,
377
- P as g,
378
- ne as p,
379
- ae as r
514
+ $e as a,
515
+ qe as b,
516
+ We as c,
517
+ E as d,
518
+ R as e,
519
+ _e as f,
520
+ v as g,
521
+ Je as h,
522
+ Te as i,
523
+ Le as j,
524
+ Ge as k,
525
+ Me as l,
526
+ Ue as m,
527
+ he as p,
528
+ we as r
380
529
  };