@arcgis/codemod 5.2.0-next.118 → 5.2.0-next.119

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,326 @@
1
+ import { log as y } from "@arcgis/toolkit/log";
2
+ import { Command as V, InvalidArgumentError as Q } from "@commander-js/extra-typings";
3
+ import { stat as U, realpath as K } from "node:fs/promises";
4
+ import { getCwd as E, path as n, toPosixPathSeparators as M } from "@arcgis/node-toolkit/path";
5
+ import { existsAsync as N, asyncFindPath as T } from "@arcgis/node-toolkit/file";
6
+ import "ts-morph";
7
+ import d from "typescript";
8
+ import { asyncRetrievePackageJson as _ } from "@arcgis/node-toolkit/packageJson";
9
+ import { glob as q } from "tinyglobby";
10
+ import { gitIgnoreFileToGlobs as B } from "@arcgis/node-toolkit/glob";
11
+ import { identity as G } from "@arcgis/toolkit/function";
12
+ import { styleText as I } 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((a, u) => {
16
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(u.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + e + (e.split("/").length !== s ? ". Note that variables only represent file names one level deep." : ""))));
17
+ });
18
+ }, xe = {
19
+ allowImportingTsExtensions: !0,
20
+ allowJs: !0,
21
+ allowArbitraryExtensions: !0,
22
+ allowSyntheticDefaultImports: !0,
23
+ checkJs: !0,
24
+ experimentalDecorators: !0,
25
+ forceConsistentCasingInFileNames: !1,
26
+ isolatedModules: !1,
27
+ isolatedDeclarations: !1,
28
+ jsx: d.JsxEmit.Preserve,
29
+ lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
30
+ module: d.ModuleKind.ESNext,
31
+ moduleResolution: d.ModuleResolutionKind.Bundler,
32
+ moduleDetection: d.ModuleDetectionKind.Auto,
33
+ strict: !1,
34
+ target: d.ScriptTarget.ESNext,
35
+ resolveJsonModule: !0,
36
+ esModuleInterop: !0
37
+ }, v = {
38
+ codemod: void 0,
39
+ codemodName: void 0,
40
+ projectsData: void 0,
41
+ 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 };
46
+ }
47
+ async function Z() {
48
+ const t = [];
49
+ let e, s = E(), o = n.dirname(s);
50
+ do {
51
+ e = o;
52
+ const a = n.join(e, ".gitignore");
53
+ if (await N(a)) {
54
+ s = n.dirname(a);
55
+ const P = n.relative(s, E()).split("/"), j = B(a);
56
+ for (const l of j) {
57
+ const g = l.startsWith("!") ? l.slice(1) : l, h = g.search(/[*?[]/u), f = h === -1 ? g : g.slice(0, h), w = f.split("/"), x = h !== -1 && !f.endsWith("/");
58
+ let i = !0;
59
+ const c = Math.min(P.length, w.length);
60
+ for (let r = 0; r < c; r++) {
61
+ const m = w[r];
62
+ if (!(x && r === w.length - 1 ? P[r].startsWith(m) : P[r] === m) && m !== "") {
63
+ i = !1;
64
+ break;
65
+ }
66
+ }
67
+ i && (l.startsWith("!") || t.push(l));
68
+ }
69
+ }
70
+ o = n.dirname(e);
71
+ } while (o !== e);
72
+ return { ignorePatterns: t, globRoot: s };
73
+ }
74
+ async function ee(t) {
75
+ return (await q("**/.gitignore", {
76
+ cwd: E(),
77
+ // Gitignore files are unlikely to be symbolic links
78
+ followSymbolicLinks: !1,
79
+ // Don't look for ignore files in these places for speed:
80
+ ignore: [
81
+ // Hardcoded ignores in TypeScript
82
+ "**/node_modules/**",
83
+ "**/bower_components/**",
84
+ "**/jspm_packages/**",
85
+ // Default build output folder in bundlers
86
+ "**/dist/**"
87
+ ],
88
+ // Not applicable for our glob pattern
89
+ expandDirectories: !1
90
+ })).flatMap((s) => {
91
+ const o = n.relative(t, n.dirname(s)), a = B(s), u = [];
92
+ for (const P of a)
93
+ P.startsWith("!") || u.push(n.join(o, P));
94
+ return u;
95
+ });
96
+ }
97
+ const te = ["js", "jsx", "mjs", "cjs"], oe = ["ts", "tsx", "mts", "cts"], se = ["json"], ne = `**/*.{${[...te, ...oe, ...se].join(",")}}`;
98
+ async function ie(t) {
99
+ const e = await Y(), s = n.join(process.cwd(), ne), o = n.join(n.resolve(e.globRoot), "/"), a = (await q(s, {
100
+ cwd: e.globRoot,
101
+ ignore: e.ignorePatterns,
102
+ // The files we are looking for are unlikely to be symbolic links
103
+ followSymbolicLinks: !1,
104
+ // Not applicable for our glob pattern
105
+ expandDirectories: !1
106
+ // Files and folders starting with . are excluded (matches TypeScript's
107
+ // default behavior). If any tsconfig.json explicitly includes such files,
108
+ // they will still be codemodded.
109
+ })).filter(
110
+ (i) => i.endsWith(".json") || t === void 0 || o + i === t
111
+ );
112
+ let u = n.relative(e.globRoot, process.cwd());
113
+ u !== "" && (u += "/");
114
+ const P = o.length + u.length, j = [], l = [], g = /* @__PURE__ */ new Set();
115
+ for (const i of a) {
116
+ const c = o + i;
117
+ if (i.endsWith(".json")) {
118
+ const r = n.basename(i);
119
+ r === "package.json" ? j.push(c) : (r.startsWith("tsconfig.") || r.startsWith("jsconfig.")) && l.push(c);
120
+ } else {
121
+ const r = i.slice(u.length);
122
+ g.add(r);
123
+ }
124
+ }
125
+ let h = await T("tsconfig.json", n.dirname(process.cwd()));
126
+ h !== void 0 && (h = M(h), l.push(h)), l.sort((i, c) => {
127
+ const r = c.split("/").length - i.split("/").length;
128
+ if (r !== 0)
129
+ return r;
130
+ const m = n.basename(i), p = n.basename(c);
131
+ return m === p ? 0 : m.endsWith("tsconfig.json") ? -1 : p.endsWith("tsconfig.json") ? 1 : m.endsWith("tsconfig.build.json") ? -1 : p.endsWith("tsconfig.build.json") ? 1 : m.localeCompare(p);
132
+ });
133
+ let f = await T("package.json");
134
+ f !== void 0 && (f = M(f));
135
+ const w = [], x = /* @__PURE__ */ new Set();
136
+ if (await Promise.all(
137
+ l.map(async (i) => {
138
+ const c = n.relative(process.cwd(), i), r = d.readConfigFile(i, d.sys.readFile);
139
+ if (r.error !== void 0) {
140
+ y(
141
+ "error",
142
+ c,
143
+ d.formatDiagnosticsWithColorAndContext([r.error], {
144
+ getCanonicalFileName: G,
145
+ getCurrentDirectory: d.sys.getCurrentDirectory,
146
+ getNewLine: () => d.sys.newLine
147
+ })
148
+ );
149
+ return;
150
+ }
151
+ const m = n.basename(c), p = d.parseJsonConfigFileContent(
152
+ r.config,
153
+ d.sys,
154
+ n.dirname(i),
155
+ void 0,
156
+ m
157
+ ), O = 18003;
158
+ p.errors.filter((b) => b.code !== O).length > 0 && y(
159
+ "warn",
160
+ c,
161
+ d.formatDiagnosticsWithColorAndContext(p.errors, {
162
+ getCanonicalFileName: G,
163
+ getCurrentDirectory: d.sys.getCurrentDirectory,
164
+ getNewLine: () => d.sys.newLine
165
+ })
166
+ );
167
+ const W = i === h, z = c === m, A = p.fileNames.filter((b) => {
168
+ if (t !== void 0 && b !== t)
169
+ return !1;
170
+ const S = b.slice(P);
171
+ return g.delete(S) ? (x.add(S), !0) : x.has(S) || S.endsWith(".json") || b.includes("node_modules") ? !1 : !W;
172
+ });
173
+ if (A.length === 0)
174
+ return;
175
+ l.length === 1 && (W || z) && g.clear();
176
+ const F = n.dirname(i);
177
+ let C = F, D = f;
178
+ do {
179
+ const b = n.join(C, "package.json");
180
+ if (j.includes(b)) {
181
+ D = b;
182
+ break;
183
+ }
184
+ } while (C !== e.globRoot && (C = n.dirname(C)));
185
+ const L = D === void 0 ? void 0 : { filePath: D, contents: await _(n.dirname(D)) }, H = {
186
+ typeScriptConfig: {
187
+ filePath: i,
188
+ compilerOptions: p.options
189
+ },
190
+ packageJson: L,
191
+ logName: I("blue", L?.contents?.name ?? F),
192
+ cwd: F,
193
+ filePaths: A
194
+ };
195
+ w.push(H);
196
+ })
197
+ ), g.size > 0) {
198
+ const i = f === void 0 ? void 0 : {
199
+ filePath: f,
200
+ contents: await _(n.dirname(f))
201
+ };
202
+ w.push({
203
+ typeScriptConfig: void 0,
204
+ packageJson: i,
205
+ cwd: process.cwd(),
206
+ logName: I("blue", i?.contents?.name ?? process.cwd()),
207
+ filePaths: Array.from(g).map((c) => n.join(process.cwd(), c))
208
+ });
209
+ }
210
+ return w.sort((i, c) => i.cwd.localeCompare(c.cwd)), v.projectsData = w, w;
211
+ }
212
+ function re() {
213
+ v.codemod.meta.needsFooter && (v.codemod.meta.needsFooter = !1, process.exitCode !== void 0 && process.exitCode !== 0 ? y(
214
+ "warn",
215
+ v.codemodName,
216
+ "One or more exceptions occurred during the codemod run. Please review the output above."
217
+ ) : y(
218
+ "info",
219
+ v.codemodName,
220
+ `${I("green", "Codemod completed successfully.")} Recommended next steps:
221
+ - Review the codemod changes.
222
+ - If your project uses ESLint, run ESLint autofix on the changed files.
223
+ - If your project uses Prettier, run Prettier on the changed files.
224
+ - If your project uses TypeScript, run type checking to ensure there are no type errors.`
225
+ ));
226
+ }
227
+ async function ae(t, e, s) {
228
+ v.codemod = t, v.codemodName = e;
229
+ const o = await ie(s);
230
+ if (o.length === 0) {
231
+ y("error", e, `Failed to find any .js or .ts files in ${process.cwd()} to run the codemod on.`), process.exitCode = 1;
232
+ return;
233
+ }
234
+ await t.run(o), re();
235
+ }
236
+ const k = new V();
237
+ k.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
238
+ k.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(async (t, e) => {
239
+ const s = await J(e);
240
+ let o;
241
+ try {
242
+ o = await X(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod-DsvACPpG.js"), "./codemods/geometry-operator-renames/codemod.ts": () => import("./codemod-CVM-ahrt.js"), "./codemods/lumina-component-extras-improvements/codemod.ts": () => import("./codemod-lXphX6G6.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod-BhxEZX2B.js"), "./codemods/normalize-calcite-icon-names/codemod.ts": () => import("./codemod-BaP5d7QD.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod-DzUJHZc4.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod-DlxIx0fk.js") }), `./codemods/${t}/codemod.ts`, 4);
243
+ } catch (a) {
244
+ if (
245
+ // direct Node execution
246
+ typeof a == "object" && a !== null && "code" in a && a.code === "ERR_MODULE_NOT_FOUND" && "url" in a && typeof a.url == "string" && a.url.endsWith(`/${t}/codemod.ts`) || // Vite build execution
247
+ String(a).includes("Unknown variable dynamic import:")
248
+ ) {
249
+ y("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
250
+ return;
251
+ } else
252
+ throw a;
253
+ }
254
+ if (typeof o.codemod != "object" || o.codemod === null) {
255
+ y("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
256
+ return;
257
+ }
258
+ await ae(o.codemod, I("blue", t), s);
259
+ });
260
+ const R = k.command("deprecations").description("Audit and report deprecated APIs");
261
+ R.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(
262
+ "--json",
263
+ "Output results as JSON. Example: npx @arcgis/codemod deprecations audit-usages --json > usages.json",
264
+ !1
265
+ ).action(async (t, e) => {
266
+ const s = await J(t), { auditDeprecatedUsages: o } = await import("./index-G3qil5yu.js");
267
+ await o(s, e.esriOnly, e.json);
268
+ });
269
+ R.command("audit-definitions").description("Report exported APIs marked as deprecated").argument("[path]", "Directory to audit", process.cwd()).option(
270
+ "--json",
271
+ "Output results as JSON. Example: npx @arcgis/codemod deprecations audit-definitions --json > definitions.json",
272
+ !1
273
+ ).action(async (t, e) => {
274
+ const s = await J(t), { auditDeprecatedDefinitions: o } = await import("./index-BYkl918U.js");
275
+ await o(s, e.json);
276
+ });
277
+ R.command("sync-issues").description(
278
+ `Create or update deprecation audit issues. Requires authenticated gh cli.
279
+
280
+ Existing open issues are updated if out of date (matched by title and invisible comment inside).
281
+ Otherwise, a new issue is created. Assignees are determined based on CODEOWNERS.`
282
+ ).argument(
283
+ "<audit-json>",
284
+ "Path to the JSON file as output by the --json flag in the audit-usages or audit-definitions CLI"
285
+ ).option("--dry-run", "Print issue contents without changing GitHub", !1).option("--offset <number>", "Skip the first number of issue plans", $, 0).option("--limit <number>", "Process at most this many issue plans", $).option(
286
+ "--label <label>",
287
+ "Label to add to newly created issues. Can be specified multiple times.",
288
+ ce,
289
+ []
290
+ ).action(async (t, e) => {
291
+ const s = n.resolve(t);
292
+ if (!await N(s) || !(await U(s)).isFile()) {
293
+ y("error", "@arcgis/codemod", `Failed to find the audit JSON file: ${t}`), process.exitCode = 1;
294
+ return;
295
+ }
296
+ const { syncDeprecationIssues: o } = await import("./sync-e0pgnEOM.js");
297
+ await o(
298
+ await K(s),
299
+ e.dryRun,
300
+ e.offset,
301
+ e.limit,
302
+ e.label
303
+ );
304
+ });
305
+ function ce(t, e) {
306
+ return [...e, t];
307
+ }
308
+ function $(t) {
309
+ const e = Number(t);
310
+ if (!Number.isSafeInteger(e) || e < 0)
311
+ throw new Q("Expected a non-negative integer.");
312
+ return e;
313
+ }
314
+ async function J(t) {
315
+ const e = n.resolve(t);
316
+ await N(e) || (y("error", "@arcgis/codemod", `Failed to find the target path: ${t}`), process.exit(1));
317
+ const s = await K(e), o = (await U(s)).isFile();
318
+ return process.chdir(o ? n.dirname(s) : s), o ? s : void 0;
319
+ }
320
+ k.parse();
321
+ export {
322
+ xe as d,
323
+ v as g,
324
+ re as p,
325
+ ae as r
326
+ };
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
- import "./cli-BLMaWpqf.js";
1
+ import "./cli-C-HhqWfY.js";
2
2
  import "@arcgis/toolkit/log";
3
3
  import "@commander-js/extra-typings";
4
- import "node:fs";
4
+ import "node:fs/promises";
5
5
  import "@arcgis/node-toolkit/path";
6
+ import "@arcgis/node-toolkit/file";
6
7
  import "node:util";
@@ -30,7 +30,7 @@ var A = (t, e, n) => {
30
30
  return a();
31
31
  };
32
32
  import { SyntaxKind as d, Node as i } from "ts-morph";
33
- import { c as z } from "./useProjectInstance-Cs8LP18f.js";
33
+ import { c as z } from "./useProjectInstance-BqEY3afe.js";
34
34
  const P = /* @__PURE__ */ new Map([
35
35
  ["arcgis-survey123", "arcgis-survey-123"],
36
36
  ["arrow-double-diagonal1", "arrow-double-diagonal-1"],
@@ -29,11 +29,12 @@ var g = (i, o, a) => {
29
29
  };
30
30
  return r();
31
31
  };
32
- import { f as h, p as P } from "./actions-CQZGPkk1.js";
32
+ import { p as h } from "./actions-pyK_bLYZ.js";
33
33
  import { log as k } from "@arcgis/toolkit/log";
34
- import { writeFile as u } from "node:fs/promises";
35
- import { c as y } from "./useProjectInstance-Cs8LP18f.js";
36
- import { p as x, g as J } from "./cli-BLMaWpqf.js";
34
+ import { writeFile as P } from "node:fs/promises";
35
+ import { f as u } from "./log-B76HBvov.js";
36
+ import { c as y } from "./useProjectInstance-BqEY3afe.js";
37
+ import { p as x, g as J } from "./cli-C-HhqWfY.js";
37
38
  async function v(i, o) {
38
39
  const a = /* @__PURE__ */ new Set();
39
40
  for (const n of i) {
@@ -44,12 +45,12 @@ async function v(i, o) {
44
45
  const r = t.contents;
45
46
  try {
46
47
  const e = await o(r, t.filePath);
47
- r !== e && await u(t.filePath, `${JSON.stringify(e, null, 2)}
48
+ r !== e && await P(t.filePath, `${JSON.stringify(e, null, 2)}
48
49
  `, "utf8");
49
50
  } catch (e) {
50
51
  process.exitCode = 1, k(
51
52
  "error",
52
- h(t.filePath),
53
+ u(t.filePath),
53
54
  `Error occurred while migrating: ${String(e)}`,
54
55
  typeof e == "object" && e !== null && "stack" in e ? { detail: { stack: e.stack } } : void 0
55
56
  );
@@ -100,7 +101,7 @@ const d = "@arcgis/components-build-utils", S = {
100
101
  specifier: "@arcgis/node-toolkit/vite/externalizeDependenciesPlugin"
101
102
  }
102
103
  }
103
- }, C = {
104
+ }, E = {
104
105
  meta: {
105
106
  needsTypeInformation: !1
106
107
  },
@@ -121,7 +122,7 @@ const d = "@arcgis/components-build-utils", S = {
121
122
  try {
122
123
  const e = g(o, y(r));
123
124
  for (const s of e.getCodemodFiles())
124
- P(s, S);
125
+ h(s, S);
125
126
  } catch (a) {
126
127
  var n = a, t = !0;
127
128
  } finally {
@@ -136,5 +137,5 @@ const d = "@arcgis/components-build-utils", S = {
136
137
  }
137
138
  };
138
139
  export {
139
- C as codemod
140
+ E as codemod
140
141
  };
@@ -29,9 +29,9 @@ var d = (o, e, a) => {
29
29
  };
30
30
  return m();
31
31
  };
32
- import { p as y } from "./cli-BLMaWpqf.js";
33
- import { c as x } from "./useProjectInstance-Cs8LP18f.js";
34
- import { p as v } from "./actions-CQZGPkk1.js";
32
+ import { p as y } from "./cli-C-HhqWfY.js";
33
+ import { c as x } from "./useProjectInstance-BqEY3afe.js";
34
+ import { p as v } from "./actions-pyK_bLYZ.js";
35
35
  const l = {
36
36
  "@arcgis/core/geometry/operators/affineTransformOperator": {
37
37
  execute: { do: "rename", name: "affineTransformExecute" },
@@ -29,9 +29,9 @@ var g = (t, e, s) => {
29
29
  };
30
30
  return n();
31
31
  };
32
- import { p } from "./actions-CQZGPkk1.js";
33
- import { c as k } from "./useProjectInstance-Cs8LP18f.js";
34
- import { p as C } from "./cli-BLMaWpqf.js";
32
+ import { p } from "./actions-pyK_bLYZ.js";
33
+ import { c as k } from "./useProjectInstance-BqEY3afe.js";
34
+ import { p as C } from "./cli-C-HhqWfY.js";
35
35
  const j = {
36
36
  meta: {
37
37
  needsTypeInformation: !1
@@ -30,9 +30,9 @@ var D = (n, e, i) => {
30
30
  return s();
31
31
  };
32
32
  import { log as y } from "@arcgis/toolkit/log";
33
- import { c as V } from "./useProjectInstance-Cs8LP18f.js";
33
+ import { c as V } from "./useProjectInstance-BqEY3afe.js";
34
34
  import { mergeApiExtractorConfigs as O, loadApiExtractorConfig as _ } from "@arcgis/api-extractor/extractor/config";
35
- import { g as F } from "./cli-BLMaWpqf.js";
35
+ import { g as F } from "./cli-C-HhqWfY.js";
36
36
  import { writeFile as I, readFile as j } from "node:fs/promises";
37
37
  import { join as W, relative as Q } from "node:path";
38
38
  import { existsAsync as U } from "@arcgis/node-toolkit/file";