@arcgis/codemod 5.2.0-next.117 → 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.
package/README.md CHANGED
@@ -12,11 +12,11 @@ and updating geometry operator usage.
12
12
 
13
13
  - Node.js 24
14
14
  - A project using the ArcGIS Maps SDK for JavaScript
15
- - This codemod operates exclusively on TypeScript files. Do not need to run this tool, if the project does not use TypeScript.
15
+ - This codemod operates exclusively on TypeScript files. You do not need to run this tool if the project does not use TypeScript.
16
16
 
17
17
  ## Before you begin
18
18
 
19
- Ensure your project's dependencies are up to date, for example with `pnpm install`.
19
+ Ensure your project's dependencies are up to date, for example by running `pnpm install`.
20
20
 
21
21
  If your project uses **ESLint, Prettier, or other formatters/linters**, run them after the codemod to ensure consistent formatting.
22
22
 
@@ -74,7 +74,7 @@ The codemod will emit warnings for cases it cannot safely rewrite, including:
74
74
  - Complex computed or dynamic type usage
75
75
  - Unresolvable symbols
76
76
 
77
- These will be reported in the console, manually review all changes before committing.
77
+ These will be reported in the console. Manually review all changes before committing.
78
78
 
79
79
  ### Normalize Calcite icon names
80
80
 
@@ -104,9 +104,9 @@ npx @arcgis/codemod run normalize-calcite-icon-names [<target-directory>]
104
104
 
105
105
  ### Rename Geometry Operators
106
106
 
107
- At 5.2, geometry operator functions were renamed to improve consistency and discoverability.
107
+ In version 5.2, geometry operator exports and option types were renamed to improve consistency and discoverability.
108
108
  The `geometry-operator-renames` codemod updates geometry operator calls to use the new names.
109
- It additionally inlines namespace imports, which are now unnecessary.
109
+ It additionally inlines namespace imports, which are no longer necessary.
110
110
 
111
111
  Run it in the root of your project or with an explicit target directory:
112
112
 
@@ -116,7 +116,7 @@ npx @arcgis/codemod run geometry-operator-renames [<target-directory>]
116
116
 
117
117
  **Before:**
118
118
 
119
- ````ts
119
+ ```ts
120
120
  import * as bufferOperator from "@arcgis/core/geometry/operators/bufferOperator";
121
121
  const options: bufferOperator.Options = { unit: "meters" };
122
122
  const buffered = bufferOperator.execute(polyline, 250, options);
@@ -128,10 +128,34 @@ const buffered = bufferOperator.execute(polyline, 250, options);
128
128
  import { bufferExecute, type BufferExecuteOptions } from "@arcgis/core/geometry/operators/bufferOperator";
129
129
  const options: BufferExecuteOptions = { unit: "meters" };
130
130
  const buffered = bufferExecute(polyline, 250, options);
131
- ````
131
+ ```
132
+
133
+ ## Versioning
134
+
135
+ The codemods are available until the corresponding deprecated feature is removed.
136
+ If migrating from a much older release, the codemod might no longer be available in the most recent version of the `@arcgis/codemod` package.
137
+ In such cases, run the codemod from an older version, matching the version in the release notes:
138
+
139
+ ```sh
140
+ npx @arcgis/codemod@5.2 run refactor-out-esri-namespace
141
+ ```
142
+
143
+ ## Troubleshooting
144
+
145
+ Some codemods rely on type information to perform more accurate migrations.
146
+ On large codebases, this may require more RAM than the default Node.js limit.
147
+ If you encounter an out-of-memory error (like `Allocation failed - JavaScript heap out of memory`), re-run the codemod with a higher RAM limit:
148
+
149
+ Example on Linux/macOS:
150
+
151
+ ```sh
152
+ NODE_OPTIONS="--max-old-space-size=10240" npx @arcgis/codemod run normalize-calcite-icon-names
153
+ ```
154
+
155
+ [Windows command line](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1) and [PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.6) use a different environment variable syntax.
132
156
 
133
157
  ## License
134
158
 
135
159
  This package is licensed under the terms described in the `LICENSE.md` file,
