@arcgis/codemod 6.0.0-next.4 → 6.0.0-next.41

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