@arcgis/codemod 5.2.0-next.5 → 5.2.0-next.50

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,354 @@
1
+ import { path as T } from "@arcgis/node-toolkit/path";
2
+ import { SyntaxKind as g } from "ts-morph";
3
+ import { g as x } from "./cli-CpDkU0N0.js";
4
+ import { ModuleResolutionKind as D } from "typescript";
5
+ import { capitalize as S } from "@arcgis/toolkit/string";
6
+ import { log as q } from "@arcgis/toolkit/log";
7
+ function w(e) {
8
+ const n = e.typeScriptConfig?.compilerOptions?.moduleResolution ?? D.Bundler;
9
+ return n >= D.Node16 && n <= D.NodeNext;
10
+ }
11
+ function b(e) {
12
+ return C(e.getFilePath());
13
+ }
14
+ function C(e) {
15
+ return T.relative(process.cwd(), e);
16
+ }
17
+ function J(e, n) {
18
+ const o = {};
19
+ K(e);
20
+ const { specifiers: l, names: u, lastImportIndex: a } = A(e), d = [], t = {};
21
+ let c = w(x.project.projectData);
22
+ for (const [i, m] of Object.entries(n)) {
23
+ let s = l.get(i) ?? (i.startsWith(".") ? l.get(
24
+ T.relative(e.getDirectoryPath(), T.resolve(x.project.projectData.cwd, i))
25
+ ) : void 0);
26
+ if (s === void 0) {
27
+ const f = l.get(`${i}.js`);
28
+ f !== void 0 && (c = !0, s === void 0 ? s = f : s = [...s, ...f]);
29
+ }
30
+ for (const [f, y] of Object.entries(m)) {
31
+ const N = Array.isArray(y) ? y : [y];
32
+ for (const I of N)
33
+ I.do === "deprecate" ? P(f, i, o, s) : I.do === "add" ? E(i, f, I, s, d, t, u) : I.do === "rename" && W(i, f, I, s, d, t, u);
34
+ }
35
+ }
36
+ const p = Object.entries(t);
37
+ let r = a;
38
+ for (let i = 0; i < p.length; i += 1) {
39
+ const [m, s] = p[i], f = m.startsWith(".") ? M(
40
+ T.relative(e.getDirectoryPath(), T.resolve(x.project.projectData.cwd, m))
41
+ ) : m, y = c && f.startsWith("@arcgis/core") ? `${f}.js` : f, N = s.afterDeclaration === void 0 ? r : s.afterDeclaration.getChildIndex() + 1;
42
+ if (s.named.length > 0) {
43
+ let I = !0;
44
+ for (let v = 0; v < s.named.length; v += 1)
45
+ I &&= s.named[v].isTypeOnly;
46
+ e.insertImportDeclaration(N, {
47
+ isTypeOnly: I,
48
+ moduleSpecifier: y,
49
+ namedImports: s.named.map((v) => ({
50
+ name: v.name,
51
+ alias: v.alias,
52
+ isTypeOnly: v.isTypeOnly && !I
53
+ }))
54
+ }), r += 1;
55
+ }
56
+ s.default !== void 0 && (e.insertImportDeclaration(N, {
57
+ isTypeOnly: s.default.isTypeOnly,
58
+ moduleSpecifier: y,
59
+ defaultImport: s.default.name
60
+ }), r += 1), s["*"] !== void 0 && (e.insertImportDeclaration(N, {
61
+ isTypeOnly: s["*"].isTypeOnly,
62
+ moduleSpecifier: y,
63
+ namespaceImport: s["*"].name
64
+ }), r += 1);
65
+ }
66
+ if (Object.keys(o).length > 0) {
67
+ const i = Object.entries(o).map(([m, s]) => `${s.join(", ")} from ${m}`).join("; ");
68
+ q("warn", b(e), `Deprecated API usages found: ${i}`);
69
+ }
70
+ return d;
71
+ }
72
+ function K(e) {
73
+ const n = e.getChildSyntaxList()?.getFirstChild();
74
+ if (j === n)
75
+ return;
76
+ j = n, h.clear();
77
+ const o = /* @__PURE__ */ new Set();
78
+ l(e);
79
+ function l(u) {
80
+ for (const a of u.getStatements())
81
+ if (a.isKind(g.ImportDeclaration)) {
82
+ const d = a.getDefaultImport(), t = a.getNamespaceImport(), c = a.getNamedImports();
83
+ d && o.add(d.getText()), t && o.add(t.getText());
84
+ for (const p of c)
85
+ o.add(p.getAliasNode()?.getText() ?? p.getName());
86
+ } else a.isKind(g.ImportEqualsDeclaration) ? o.add(a.getName()) : a.isKind(g.ModuleDeclaration) ? l(a) : u.forEachDescendant((d) => {
87
+ if (!d.isKind(g.Identifier))
88
+ return;
89
+ const t = d.getParent();
90
+ if (t.isKind(g.QualifiedName) && t.getLeft() !== d || t.isKind(g.PropertyAccessExpression) && t.getExpression() !== d || (t.isKind(g.PropertyDeclaration) || t.isKind(g.PropertySignature) || t.isKind(g.PropertyAssignment)) && t.getNameNode() === d)
91
+ return;
92
+ const c = d.getText();
93
+ o.has(c) || h.add(d.getText());
94
+ });
95
+ }
96
+ }
97
+ function A(e) {
98
+ const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), l = e.getStatements();
99
+ let u;
100
+ for (let d = 0; d < l.length; d += 1) {
101
+ const t = l[d];
102
+ if (!t.isKind(g.ImportDeclaration)) {
103
+ const f = t.getName?.();
104
+ f !== void 0 && o.add(f);
105
+ continue;
106
+ }
107
+ u = t;
108
+ const c = t.getModuleSpecifierValue(), p = n.get(c);
109
+ p === void 0 ? n.set(c, [t]) : p.push(t);
110
+ const r = t.getImportClause();
111
+ if (r === void 0)
112
+ continue;
113
+ const i = r.getDefaultImport()?.getText();
114
+ i !== void 0 && o.add(i);
115
+ const m = r.getNamedBindings();
116
+ if (m !== void 0)
117
+ if (m.isKind(g.NamedImports))
118
+ for (const s of m.getElements()) {
119
+ const f = s.getName();
120
+ o.add(f);
121
+ }
122
+ else {
123
+ const s = m.getName();
124
+ o.add(s);
125
+ }
126
+ }
127
+ const a = u === void 0 ? 0 : u.getChildIndex() + 1;
128
+ return { specifiers: n, names: o, lastImportIndex: a };
129
+ }
130
+ function P(e, n, o, l) {
131
+ if (l !== void 0) {
132
+ if (e === "default")
133
+ for (const u of l) {
134
+ const a = u.getDefaultImport();
135
+ if (a !== void 0) {
136
+ o[n] ??= [], o[n].push(a.getText());
137
+ return;
138
+ }
139
+ }
140
+ else if (e === "*")
141
+ for (const u of l) {
142
+ const a = u.getNamespaceImport();
143
+ if (a !== void 0) {
144
+ o[n] ??= [], o[n].push(a.getText());
145
+ return;
146
+ }
147
+ }
148
+ else
149
+ for (const u of l)
150
+ for (const a of u.getNamedImports())
151
+ if (a.getName() === e) {
152
+ o[n] ??= [], o[n].push(a.getName());
153
+ return;
154
+ }
155
+ }
156
+ }
157
+ function E(e, n, o, l, u, a, d) {
158
+ const t = n === "default";
159
+ if (t || n === "*") {
160
+ if (l !== void 0)
161
+ for (const p of l) {
162
+ const r = t ? p.getDefaultImport() : p.getNamespaceImport();
163
+ if (r !== void 0) {
164
+ o.isTypeOnly !== !0 && p.isTypeOnly() && p.setIsTypeOnly(!1), u.push({
165
+ specifier: e,
166
+ requestedName: n,
167
+ actualName: r.getText()
168
+ });
169
+ return;
170
+ }
171
+ }
172
+ const c = O(o.preferredAlias, void 0, e, d);
173
+ u.push({ specifier: e, requestedName: n, actualName: c }), a[e] ??= {
174
+ afterDeclaration: void 0,
175
+ named: [],
176
+ default: void 0,
177
+ "*": void 0
178
+ }, a[e].afterDeclaration ??= l?.[0], a[e][n] = {
179
+ name: c,
180
+ isTypeOnly: o.isTypeOnly === !0
181
+ };
182
+ } else {
183
+ let c, p;
184
+ if (l !== void 0) {
185
+ let m = !1;
186
+ for (const s of l)
187
+ if (s.getNamespaceImport() === void 0) {
188
+ p ??= s, c ??= s.isTypeOnly() && s.getDefaultImport() === void 0 ? s : void 0;
189
+ for (const f of s.getNamedImports())
190
+ if (f.getNameNode().getText() === n) {
191
+ if (m = !0, o.isTypeOnly !== !0) {
192
+ if (f.isTypeOnly())
193
+ f.setIsTypeOnly(!1);
194
+ else if (s.isTypeOnly()) {
195
+ for (const y of s.getNamedImports())
196
+ y !== f && y.setIsTypeOnly(!0);
197
+ s.setIsTypeOnly(!1);
198
+ }
199
+ }
200
+ u.push({
201
+ specifier: e,
202
+ requestedName: n,
203
+ actualName: f.getAliasNode()?.getText() ?? n
204
+ });
205
+ break;
206
+ }
207
+ }
208
+ if (m)
209
+ return;
210
+ }
211
+ const r = O(
212
+ o.preferAlias === !0 ? o.preferredAlias : n,
213
+ o.preferAlias === !0 ? n : o.preferredAlias,
214
+ e,
215
+ d
216
+ ), i = n === r ? void 0 : r;
217
+ if (o.isTypeOnly && c !== void 0)
218
+ c.addNamedImport({
219
+ name: n,
220
+ alias: i
221
+ });
222
+ else if (p !== void 0 && (!o.isTypeOnly || p.getDefaultImport() === void 0)) {
223
+ if (p.isTypeOnly() && !o.isTypeOnly) {
224
+ p.setIsTypeOnly(!1);
225
+ for (const m of p.getNamedImports())
226
+ m.setIsTypeOnly(!0);
227
+ }
228
+ p.addNamedImport({
229
+ name: n,
230
+ alias: i,
231
+ isTypeOnly: o.isTypeOnly && !p.isTypeOnly()
232
+ });
233
+ } else
234
+ a[e] ??= {
235
+ afterDeclaration: void 0,
236
+ named: [],
237
+ default: void 0,
238
+ "*": void 0
239
+ }, a[e].afterDeclaration ??= l?.[0], a[e].named.push({
240
+ name: n,
241
+ alias: i,
242
+ isTypeOnly: o.isTypeOnly === !0
243
+ });
244
+ u.push({ specifier: e, requestedName: n, actualName: r });
245
+ }
246
+ }
247
+ function W(e, n, o, l, u, a, d) {
248
+ if (l === void 0)
249
+ return;
250
+ const t = o.name ?? n, c = o.specifier ?? e, p = n === "default";
251
+ if (p || n === "*") {
252
+ for (const r of l) {
253
+ const i = p ? r.getDefaultImport() : r.getNamespaceImport();
254
+ if (i === void 0)
255
+ continue;
256
+ if (o.isTypeOnly === !1 && r.isTypeOnly()) {
257
+ r.setIsTypeOnly(!1);
258
+ for (const s of r.getNamedImports())
259
+ s.setIsTypeOnly(!0);
260
+ }
261
+ let m = t;
262
+ if (t !== n) {
263
+ const s = O(t, n, e, d);
264
+ t === s ? i.rename(t) : m = i.getText();
265
+ } else
266
+ m = i.getText();
267
+ e !== c && (r.getNamedImports().length === 0 ? r.setModuleSpecifier(c) : (p ? r.removeDefaultImport() : r.removeNamespaceImport(), a[c] ??= {
268
+ afterDeclaration: void 0,
269
+ named: [],
270
+ default: void 0,
271
+ "*": void 0
272
+ }, a[c].afterDeclaration ??= r, a[c][n] = {
273
+ name: m,
274
+ isTypeOnly: r.isTypeOnly()
275
+ })), u.push({
276
+ specifier: c,
277
+ requestedName: n,
278
+ actualName: m
279
+ });
280
+ break;
281
+ }
282
+ return;
283
+ }
284
+ for (const r of l)
285
+ for (const i of r.getNamedImports()) {
286
+ if (i.getNameNode().getText() !== n)
287
+ continue;
288
+ if (o.isTypeOnly === !1) {
289
+ if (i.isTypeOnly())
290
+ i.setIsTypeOnly(!1);
291
+ else if (r.isTypeOnly()) {
292
+ r.setIsTypeOnly(!1);
293
+ for (const f of r.getNamedImports())
294
+ f !== i && f.setIsTypeOnly(!0);
295
+ }
296
+ }
297
+ let m = t;
298
+ const s = i.getAliasNode();
299
+ if (t !== n)
300
+ if (s === void 0) {
301
+ const f = O(t, n, e, d);
302
+ t === f ? i.getNameNode().asKind(g.Identifier)?.rename(t) : (i.setAlias(n), i.getNameNode().replaceWithText(t), m = n);
303
+ } else
304
+ i.getNameNode().replaceWithText(t), m = s.getText();
305
+ if (c !== e) {
306
+ const y = (w(x.project.projectData) || r.getModuleSpecifierValue().endsWith(".js")) && c.startsWith("@arcgis/core") ? `${c}.js` : c;
307
+ r.getNamedImports().length === 1 && r.getDefaultImport() === void 0 ? r.setModuleSpecifier(y) : (a[y] ??= {
308
+ afterDeclaration: void 0,
309
+ named: [],
310
+ default: void 0,
311
+ "*": void 0
312
+ }, a[y].afterDeclaration ??= l?.[0], a[y].named.push({
313
+ name: t,
314
+ alias: t === m ? void 0 : m,
315
+ isTypeOnly: i.isTypeOnly()
316
+ }), i.remove());
317
+ }
318
+ u.push({
319
+ specifier: c,
320
+ requestedName: t,
321
+ actualName: s?.getText() ?? m
322
+ });
323
+ return;
324
+ }
325
+ }
326
+ function O(e, n, o, l) {
327
+ if (e !== void 0) {
328
+ if (!l.has(e) && !h.has(e))
329
+ return l.add(e), e;
330
+ if (n !== void 0)
331
+ return O(n, void 0, o, l);
332
+ }
333
+ o.startsWith("@arcgis/core") && (o = `arcgisCore${o.slice(12)}`);
334
+ const u = o.split("/");
335
+ let a = e ?? "";
336
+ for (let d = u.length - 1; d >= 0; d--) {
337
+ const t = u[d].replaceAll($, "");
338
+ if (t !== a && (a = t + S(a), !l.has(a) && !h.has(a)))
339
+ return l.add(a), a;
340
+ }
341
+ for (let d = 2; ; d++) {
342
+ const t = a + d;
343
+ if (!l.has(t) && !h.has(t))
344
+ return l.add(t), t;
345
+ }
346
+ }
347
+ const $ = /[^a-zA-Z0-9$_]/gu, M = (e) => e.startsWith(".") ? e : `./${e}`, h = /* @__PURE__ */ new Set();
348
+ let j;
349
+ export {
350
+ b as a,
351
+ C as f,
352
+ J as p,
353
+ K as u
354
+ };
@@ -1,18 +1,21 @@
1
1
  import { log as h } from "@arcgis/toolkit/log";