136
160
  located in the root of the package, and at https://js.arcgis.com/5.2/LICENSE.txt.
137
- For third party notices, see https://js.arcgis.com/5.2/third-party-notices.txt.
161
+ For third-party notices, see https://js.arcgis.com/5.2/third-party-notices.txt.
@@ -1,36 +1,31 @@
1
- import { path as O } from "@arcgis/node-toolkit/path";
1
+ import { path as x } from "@arcgis/node-toolkit/path";
2
2
  import { SyntaxKind as I } from "ts-morph";
3
- import { g as D } from "./cli-BLMaWpqf.js";
4
- import { ModuleResolutionKind as P } from "typescript";
5
- import { capitalize as S } from "@arcgis/toolkit/string";
6
- import { log as j } from "@arcgis/toolkit/log";
7
- function K(t) {
8
- const e = t.typeScriptConfig?.compilerOptions?.moduleResolution ?? P.Bundler;
9
- return e >= P.Node16 && e <= P.NodeNext;
10
- }
11
- function A(t) {
12
- return q(t.getFilePath());
13
- }
14
- function q(t) {
15
- return O.relative(process.cwd(), t);
3
+ import { g as D } from "./cli-C-HhqWfY.js";
4
+ import { ModuleResolutionKind as K } from "typescript";
5
+ import { a as w } from "./log-B76HBvov.js";
6
+ import { capitalize as A } from "@arcgis/toolkit/string";
7
+ import { log as P } from "@arcgis/toolkit/log";
8
+ function j(t) {
9
+ const e = t.typeScriptConfig?.compilerOptions?.moduleResolution ?? K.Bundler;
10
+ return e >= K.Node16 && e <= K.NodeNext;
16
11
  }
17
12
  function V(t, e) {
18
13
  const s = {};
19
- b(t);
20
- const { specifiers: i, names: m, lastImportIndex: r } = C(t), l = [], n = {}, c = [];
21
- let p = K(D.project.projectData);
22
- for (const [o, d] of Object.entries(e)) {
14
+ q(t);
15
+ const { specifiers: i, names: m, lastImportIndex: r } = b(t), l = [], n = {}, c = [];
16
+ let p = j(D.project.projectData);
17
+ for (const [o, f] of Object.entries(e)) {
23
18
  let a = i.get(o) ?? (o.startsWith(".") ? i.get(
24
- O.relative(t.getDirectoryPath(), O.resolve(D.project.projectData.cwd, o))
19
+ x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, o))
25
20
  ) : void 0);
26
21
  if (a === void 0) {
27
22
  const y = i.get(`${o}.js`);
28
23
  y !== void 0 && (p = !0, a === void 0 ? a = y : a = [...a, ...y]);
29
24
  }
30
- for (const [y, g] of Object.entries(d)) {
25
+ for (const [y, g] of Object.entries(f)) {
31
26
  const v = Array.isArray(g) ? g : [g];
32
27
  for (const N of v)
33
- N.do === "deprecate" ? R(y, o, s, a) : N.do === "add" ? E(o, y, N, a, l, n, m) : N.do === "rename" ? W(o, y, N, a, l, n, m) : N.do === "remove-namespace-import" && $(
28
+ N.do === "deprecate" ? R(y, o, s, a) : N.do === "add" ? C(o, y, N, a, l, n, m) : N.do === "rename" ? E(o, y, N, a, l, n, m) : N.do === "remove-namespace-import" && W(
34
29
  o,
35
30
  a,
36
31
  l,
@@ -40,12 +35,12 @@ function V(t, e) {
40
35
  );
41
36
  }
42
37
  }
43
- const f = Object.entries(n);
38
+ const d = Object.entries(n);
44
39
  let u = r;
45
- for (let o = 0; o < f.length; o += 1) {
46
- const [d, a] = f[o], y = d.startsWith(".") ? U(
47
- O.relative(t.getDirectoryPath(), O.resolve(D.project.projectData.cwd, d))
48
- ) : d, g = p && y.startsWith("@arcgis/core") ? `${y}.js` : y, v = a.afterDeclaration === void 0 ? u : a.afterDeclaration.getChildIndex() + 1;
40
+ for (let o = 0; o < d.length; o += 1) {
41
+ const [f, a] = d[o], y = f.startsWith(".") ? M(
42
+ x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, f))
43
+ ) : f, g = p && y.startsWith("@arcgis/core") ? `${y}.js` : y, v = a.afterDeclaration === void 0 ? u : a.afterDeclaration.getChildIndex() + 1;
49
44
  if (a.named.length > 0) {
50
45
  let N = !0;
51
46
  for (let h = 0; h < a.named.length; h += 1)
@@ -71,18 +66,18 @@ function V(t, e) {
71
66
  }), u += 1);
72
67
  }
73
68
  if (Object.keys(s).length > 0) {
74
- const o = Object.entries(s).map(([d, a]) => `${a.join(", ")} from ${d}`).join("; ");
75
- j("warn", A(t), `Deprecated API usages found: ${o}`);
69
+ const o = Object.entries(s).map(([f, a]) => `${a.join(", ")} from ${f}`).join("; ");
70
+ P("warn", w(t), `Deprecated API usages found: ${o}`);
76
71
  }
77
72
  for (const o of c)
78
73
  o.remove();
79
74
  return l;
80
75
  }
81
- function b(t) {
76
+ function q(t) {
82
77
  const e = t.getChildSyntaxList()?.getFirstChild();
83
- if (w === e)
78
+ if (S === e)
84
79
  return;
85
- w = e, x.clear();
80
+ S = e, O.clear();
86
81
  const s = /* @__PURE__ */ new Set();
87
82
  i(t);
88
83
  function i(m) {
@@ -99,11 +94,11 @@ function b(t) {
99
94
  if (n.isKind(I.QualifiedName) && n.getLeft() !== l || n.isKind(I.PropertyAccessExpression) && n.getExpression() !== l || (n.isKind(I.PropertyDeclaration) || n.isKind(I.PropertySignature) || n.isKind(I.PropertyAssignment)) && n.getNameNode() === l)
100
95
  return;
101
96
  const c = l.getText();
102
- s.has(c) || x.add(l.getText());
97
+ s.has(c) || O.add(l.getText());
103
98
  });
104
99
  }
105
100
  }
106
- function C(t) {
101
+ function b(t) {
107
102
  const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), i = t.getStatements();
108
103
  let m;
109
104
  for (let l = 0; l < i.length; l += 1) {
@@ -116,21 +111,21 @@ function C(t) {
116
111
  m = n;
117
112
  const c = n.getModuleSpecifierValue(), p = e.get(c);
118
113
  p === void 0 ? e.set(c, [n]) : p.push(n);
119
- const f = n.getImportClause();
120
- if (f === void 0)
114
+ const d = n.getImportClause();
115
+ if (d === void 0)
121
116
  continue;
122
- const u = f.getDefaultImport()?.getText();
117
+ const u = d.getDefaultImport()?.getText();
123
118
  u !== void 0 && s.add(u);
124
- const o = f.getNamedBindings();
119
+ const o = d.getNamedBindings();
125
120
  if (o !== void 0)
126
121
  if (o.isKind(I.NamedImports))
127
- for (const d of o.getElements()) {
128
- const a = d.getName();
122
+ for (const f of o.getElements()) {
123
+ const a = f.getName();
129
124
  s.add(a);
130
125
  }
131
126
  else {
132
- const d = o.getName();
133
- s.add(d);
127
+ const f = o.getName();
128
+ s.add(f);
134
129
  }
135
130
  }
136
131
  const r = m === void 0 ? 0 : m.getChildIndex() + 1;
@@ -163,17 +158,17 @@ function R(t, e, s, i) {
163
158
  }
164
159
  }
165
160
  }
166
- function E(t, e, s, i, m, r, l) {
161
+ function C(t, e, s, i, m, r, l) {
167
162
  const n = e === "default";
168
163
  if (n || e === "*") {
169
164
  if (i !== void 0)
170
165
  for (const p of i) {
171
- const f = n ? p.getDefaultImport() : p.getNamespaceImport();
172
- if (f !== void 0) {
166
+ const d = n ? p.getDefaultImport() : p.getNamespaceImport();
167
+ if (d !== void 0) {
173
168
  s.isTypeOnly !== !0 && p.isTypeOnly() && p.setIsTypeOnly(!1), m.push({
174
169
  specifier: t,
175
170
  requestedName: e,
176
- actualName: f.getText()
171
+ actualName: d.getText()
177
172
  });
178
173
  return;
179
174
  }
@@ -192,18 +187,18 @@ function E(t, e, s, i, m, r, l) {
192
187
  let c, p;
193
188
  if (i !== void 0) {
194
189
  let o = !1;
195
- for (const d of i)
196
- if (d.getNamespaceImport() === void 0) {
197
- p ??= d, c ??= d.isTypeOnly() && d.getDefaultImport() === void 0 ? d : void 0;
198
- for (const a of d.getNamedImports())
190
+ for (const f of i)
191
+ if (f.getNamespaceImport() === void 0) {
192
+ p ??= f, c ??= f.isTypeOnly() && f.getDefaultImport() === void 0 ? f : void 0;
193
+ for (const a of f.getNamedImports())
199
194
  if (a.getNameNode().getText() === e) {
200
195
  if (o = !0, s.isTypeOnly !== !0) {
201
196
  if (a.isTypeOnly())
202
197
  a.setIsTypeOnly(!1);
203
- else if (d.isTypeOnly()) {
204
- for (const y of d.getNamedImports())
198
+ else if (f.isTypeOnly()) {
199
+ for (const y of f.getNamedImports())
205
200
  y !== a && y.setIsTypeOnly(!0);
206
- d.setIsTypeOnly(!1);
201
+ f.setIsTypeOnly(!1);
207
202
  }
208
203
  }
209
204
  m.push({
@@ -217,12 +212,12 @@ function E(t, e, s, i, m, r, l) {
217
212
  if (o)
218
213
  return;
219
214
  }
220
- const f = T(
215
+ const d = T(
221
216
  s.preferAlias === !0 ? s.preferredAlias : e,
222
217
  s.preferAlias === !0 ? e : s.preferredAlias,
223
218
  t,
224
219
  l
225
- ), u = e === f ? void 0 : f;
220
+ ), u = e === d ? void 0 : d;
226
221
  if (s.isTypeOnly && c !== void 0)
227
222
  c.addNamedImport({
228
223
  name: e,
@@ -250,37 +245,37 @@ function E(t, e, s, i, m, r, l) {
250
245
  alias: u,
251
246
  isTypeOnly: s.isTypeOnly === !0
252
247
  });
253
- m.push({ specifier: t, requestedName: e, actualName: f });
248
+ m.push({ specifier: t, requestedName: e, actualName: d });
254
249
  }
255
250
  }
256
- function W(t, e, s, i, m, r, l) {
251
+ function E(t, e, s, i, m, r, l) {
257
252
  if (i === void 0)
258
253
  return;
259
254
  const n = s.name ?? e, c = s.specifier ?? t, p = e === "default";
260
255
  if (p || e === "*") {
261
- for (const f of i) {
262
- const u = p ? f.getDefaultImport() : f.getNamespaceImport();
256
+ for (const d of i) {
257
+ const u = p ? d.getDefaultImport() : d.getNamespaceImport();
263
258
  if (u === void 0)
264
259
  continue;
265
- if (s.isTypeOnly === !1 && f.isTypeOnly()) {
266
- f.setIsTypeOnly(!1);
267
- for (const d of f.getNamedImports())
268
- d.setIsTypeOnly(!0);
260
+ if (s.isTypeOnly === !1 && d.isTypeOnly()) {
261
+ d.setIsTypeOnly(!1);
262
+ for (const f of d.getNamedImports())
263
+ f.setIsTypeOnly(!0);
269
264
  }
270
265
  let o = n;
271
266
  if (n !== e) {
272
- const d = T(n, e, t, l);
273
- n === d ? u.rename(n) : o = u.getText();
267
+ const f = T(n, e, t, l);
268
+ n === f ? u.rename(n) : o = u.getText();
274
269
  } else
275
270
  o = u.getText();
276
- t !== c && (f.getNamedImports().length === 0 ? f.setModuleSpecifier(c) : (p ? f.removeDefaultImport() : f.removeNamespaceImport(), r[c] ??= {
271
+ t !== c && (d.getNamedImports().length === 0 ? d.setModuleSpecifier(c) : (p ? d.removeDefaultImport() : d.removeNamespaceImport(), r[c] ??= {
277
272
  afterDeclaration: void 0,
278
273
  named: [],
279
274
  default: void 0,
280
275
  "*": void 0
281
- }, r[c].afterDeclaration ??= f, r[c][e] = {
276
+ }, r[c].afterDeclaration ??= d, r[c][e] = {
282
277
  name: o,
283
- isTypeOnly: f.isTypeOnly()
278
+ isTypeOnly: d.isTypeOnly()
284
279
  })), m.push({
285
280
  specifier: c,
286
281
  requestedName: e,
@@ -290,46 +285,46 @@ function W(t, e, s, i, m, r, l) {
290
285
  }
291
286
  return;
292
287
  }
293
- for (const f of i) {
294
- for (const o of f.getNamedImports()) {
288
+ for (const d of i) {
289
+ for (const o of d.getNamedImports()) {
295
290
  if (o.getNameNode().getText() !== e)
296
291
  continue;
297
292
  if (s.isTypeOnly === !1) {
298
293
  if (o.isTypeOnly())
299
294
  o.setIsTypeOnly(!1);
300
- else if (f.isTypeOnly()) {
301
- f.setIsTypeOnly(!1);
302
- for (const y of f.getNamedImports())
295
+ else if (d.isTypeOnly()) {
296
+ d.setIsTypeOnly(!1);
297
+ for (const y of d.getNamedImports())
303
298
  y !== o && y.setIsTypeOnly(!0);
304
299
  }
305
300
  }
306
- let d = n;
301
+ let f = n;
307
302
  const a = o.getAliasNode();
308
303
  if (n !== e)
309
304
  if (a === void 0) {
310
305
  const y = T(n, e, t, l);
311
- n === y ? o.getNameNode().asKind(I.Identifier)?.rename(n) : (o.setAlias(e), o.getNameNode().replaceWithText(n), d = e);
306
+ n === y ? o.getNameNode().asKind(I.Identifier)?.rename(n) : (o.setAlias(e), o.getNameNode().replaceWithText(n), f = e);
312
307
  } else
313
- o.getNameNode().replaceWithText(n), d = a.getText();
308
+ o.getNameNode().replaceWithText(n), f = a.getText();
314
309
  if (c !== t) {
315
- const g = (K(D.project.projectData) || f.getModuleSpecifierValue().endsWith(".js")) && c.startsWith("@arcgis/core") ? `${c}.js` : c;
316
- f.getNamedImports().length === 1 && f.getDefaultImport() === void 0 ? f.setModuleSpecifier(g) : (r[g] ??= { named: [] }, r[g].afterDeclaration ??= i?.[0], r[g].named.push({
310
+ const g = (j(D.project.projectData) || d.getModuleSpecifierValue().endsWith(".js")) && c.startsWith("@arcgis/core") ? `${c}.js` : c;
311
+ d.getNamedImports().length === 1 && d.getDefaultImport() === void 0 ? d.setModuleSpecifier(g) : (r[g] ??= { named: [] }, r[g].afterDeclaration ??= i?.[0], r[g].named.push({
317
312
  name: n,
318
- alias: n === d ? void 0 : d,
313
+ alias: n === f ? void 0 : f,
319
314
  isTypeOnly: o.isTypeOnly()
320
315
  }), o.remove());
321
316
  }
322
317
  m.push({
323
318
  specifier: c,
324
319
  requestedName: n,
325
- actualName: a?.getText() ?? d
320
+ actualName: a?.getText() ?? f
326
321
  });
327
322
  return;
328
323
  }
329
- const u = f.getNamespaceImport();
324
+ const u = d.getNamespaceImport();
330
325
  if (u)
331
326
  for (const o of u.findReferencesAsNodes().slice(1)) {
332
- const d = o.getParentIfKind(I.PropertyAccessExpression), a = o.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), y = d ?? a;
327
+ const f = o.getParentIfKind(I.PropertyAccessExpression), a = o.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), y = f ?? a;
333
328
  if (!y)
334
329
  continue;
335
330
  const g = y.getText();
@@ -337,7 +332,7 @@ function W(t, e, s, i, m, r, l) {
337
332
  }
338
333
  }
339
334
  }
340
- function $(t, e, s, i, m, r) {
335
+ function W(t, e, s, i, m, r) {
341
336
  if (e = e?.filter((u) => u.getNamespaceImport() != null), e === void 0 || e.length === 0)
342
337
  return;
343
338
  if (e.length !== 1)
@@ -346,21 +341,21 @@ function $(t, e, s, i, m, r) {
346
341
  );
347
342
  const [l] = e, n = l.getNamespaceImport(), c = {}, p = /* @__PURE__ */ new Set();
348
343
  for (const u of n.findReferencesAsNodes()) {
349
- const o = u.getParentIfKind(I.PropertyAccessExpression), d = u.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), a = o ?? d;
344
+ const o = u.getParentIfKind(I.PropertyAccessExpression), f = u.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), a = o ?? f;
350
345
  if (!a)
351
346
  continue;
352
347
  const y = a.getText().split(".").pop().trim();
353
348
  c[y] ??= T(y, void 0, t, r);
354
349
  const g = c[y];
355
- a.replaceWithText(g), d || p.add(g);
350
+ a.replaceWithText(g), f || p.add(g);
356
351
  }
357
352
  i[t] ??= {
358
353
  afterDeclaration: l,
359
354
  named: []
360
355
  };
361
- const { named: f } = i[t];
356
+ const { named: d } = i[t];
362
357
  for (const [u, o] of Object.entries(c))
363
- f.push({
358
+ d.push({
364
359
  name: u,
365
360
  alias: o === u ? void 0 : o,
366
361
  isTypeOnly: !p.has(o)
@@ -373,7 +368,7 @@ function $(t, e, s, i, m, r) {
373
368
  }
374
369
  function T(t, e, s, i) {
375
370
  if (t !== void 0) {
376
- if (!i.has(t) && !x.has(t))
371
+ if (!i.has(t) && !O.has(t))
377
372
  return i.add(t), t;
378
373
  if (e !== void 0)
379
374
  return T(e, void 0, s, i);
@@ -382,21 +377,19 @@ function T(t, e, s, i) {
382
377
  const m = s.split("/");
383
378
  let r = t ?? "";
384
379
  for (let l = m.length - 1; l >= 0; l--) {
385
- const n = m[l].replaceAll(M, "");
386
- if (n !== r && (r = n + S(r), !i.has(r) && !x.has(r)))
380
+ const n = m[l].replaceAll($, "");
381
+ if (n !== r && (r = n + A(r), !i.has(r) && !O.has(r)))
387
382
  return i.add(r), r;
388
383
  }
389
384
  for (let l = 2; ; l++) {
390
385
  const n = r + l;
391
- if (!i.has(n) && !x.has(n))
386
+ if (!i.has(n) && !O.has(n))
392
387
  return i.add(n), n;
393
388
  }
394
389
  }
395
- const M = /[^a-zA-Z0-9$_]/gu, U = (t) => t.startsWith(".") ? t : `./${t}`, x = /* @__PURE__ */ new Set();
396
- let w;
390
+ const $ = /[^a-zA-Z0-9$_]/gu, M = (t) => t.startsWith(".") ? t : `./${t}`, O = /* @__PURE__ */ new Set();
391
+ let S;
397
392
  export {
398
- A as a,
399
- q as f,
400
393
  V as p,
401
- b as u
394
+ q as u
402
395
  };