@arcgis/codemod 5.2.0-next.10 → 5.2.0-next.101

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,269 @@
1
+ import { log as y } from "@arcgis/toolkit/log";
2
+ import { Command as U } from "@commander-js/extra-typings";
3
+ import { statSync as B } from "node:fs";
4
+ import { getCwd as k, path as e, toPosixPathSeparators as W } from "@arcgis/node-toolkit/path";
5
+ import "ts-morph";
6
+ import c from "typescript";
7
+ import { existsAsync as q, asyncFindPath as M } from "@arcgis/node-toolkit/file";
8
+ import { asyncRetrievePackageJson as L } from "@arcgis/node-toolkit/packageJson";
9
+ import { glob as A } from "tinyglobby";
10
+ import { gitIgnoreFileToGlobs as G } from "@arcgis/node-toolkit/glob";
11
+ import { identity as _ } from "@arcgis/toolkit/function";
12
+ import { styleText as F } from "node:util";
13
+ const z = (t, o, n) => {
14
+ const r = t[o];
15
+ return r ? typeof r == "function" ? r() : Promise.resolve(r) : new Promise((d, 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." : ""))));
17
+ });
18
+ }, ye = {
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: c.JsxEmit.Preserve,
29
+ lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
30
+ module: c.ModuleKind.ESNext,
31
+ moduleResolution: c.ModuleResolutionKind.Bundler,
32
+ moduleDetection: c.ModuleDetectionKind.Auto,
33
+ strict: !1,
34
+ target: c.ScriptTarget.ESNext,
35
+ resolveJsonModule: !0,
36
+ esModuleInterop: !0
37
+ }, j = {
38
+ codemod: void 0,
39
+ codemodName: void 0,
40
+ projectsData: void 0,
41
+ project: void 0
42
+ };
43
+ async function H() {
44
+ const { ignorePatterns: t, globRoot: o } = await Q(), n = await V(o);
45
+ return t.push(...n), { ignorePatterns: t, globRoot: o };
46
+ }
47
+ async function Q() {
48
+ const t = [];
49
+ let o, n = k(), r = e.dirname(n);
50
+ do {
51
+ o = r;
52
+ const d = e.join(o, ".gitignore");
53
+ if (await q(d)) {
54
+ n = e.dirname(d);
55
+ const g = e.relative(n, k()).split("/"), P = G(d);
56
+ for (const u of P) {
57
+ const h = u.startsWith("!") ? u.slice(1) : u, p = h.search(/[*?[]/u), w = p === -1 ? h : h.slice(0, p), v = w.split("/"), s = p !== -1 && !w.endsWith("/");
58
+ let a = !0;
59
+ const l = Math.min(g.length, v.length);
60
+ for (let m = 0; m < l; m++) {
61
+ const f = v[m];
62
+ if (!(s && m === v.length - 1 ? g[m].startsWith(f) : g[m] === f) && f !== "") {
63
+ a = !1;
64
+ break;
65
+ }
66
+ }
67
+ a && (u.startsWith("!") || t.push(u));
68
+ }
69
+ }
70
+ r = e.dirname(o);
71
+ } while (r !== o);
72
+ return { ignorePatterns: t, globRoot: n };
73
+ }
74
+ async function V(t) {
75
+ return (await A("**/.gitignore", {
76
+ cwd: k(),
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((n) => {
91
+ const r = e.relative(t, e.dirname(n)), d = G(n), i = [];
92
+ for (const g of d)
93
+ g.startsWith("!") || i.push(e.join(r, g));
94
+ return i;
95
+ });
96
+ }
97
+ const X = ["js", "jsx", "mjs", "cjs"], Y = ["ts", "tsx", "mts", "cts"], Z = ["json"], ee = `**/*.{${[...X, ...Y, ...Z].join(",")}}`;
98
+ async function te() {
99
+ const t = await H(), o = e.join(process.cwd(), ee), n = await A(o, {
100
+ cwd: t.globRoot,
101
+ ignore: t.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
+ });
110
+ let r = e.relative(t.globRoot, process.cwd());
111
+ r !== "" && (r += "/");
112
+ const d = e.join(e.resolve(t.globRoot), "/"), i = d.length + r.length, g = [], P = [], u = /* @__PURE__ */ new Set();
113
+ for (const s of n) {
114
+ const a = d + s;
115
+ if (s.endsWith(".json")) {
116
+ const l = e.basename(s);
117
+ l === "package.json" ? g.push(a) : (l.startsWith("tsconfig.") || l.startsWith("jsconfig.")) && P.push(a);
118
+ } else {
119
+ const l = s.slice(r.length);
120
+ u.add(l);
121
+ }
122
+ }
123
+ let h = await M("tsconfig.json", e.dirname(process.cwd()));
124
+ h !== void 0 && (h = W(h), P.push(h)), P.sort((s, a) => {
125
+ const l = a.split("/").length - s.split("/").length;
126
+ if (l !== 0)
127
+ return l;
128
+ const m = e.basename(s), f = e.basename(a);
129
+ return m === f ? 0 : m.endsWith("tsconfig.json") ? -1 : f.endsWith("tsconfig.json") ? 1 : m.endsWith("tsconfig.build.json") ? -1 : f.endsWith("tsconfig.build.json") ? 1 : m.localeCompare(f);
130
+ });
131
+ let p = await M("package.json");
132
+ p !== void 0 && (p = W(p));
133
+ const w = [], v = /* @__PURE__ */ new Set();
134
+ if (await Promise.all(
135
+ P.map(async (s) => {
136
+ const a = e.relative(process.cwd(), s), l = c.readConfigFile(s, c.sys.readFile);
137
+ if (l.error !== void 0) {
138
+ y(
139
+ "error",
140
+ a,
141
+ c.formatDiagnosticsWithColorAndContext([l.error], {
142
+ getCanonicalFileName: _,
143
+ getCurrentDirectory: c.sys.getCurrentDirectory,
144
+ getNewLine: () => c.sys.newLine
145
+ })
146
+ );
147
+ return;
148
+ }
149
+ const m = e.basename(a), f = c.parseJsonConfigFileContent(
150
+ l.config,
151
+ c.sys,
152
+ e.dirname(s),
153
+ void 0,
154
+ m
155
+ ), R = 18003;
156
+ f.errors.filter((b) => b.code !== R).length > 0 && y(
157
+ "warn",
158
+ a,
159
+ c.formatDiagnosticsWithColorAndContext(f.errors, {
160
+ getCanonicalFileName: _,
161
+ getCurrentDirectory: c.sys.getCurrentDirectory,
162
+ getNewLine: () => c.sys.newLine
163
+ })
164
+ );
165
+ const E = s === h, $ = a === m, N = f.fileNames.filter((b) => {
166
+ const D = b.slice(i);
167
+ return u.delete(D) ? (v.add(D), !0) : v.has(D) || D.endsWith(".json") || b.includes("node_modules") ? !1 : !E;
168
+ });
169
+ if (N.length === 0)
170
+ return;
171
+ P.length === 1 && (E || $) && u.clear();
172
+ const S = e.dirname(s);
173
+ let x = S, C = p;
174
+ do {
175
+ const b = e.join(x, "package.json");
176
+ if (g.includes(b)) {
177
+ C = b;
178
+ break;
179
+ }
180
+ } while (x !== t.globRoot && (x = e.dirname(x)));
181
+ const J = C === void 0 ? void 0 : { filePath: C, contents: await L(e.dirname(C)) }, K = {
182
+ typeScriptConfig: {
183
+ filePath: s,
184
+ compilerOptions: f.options
185
+ },
186
+ packageJson: J,
187
+ logName: F("blue", J?.contents?.name ?? S),
188
+ cwd: S,
189
+ filePaths: N
190
+ };
191
+ w.push(K);
192
+ })
193
+ ), u.size > 0) {
194
+ const s = p === void 0 ? void 0 : {
195
+ filePath: p,
196
+ contents: await L(e.dirname(p))
197
+ };
198
+ w.push({
199
+ typeScriptConfig: void 0,
200
+ packageJson: s,
201
+ cwd: process.cwd(),
202
+ logName: F("blue", s?.contents?.name ?? process.cwd()),
203
+ filePaths: Array.from(u).map((a) => e.join(process.cwd(), a))
204
+ });
205
+ }
206
+ return w.sort((s, a) => s.cwd.localeCompare(a.cwd)), j.projectsData = w, w;
207
+ }
208
+ let T = !1;
209
+ function oe() {
210
+ T || (T = !0, process.exitCode !== void 0 && process.exitCode !== 0 ? y(
211
+ "warn",
212
+ j.codemodName,
213
+ "One or more exceptions occurred during the codemod run. Please review the output above."
214
+ ) : y(
215
+ "info",
216
+ j.codemodName,
217
+ `${F("green", "Codemod completed successfully.")} Recommended next steps:
218
+ - Review the codemod changes.
219
+ - If your project uses ESLint, run ESLint autofix on the changed files.
220
+ - If your project uses Prettier, run Prettier on the changed files.
221
+ - If your project uses TypeScript, run type checking to ensure there are no type errors.`
222
+ ));
223
+ }
224
+ async function se(t, o) {
225
+ j.codemod = t, j.codemodName = o;
226
+ const n = await te();
227
+ if (n.length === 0) {
228
+ y("error", o, `Failed to find any .js or .ts files in ${process.cwd()} to run the codemod on.`), process.exitCode = 1;
229
+ return;
230
+ }
231
+ await t.run(n), oe();
232
+ }
233
+ const I = new U();
234
+ I.name("@arcgis/codemod").description("Codemod for migrating or refactoring usages of ArcGIS Maps SDK for JavaScript");
235
+ I.command("run").description("Run a single codemod").argument("<codemodName>", "Name of the transform").argument("[path]", "Directory to transform", process.cwd()).action(ne);
236
+ async function ne(t, o) {
237
+ const n = B(o, { throwIfNoEntry: !1 });
238
+ if (n === void 0) {
239
+ y("error", "@arcgis/codemod", `Failed to find the target path: ${o}`), process.exitCode = 1;
240
+ return;
241
+ }
242
+ const r = n.isFile();
243
+ process.chdir(r ? e.dirname(o) : o);
244
+ let d;
245
+ try {
246
+ d = await z(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod-BCA3Zsj5.js"), "./codemods/geometry-operator-renames/codemod.ts": () => import("./codemod-DR-xywzq.js"), "./codemods/lumina-component-extras-improvements/codemod.ts": () => import("./codemod-BbDIW8zt.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod-B5vDOHtC.js"), "./codemods/normalize-calcite-icon-names/codemod.ts": () => import("./codemod-Bx0pPjvL.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod-uDufyH34.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod-D6XW4GHI.js") }), `./codemods/${t}/codemod.ts`, 4);
247
+ } catch (i) {
248
+ if (
249
+ // direct Node execution
250
+ typeof i == "object" && i !== null && "code" in i && i.code === "ERR_MODULE_NOT_FOUND" && "url" in i && typeof i.url == "string" && i.url.endsWith(`/${t}/codemod.ts`) || // Vite build execution
251
+ String(i).includes("Unknown variable dynamic import:")
252
+ ) {
253
+ y("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
254
+ return;
255
+ } else
256
+ throw i;
257
+ }
258
+ if (typeof d.codemod != "object" || d.codemod === null) {
259
+ y("error", "@arcgis/codemod", `Can't find codemod by name "${t}".`), process.exitCode = 1;
260
+ return;
261
+ }
262
+ await se(d.codemod, F("blue", t));
263
+ }
264
+ I.parse();
265
+ export {
266
+ ye as d,
267
+ j as g,
268
+ oe as p
269
+ };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./cli-CEoOkVsW.js";
1
+ import "./cli-BKb1yG1F.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
6
  import "node:util";
@@ -0,0 +1,140 @@
1
+ var p = (i, o) => (o = Symbol[i]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + i), f = (i) => {
2
+ throw TypeError(i);
3
+ };
4
+ var g = (i, o, a) => {
5
+ if (o != null) {
6
+ typeof o != "object" && typeof o != "function" && f("Object expected");
7
+ var n, t;
8
+ a && (n = o[p("asyncDispose")]), n === void 0 && (n = o[p("dispose")], a && (t = n)), typeof n != "function" && f("Object not disposable"), t && (n = function() {
9
+ try {
10
+ t.call(this);
11
+ } catch (r) {
12
+ return Promise.reject(r);
13
+ }
14
+ }), i.push([a, n, o]);
15
+ } else a && i.push([a]);
16
+ return o;
17
+ }, m = (i, o, a) => {
18
+ var n = typeof SuppressedError == "function" ? SuppressedError : function(e, s, c, l) {
19
+ return l = Error(c), l.name = "SuppressedError", l.error = e, l.suppressed = s, l;
20
+ }, t = (e) => o = a ? new n(e, o, "An error was suppressed during disposal") : (a = !0, e), r = (e) => {
21
+ for (; e = i.pop(); )
22
+ try {
23
+ var s = e[1] && e[1].call(e[2]);
24
+ if (e[0]) return Promise.resolve(s).then(r, (c) => (t(c), r()));
25
+ } catch (c) {
26
+ t(c);
27
+ }
28
+ if (a) throw o;
29
+ };
30
+ return r();
31
+ };
32
+ import { f as h, p as P } from "./actions-BxmXtSdU.js";
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-CyHNM-mp.js";
36
+ import { p as x, g as J } from "./cli-BKb1yG1F.js";
37
+ async function v(i, o) {
38
+ const a = /* @__PURE__ */ new Set();
39
+ for (const n of i) {
40
+ const t = n.packageJson;
41
+ if (t === void 0 || a.has(t.filePath))
42
+ continue;
43
+ a.add(t.filePath);
44
+ const r = t.contents;
45
+ try {
46
+ const e = await o(r, t.filePath);
47
+ r !== e && await u(t.filePath, `${JSON.stringify(e, null, 2)}
48
+ `, "utf8");
49
+ } catch (e) {
50
+ process.exitCode = 1, k(
51
+ "error",
52
+ h(t.filePath),
53
+ `Error occurred while migrating: ${String(e)}`,
54
+ typeof e == "object" && e !== null && "stack" in e ? { detail: { stack: e.stack } } : void 0
55
+ );
56
+ }
57
+ }
58
+ }
59
+ function D(i, o) {
60
+ for (const a of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
61
+ const n = i[a];
62
+ if (n) {
63
+ const t = o(n, a);
64
+ t !== n && (i = { ...i, [a]: t });
65
+ }
66
+ }
67
+ return i;
68
+ }
69
+ const d = "@arcgis/components-build-utils", S = {
70
+ [d]: {
71
+ existsAsync: { do: "rename", specifier: "@arcgis/node-toolkit/file" },
72
+ // Command-string helpers require manual tokenization before using command-plus-args helpers.
73
+ sh: { do: "rename", specifier: "@arcgis/node-toolkit/shell" },
74
+ // sp was removed from node-toolkit; collectOutputSync is the closest return-value replacement.
75
+ sp: { do: "rename", name: "collectOutputSync", specifier: "@arcgis/node-toolkit/shell" },
76
+ asyncSh: { do: "rename", specifier: "@arcgis/node-toolkit/shell" },
77
+ findPath: { do: "rename", specifier: "@arcgis/node-toolkit/file" },
78
+ asyncFindPath: { do: "rename", specifier: "@arcgis/node-toolkit/file" },
79
+ createFileIfNotExists: { do: "rename", specifier: "@arcgis/node-toolkit/file" },
80
+ gitIgnoreFileToGlobs: { do: "rename", specifier: "@arcgis/node-toolkit/glob" },
81
+ gitIgnoreToGlob: { do: "rename", specifier: "@arcgis/node-toolkit/glob" },
82
+ isPosix: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
83
+ toPosixPathSeparators: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
84
+ normalizePath: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
85
+ toSystemPathSeparators: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
86
+ getCwd: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
87
+ path: { do: "rename", specifier: "@arcgis/node-toolkit/path" },
88
+ PackageJson: { do: "rename", specifier: "@arcgis/node-toolkit/packageJson" },
89
+ retrievePackageJson: { do: "rename", specifier: "@arcgis/node-toolkit/packageJson" },
90
+ asyncRetrievePackageJson: { do: "rename", specifier: "@arcgis/node-toolkit/packageJson" },
91
+ fetchPackageLocation: { do: "rename", specifier: "@arcgis/node-toolkit/packageJson" },
92
+ detectPackageManager: { do: "rename", specifier: "@arcgis/node-toolkit/packageJson" },
93
+ DependencyManagementOptions: {
94
+ do: "rename",
95
+ specifier: "@arcgis/node-toolkit/vite/externalizeDependenciesPlugin"
96
+ },
97
+ vitePresetPlugin: { do: "rename", specifier: "@arcgis/node-toolkit/vite/presetPlugin" },
98
+ externalizeDependencies: {
99
+ do: "rename",
100
+ specifier: "@arcgis/node-toolkit/vite/externalizeDependenciesPlugin"
101
+ }
102
+ }
103
+ }, C = {
104
+ meta: {
105
+ needsTypeInformation: !1
106
+ },
107
+ async run(i) {
108
+ await v(
109
+ i,
110
+ (r) => D(
111
+ r,
112
+ (e) => e[d] ? {
113
+ ...e,
114
+ [d]: void 0,
115
+ "@arcgis/node-toolkit": e[d]
116
+ } : e
117
+ )
118
+ );
119
+ for (const r of i) {
120
+ var o = [];
121
+ try {
122
+ const e = g(o, y(r));
123
+ for (const s of e.getCodemodFiles())
124
+ P(s, S);
125
+ } catch (a) {
126
+ var n = a, t = !0;
127
+ } finally {
128
+ m(o, n, t);
129
+ }
130
+ }
131
+ x(), k(
132
+ "info",
133
+ J.codemodName,
134
+ "Next step: run npm install/pnpm install/yarn install to get @arcgis/node-toolkit package installed."
135
+ );
136
+ }
137
+ };
138
+ export {
139
+ C as codemod
140
+ };
@@ -30,12 +30,12 @@ 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-C2IpDULI.js";
33
+ import { c as V } from "./useProjectInstance-CyHNM-mp.js";
34
34
  import { mergeApiExtractorConfigs as O, loadApiExtractorConfig as _ } from "@arcgis/api-extractor/extractor/config";
35
- import { g as F } from "./cli-CEoOkVsW.js";
35
+ import { g as F } from "./cli-BKb1yG1F.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
- import { existsAsync as U } from "@arcgis/components-build-utils";
38
+ import { existsAsync as U } from "@arcgis/node-toolkit/file";
39
39
  import { ApiExtractor as Y } from "@arcgis/api-extractor/extractor/ApiExtractor";
40
40
  import { SyntaxKind as f } from "ts-morph";
41
41
  import { getApiMemberName as q } from "@arcgis/api-extractor/utils/apiHelpers";
@@ -127,7 +127,7 @@ function M(n, e) {
127
127
  return n.replace(/\{@link +([^}]+)\}/gu, (i, d) => {
128
128
  const r = d.trim(), s = r.indexOf(" "), t = s === -1 ? r : r.slice(0, s), c = s === -1 ? "" : r.slice(s + 1).trim();
129
129
  if (t.startsWith("https://"))
130
- return c ? `[${c}](${t})]` : t;
130
+ return c ? `[${c}](${t})` : t;
131
131
  if (t.includes("!"))
132
132
  return i;
133
133
  const o = t.indexOf("#"), a = o === -1 ? t : t.slice(0, o), l = o === -1 ? void 0 : t.slice(o + 1), u = e[a] ?? Object.values(e).find(({ modulePath: N }) => N === a);
@@ -182,7 +182,7 @@ ${a}
182
182
  For each added declaration, remove @public from it if it is not supposed to be public. For each removed declaration, add @public JSDoc tag if it needs to remain public.`
183
183
  );
184
184
  }
185
- const te = "5.2.0-next.10", ne = {
185
+ const te = "5.2.0-next.101", ne = {
186
186
  version: te
187
187
  };
188
188
  async function oe(n) {
@@ -382,7 +382,7 @@ async function re(n) {
382
382
  r.length > 0 && y(
383
383
  "warn",
384
384
  n.logName,
385
- `Found deprecated options in ${e}: ${r.join(", ")}. Please refactor these out to equivalents specific in their deprecation messages (see vscode tooltips). See https://webgis.esri.com/references/api-extractor/running-standalone for an example api-extractor.config.ts. You do not need to re-run the codemod.
385
+ `Found deprecated options in ${e}: ${r.join(", ")}. Please refactor these out to equivalents specific in their deprecation messages (see vscode tooltips). See https://webgis.esri.com/references/api-extractor/integrations for an example api-extractor.config.ts. You do not need to re-run the codemod.
386
386
  `
387
387
  );
388
388
  }