2
- import { Command as $ } from "@commander-js/extra-typings";
3
- import { statSync as K } from "node:fs";
4
- import { getCwd as I, path as e, existsAsync as U, gitIgnoreFileToGlobs as L, asyncFindPath as E, toPosixPathSeparators as N, asyncRetrievePackageJson as J } from "@arcgis/components-build-utils";
2
+ import { Command as K } from "@commander-js/extra-typings";
3
+ import { statSync as U } from "node:fs";
4
+ import { getCwd as F, path as e, toPosixPathSeparators as J } from "@arcgis/node-toolkit/path";
5
5
  import "ts-morph";
6
- import i from "typescript";
7
- import { glob as _ } from "tinyglobby";
8
- import { identity as W } from "@arcgis/toolkit/function";
9
- import { styleText as B } from "node:util";
6
+ import a from "typescript";
7
+ import { existsAsync as B, asyncFindPath as W } from "@arcgis/node-toolkit/file";
8
+ import { asyncRetrievePackageJson as M } from "@arcgis/node-toolkit/packageJson";
9
+ import { glob as T } from "tinyglobby";
10
+ import { gitIgnoreFileToGlobs as $ } from "@arcgis/node-toolkit/glob";
11
+ import { identity as L } from "@arcgis/toolkit/function";
12
+ import { styleText as S } from "node:util";
10
13
  const q = (t, o, n) => {
11
14
  const r = t[o];
12
- return r ? typeof r == "function" ? r() : Promise.resolve(r) : new Promise((a, c) => {
13
- (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(c.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + o + (o.split("/").length !== n ? ". Note that variables only represent file names one level deep." : ""))));
15
+ return r ? typeof r == "function" ? r() : Promise.resolve(r) : new Promise((c, i) => {
16
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(i.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + o + (o.split("/").length !== n ? ". Note that variables only represent file names one level deep." : ""))));
14
17
  });
15
- }, ge = {
18
+ }, ye = {
16
19
  allowImportingTsExtensions: !0,
17
20
  allowJs: !0,
18
21
  allowArbitraryExtensions: !0,
@@ -22,13 +25,13 @@ const q = (t, o, n) => {
22
25
  forceConsistentCasingInFileNames: !1,
23
26
  isolatedModules: !1,
24
27
  isolatedDeclarations: !1,
25
- jsx: i.JsxEmit.Preserve,
28
+ jsx: a.JsxEmit.Preserve,
26
29
  lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
27
- module: i.ModuleKind.ESNext,
28
- moduleResolution: i.ModuleResolutionKind.Bundler,
29
- moduleDetection: i.ModuleDetectionKind.Auto,
30
+ module: a.ModuleKind.ESNext,
31
+ moduleResolution: a.ModuleResolutionKind.Bundler,
32
+ moduleDetection: a.ModuleDetectionKind.Auto,
30
33
  strict: !1,
31
- target: i.ScriptTarget.ESNext,
34
+ target: a.ScriptTarget.ESNext,
32
35
  resolveJsonModule: !0,
33
36
  esModuleInterop: !0
34
37
  }, j = {
@@ -43,13 +46,13 @@ async function z() {
43
46
  }
44
47
  async function H() {
45
48
  const t = [];
46
- let o, n = I(), r = e.dirname(n);
49
+ let o, n = F(), r = e.dirname(n);
47
50
  do {
48
51
  o = r;
49
- const a = e.join(o, ".gitignore");
50
- if (await U(a)) {
51
- n = e.dirname(a);
52
- const w = e.relative(n, I()).split("/"), y = L(a);
52
+ const c = e.join(o, ".gitignore");
53
+ if (await B(c)) {
54
+ n = e.dirname(c);
55
+ const w = e.relative(n, F()).split("/"), y = $(c);
53
56
  for (const f of y) {
54
57
  const m = (f.startsWith("!") ? f.slice(1) : f).split("*")[0].split("/");
55
58
  let p = !0;
@@ -66,7 +69,8 @@ async function H() {
66
69
  return { ignorePatterns: t, globRoot: n };
67
70
  }
68
71
  async function Q(t) {
69
- return (await _("**/.gitignore", {
72
+ return (await T("**/.gitignore", {
73
+ cwd: F(),
70
74
  // Gitignore files are unlikely to be symbolic links
71
75
  followSymbolicLinks: !1,
72
76
  // Don't look for ignore files in these places for speed:
@@ -81,15 +85,15 @@ async function Q(t) {
81
85
  // Not applicable for our glob pattern
82
86
  expandDirectories: !1
83
87
  })).flatMap((n) => {
84
- const r = e.relative(t, e.dirname(n)), a = L(n), c = [];
85
- for (const w of a)
86
- w.startsWith("!") || c.push(e.join(r, w));
87
- return c;
88
+ const r = e.relative(t, e.dirname(n)), c = $(n), i = [];
89
+ for (const w of c)
90
+ w.startsWith("!") || i.push(e.join(r, w));
91
+ return i;
88
92
  });
89
93
  }
90
94
  const V = ["js", "jsx", "mjs", "cjs"], X = ["ts", "tsx", "mts", "cts"], Y = ["json"], Z = `**/*.{${[...V, ...X, ...Y].join(",")}}`;
91
95
  async function ee() {
92
- const t = await z(), o = e.join(process.cwd(), Z), n = await _(o, {
96
+ const t = await z(), o = e.join(process.cwd(), Z), n = await T(o, {
93
97
  cwd: t.globRoot,
94
98
  ignore: t.ignorePatterns,
95
99
  // The files we are looking for are unlikely to be symbolic links
@@ -102,9 +106,9 @@ async function ee() {
102
106
  });
103
107
  let r = e.relative(t.globRoot, process.cwd());
104
108
  r !== "" && (r += "/");
105
- const a = e.join(e.resolve(t.globRoot), "/"), c = a.length + r.length, w = [], y = [], f = /* @__PURE__ */ new Set();
109
+ const c = e.join(e.resolve(t.globRoot), "/"), i = c.length + r.length, w = [], y = [], f = /* @__PURE__ */ new Set();
106
110
  for (const s of n) {
107
- const l = a + s;
111
+ const l = c + s;
108
112
  if (s.endsWith(".json")) {
109
113
  const d = e.basename(s);
110
114
  d === "package.json" ? w.push(l) : (d.startsWith("tsconfig.") || d.startsWith("jsconfig.")) && y.push(l);
@@ -113,57 +117,57 @@ async function ee() {
113
117
  f.add(d);
114
118
  }
115
119
  }
116
- let v = await E("tsconfig.json", e.dirname(process.cwd()));
117
- v !== void 0 && (v = N(v), y.push(v)), y.sort((s, l) => {
120
+ let v = await W("tsconfig.json", e.dirname(process.cwd()));
121
+ v !== void 0 && (v = J(v), y.push(v)), y.sort((s, l) => {
118
122
  const d = l.split("/").length - s.split("/").length;
119
123
  if (d !== 0)
120
124
  return d;
121
125
  const b = e.basename(s), u = e.basename(l);
122
126
  return b === u ? 0 : b.endsWith("tsconfig.json") ? -1 : u.endsWith("tsconfig.json") ? 1 : b.endsWith("tsconfig.build.json") ? -1 : u.endsWith("tsconfig.build.json") ? 1 : b.localeCompare(u);
123
127
  });
124
- let m = await E("package.json");
125
- m !== void 0 && (m = N(m));
128
+ let m = await W("package.json");
129
+ m !== void 0 && (m = J(m));
126
130
  const p = [], g = /* @__PURE__ */ new Set();
127
- return await Promise.all(
131
+ if (await Promise.all(
128
132
  y.map(async (s) => {
129
- const l = e.relative(process.cwd(), s), d = i.readConfigFile(s, i.sys.readFile);
133
+ const l = e.relative(process.cwd(), s), d = a.readConfigFile(s, a.sys.readFile);
130
134
  if (d.error !== void 0) {
131
135
  h(
132
136
  "error",
133
137
  l,
134
- i.formatDiagnosticsWithColorAndContext([d.error], {
135
- getCanonicalFileName: W,
136
- getCurrentDirectory: i.sys.getCurrentDirectory,
137
- getNewLine: () => i.sys.newLine
138
+ a.formatDiagnosticsWithColorAndContext([d.error], {
139
+ getCanonicalFileName: L,
140
+ getCurrentDirectory: a.sys.getCurrentDirectory,
141
+ getNewLine: () => a.sys.newLine
138
142
  })
139
143
  );
140
144
  return;
141
145
  }
142
- const b = e.basename(l), u = i.parseJsonConfigFileContent(
146
+ const b = e.basename(l), u = a.parseJsonConfigFileContent(
143
147
  d.config,
144
- i.sys,
148
+ a.sys,
145
149
  e.dirname(s),
146
150
  void 0,
147
151
  b
148
- ), T = 18003;
149
- u.errors.filter((P) => P.code !== T).length > 0 && h(
152
+ ), A = 18003;
153
+ u.errors.filter((P) => P.code !== A).length > 0 && h(
150
154
  "warn",
151
155
  l,
152
- i.formatDiagnosticsWithColorAndContext(u.errors, {
153
- getCanonicalFileName: W,
154
- getCurrentDirectory: i.sys.getCurrentDirectory,
155
- getNewLine: () => i.sys.newLine
156
+ a.formatDiagnosticsWithColorAndContext(u.errors, {
157
+ getCanonicalFileName: L,
158
+ getCurrentDirectory: a.sys.getCurrentDirectory,
159
+ getNewLine: () => a.sys.newLine
156
160
  })
157
161
  );
158
- const F = s === v, A = l === b, k = u.fileNames.filter((P) => {
159
- const D = P.slice(c);
160
- return f.delete(D) ? (g.add(D), !0) : g.has(D) || D.endsWith(".json") || P.includes("node_modules") ? !1 : !F;
162
+ const I = s === v, G = l === b, N = u.fileNames.filter((P) => {
163
+ const D = P.slice(i);
164
+ return f.delete(D) ? (g.add(D), !0) : g.has(D) || D.endsWith(".json") || P.includes("node_modules") ? !1 : !I;
161
165
  });
162
- if (k.length === 0)
166
+ if (N.length === 0)
163
167
  return;
164
- y.length === 1 && (F || A) && f.clear();
165
- const R = e.dirname(s);
166
- let C = R, x = m;
168
+ y.length === 1 && (I || G) && f.clear();
169
+ const k = e.dirname(s);
170
+ let C = k, x = m;
167
171
  do {
168
172
  const P = e.join(C, "package.json");
169
173
  if (w.includes(P)) {
@@ -171,37 +175,43 @@ async function ee() {
171
175
  break;
172
176
  }
173
177
  } while (C !== t.globRoot && (C = e.dirname(C)));
174
- const G = x === void 0 ? void 0 : { filePath: x, contents: await J(e.dirname(x)) }, O = {
178
+ const E = x === void 0 ? void 0 : { filePath: x, contents: await M(e.dirname(x)) }, O = {
175
179
  typeScriptConfig: {
176
180
  filePath: s,
177
181
  compilerOptions: u.options
178
182
  },
179
- packageJson: G,
180
- cwd: R,
181
- filePaths: k
183
+ packageJson: E,
184
+ logName: S("blue", E?.contents?.name ?? k),
185
+ cwd: k,
186
+ filePaths: N
182
187
  };
183
188
  p.push(O);
184
189
  })
185
- ), f.size > 0 && p.push({
186
- typeScriptConfig: void 0,
187
- packageJson: m === void 0 ? void 0 : {
190
+ ), f.size > 0) {
191
+ const s = m === void 0 ? void 0 : {
188
192
  filePath: m,
189
- contents: await J(e.dirname(m))
190
- },
191
- cwd: process.cwd(),
192
- filePaths: Array.from(f).map((s) => e.join(process.cwd(), s))
193
- }), p.sort((s, l) => s.cwd.localeCompare(l.cwd)), j.projectsData = p, p;
193
+ contents: await M(e.dirname(m))
194
+ };
195
+ p.push({
196
+ typeScriptConfig: void 0,
197
+ packageJson: s,
198
+ cwd: process.cwd(),
199
+ logName: S("blue", s?.contents?.name ?? process.cwd()),
200
+ filePaths: Array.from(f).map((l) => e.join(process.cwd(), l))
201
+ });
202
+ }
203
+ return p.sort((s, l) => s.cwd.localeCompare(l.cwd)), j.projectsData = p, p;
194
204
  }
195
- let M = !1;
205
+ let _ = !1;
196
206
  function te() {
197
- M || (M = !0, process.exitCode !== void 0 && process.exitCode !== 0 ? h(
207
+ _ || (_ = !0, process.exitCode !== void 0 && process.exitCode !== 0 ? h(
198
208
  "warn",
199
209
  j.codemodName,
200
210
  "One or more exceptions occurred during the codemod run. Please review the output above."
201
211
  ) : h(
202
212
  "info",
203
213
  j.codemodName,
204
- `${B("green", "Codemod completed successfully.")} Recommended next steps:
214
+ `${S("green", "Codemod completed successfully.")} Recommended next steps:
205
215
  - Review the codemod changes.
206
216
  - If your project uses ESLint, run ESLint autofix on the changed files.
207
217
  - If your project uses Prettier, run Prettier on the changed files.
@@ -217,40 +227,40 @@ async function oe(t, o) {
217
227
  }
218
228
  await t.run(n), te();
219
229
  }
220
- const S = new $();
221
- S.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
222
- S.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(ne);
230
+ const R = new K();
231
+ R.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
232
+ R.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(ne);
223
233
  async function ne(t, o) {
224
- const n = K(o, { throwIfNoEntry: !1 });
234
+ const n = U(o, { throwIfNoEntry: !1 });
225
235
  if (n === void 0) {
226
236
  h("error", "@arcgis/codemod", `Failed to find the target path: ${o}`), process.exitCode = 1;
227
237
  return;
228
238
  }
229
239
  const r = n.isFile();
230
240
  process.chdir(r ? e.dirname(o) : o);
231
- let a;
241
+ let c;
232
242
  try {
233
- a = await q(/* @__PURE__ */ Object.assign({ "./codemods/arcgis-toolkit/codemod.ts": () => import("./codemod-wiEaN6_r.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod-ul_pPsIY.js") }), `./codemods/${t}/codemod.ts`, 4);
234
- } catch (c) {
243
+ c = await q(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod-CFaEypYt.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod-0vXKYWuW.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod-p2LtUIRE.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod-DSM8Wych.js") }), `./codemods/${t}/codemod.ts`, 4);
244
+ } catch (i) {
235
245
  if (
236
246
  // direct Node execution
237
- typeof c == "object" && c !== null && "code" in c && c.code === "ERR_MODULE_NOT_FOUND" || // Vite build execution
238
- String(c).includes("Unknown variable dynamic import:")
247
+ typeof i == "object" && i !== null && "code" in i && i.code === "ERR_MODULE_NOT_FOUND" && "url" in i && typeof i.url == "string" && i.url.endsWith(`${e.sep}${t}${e.sep}codemod.ts`) || // Vite build execution
248
+ String(i).includes("Unknown variable dynamic import:")
239
249
  ) {
240
250
  h("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
241
251
  return;
242
252
  } else
243
- throw c;
253
+ throw i;
244
254
  }
245
- if (typeof a.codemod != "object" || a.codemod === null) {
255
+ if (typeof c.codemod != "object" || c.codemod === null) {
246
256
  h("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
247
257
  return;
248
258
  }
249
- await oe(a.codemod, t);
259
+ await oe(c.codemod, S("blue", t));
250
260
  }
251
- S.parse();
261
+ R.parse();
252
262
  export {
253
- ge as d,
263
+ ye as d,
254
264
  j as g,
255
265
  te as p
256
266
  };
package/dist/cli.js CHANGED
@@ -1,5 +1,6 @@
1
- import "./cli-mQ3ZNyiH.js";
1
+ import "./cli-CpDkU0N0.js";
2
2
  import "@arcgis/toolkit/log";
3
3
  import "@commander-js/extra-typings";
4
4
  import "node:fs";
5
- import "@arcgis/components-build-utils";
5
+ import "@arcgis/node-toolkit/path";
6
+ import "node:util";