@arcgis/codemod 5.2.0-next.85 → 5.2.0-next.87
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 +40 -5
- package/dist/{actions-DK9SU_tx.js → actions-8PIadCgg.js} +1 -1
- package/dist/actions-D_zMP7bV.js +354 -0
- package/dist/{cli-Di2luZf3.js → cli-COx17UK8.js} +36 -36
- package/dist/cli-qKUUieac.js +266 -0
- package/dist/cli.js +1 -1
- package/dist/{codemod-Bx0Mj5YU.js → codemod-BcgYxPxD.js} +3 -3
- package/dist/{codemod-BjO9lW8z.js → codemod-BnKQVsF8.js} +3 -3
- package/dist/{codemod-DdiyCqBV.js → codemod-BwRmX2eo.js} +3 -3
- package/dist/codemod-CJUchJW_.js +6080 -0
- package/dist/codemod-CTd7n0lD.js +140 -0
- package/dist/codemod-Ce_Kk0Ir.js +240 -0
- package/dist/codemod-CjvNjSDv.js +240 -0
- package/dist/{codemod-D999oAKl.js → codemod-D77Br2SQ.js} +3 -3
- package/dist/codemod-DPXaddAw.js +436 -0
- package/dist/codemod-Q9pmw-JU.js +74 -0
- package/dist/{useProjectInstance-B7uO3lBW.js → useProjectInstance-B86v8eX5.js} +13 -16
- package/dist/useProjectInstance-evHsM1li.js +47 -0
- package/package.json +5 -5
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { log as h } from "@arcgis/toolkit/log";
|
|
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
|
+
import "ts-morph";
|
|
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";
|
|
13
|
+
const q = (o, t, n) => {
|
|
14
|
+
const r = o[t];
|
|
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: " + t + (t.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: a.JsxEmit.Preserve,
|
|
29
|
+
lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
|
|
30
|
+
module: a.ModuleKind.ESNext,
|
|
31
|
+
moduleResolution: a.ModuleResolutionKind.Bundler,
|
|
32
|
+
moduleDetection: a.ModuleDetectionKind.Auto,
|
|
33
|
+
strict: !1,
|
|
34
|
+
target: a.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 z() {
|
|
44
|
+
const { ignorePatterns: o, globRoot: t } = await H(), n = await Q(t);
|
|
45
|
+
return o.push(...n), { ignorePatterns: o, globRoot: t };
|
|
46
|
+
}
|
|
47
|
+
async function H() {
|
|
48
|
+
const o = [];
|
|
49
|
+
let t, n = F(), r = e.dirname(n);
|
|
50
|
+
do {
|
|
51
|
+
t = r;
|
|
52
|
+
const c = e.join(t, ".gitignore");
|
|
53
|
+
if (await B(c)) {
|
|
54
|
+
n = e.dirname(c);
|
|
55
|
+
const w = e.relative(n, F()).split("/"), y = $(c);
|
|
56
|
+
for (const f of y) {
|
|
57
|
+
const m = (f.startsWith("!") ? f.slice(1) : f).split("*")[0].split("/");
|
|
58
|
+
let p = !0;
|
|
59
|
+
for (let g = 0; g < m.length; g++)
|
|
60
|
+
if (w[g] !== m[g] && m[g] !== "") {
|
|
61
|
+
p = !1;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
p && (f.startsWith("!") || o.push(f));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
r = e.dirname(t);
|
|
68
|
+
} while (r !== t);
|
|
69
|
+
return { ignorePatterns: o, globRoot: n };
|
|
70
|
+
}
|
|
71
|
+
async function Q(o) {
|
|
72
|
+
return (await T("**/.gitignore", {
|
|
73
|
+
cwd: F(),
|
|
74
|
+
// Gitignore files are unlikely to be symbolic links
|
|
75
|
+
followSymbolicLinks: !1,
|
|
76
|
+
// Don't look for ignore files in these places for speed:
|
|
77
|
+
ignore: [
|
|
78
|
+
// Hardcoded ignores in TypeScript
|
|
79
|
+
"**/node_modules/**",
|
|
80
|
+
"**/bower_components/**",
|
|
81
|
+
"**/jspm_packages/**",
|
|
82
|
+
// Default build output folder in bundlers
|
|
83
|
+
"**/dist/**"
|
|
84
|
+
],
|
|
85
|
+
// Not applicable for our glob pattern
|
|
86
|
+
expandDirectories: !1
|
|
87
|
+
})).flatMap((n) => {
|
|
88
|
+
const r = e.relative(o, e.dirname(n)), c = $(n), i = [];
|
|
89
|
+
for (const w of c)
|
|
90
|
+
w.startsWith("!") || i.push(e.join(r, w));
|
|
91
|
+
return i;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const V = ["js", "jsx", "mjs", "cjs"], X = ["ts", "tsx", "mts", "cts"], Y = ["json"], Z = `**/*.{${[...V, ...X, ...Y].join(",")}}`;
|
|
95
|
+
async function ee() {
|
|
96
|
+
const o = await z(), t = e.join(process.cwd(), Z), n = await T(t, {
|
|
97
|
+
cwd: o.globRoot,
|
|
98
|
+
ignore: o.ignorePatterns,
|
|
99
|
+
// The files we are looking for are unlikely to be symbolic links
|
|
100
|
+
followSymbolicLinks: !1,
|
|
101
|
+
// Not applicable for our glob pattern
|
|
102
|
+
expandDirectories: !1
|
|
103
|
+
// Files and folders starting with . are excluded (matches TypeScript's
|
|
104
|
+
// default behavior). If any tsconfig.json explicitly includes such files,
|
|
105
|
+
// they will still be codemodded.
|
|
106
|
+
});
|
|
107
|
+
let r = e.relative(o.globRoot, process.cwd());
|
|
108
|
+
r !== "" && (r += "/");
|
|
109
|
+
const c = e.join(e.resolve(o.globRoot), "/"), i = c.length + r.length, w = [], y = [], f = /* @__PURE__ */ new Set();
|
|
110
|
+
for (const s of n) {
|
|
111
|
+
const l = c + s;
|
|
112
|
+
if (s.endsWith(".json")) {
|
|
113
|
+
const d = e.basename(s);
|
|
114
|
+
d === "package.json" ? w.push(l) : (d.startsWith("tsconfig.") || d.startsWith("jsconfig.")) && y.push(l);
|
|
115
|
+
} else {
|
|
116
|
+
const d = s.slice(r.length);
|
|
117
|
+
f.add(d);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
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) => {
|
|
122
|
+
const d = l.split("/").length - s.split("/").length;
|
|
123
|
+
if (d !== 0)
|
|
124
|
+
return d;
|
|
125
|
+
const b = e.basename(s), u = e.basename(l);
|
|
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);
|
|
127
|
+
});
|
|
128
|
+
let m = await W("package.json");
|
|
129
|
+
m !== void 0 && (m = J(m));
|
|
130
|
+
const p = [], g = /* @__PURE__ */ new Set();
|
|
131
|
+
if (await Promise.all(
|
|
132
|
+
y.map(async (s) => {
|
|
133
|
+
const l = e.relative(process.cwd(), s), d = a.readConfigFile(s, a.sys.readFile);
|
|
134
|
+
if (d.error !== void 0) {
|
|
135
|
+
h(
|
|
136
|
+
"error",
|
|
137
|
+
l,
|
|
138
|
+
a.formatDiagnosticsWithColorAndContext([d.error], {
|
|
139
|
+
getCanonicalFileName: L,
|
|
140
|
+
getCurrentDirectory: a.sys.getCurrentDirectory,
|
|
141
|
+
getNewLine: () => a.sys.newLine
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const b = e.basename(l), u = a.parseJsonConfigFileContent(
|
|
147
|
+
d.config,
|
|
148
|
+
a.sys,
|
|
149
|
+
e.dirname(s),
|
|
150
|
+
void 0,
|
|
151
|
+
b
|
|
152
|
+
), A = 18003;
|
|
153
|
+
u.errors.filter((P) => P.code !== A).length > 0 && h(
|
|
154
|
+
"warn",
|
|
155
|
+
l,
|
|
156
|
+
a.formatDiagnosticsWithColorAndContext(u.errors, {
|
|
157
|
+
getCanonicalFileName: L,
|
|
158
|
+
getCurrentDirectory: a.sys.getCurrentDirectory,
|
|
159
|
+
getNewLine: () => a.sys.newLine
|
|
160
|
+
})
|
|
161
|
+
);
|
|
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;
|
|
165
|
+
});
|
|
166
|
+
if (N.length === 0)
|
|
167
|
+
return;
|
|
168
|
+
y.length === 1 && (I || G) && f.clear();
|
|
169
|
+
const k = e.dirname(s);
|
|
170
|
+
let C = k, x = m;
|
|
171
|
+
do {
|
|
172
|
+
const P = e.join(C, "package.json");
|
|
173
|
+
if (w.includes(P)) {
|
|
174
|
+
x = P;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
} while (C !== o.globRoot && (C = e.dirname(C)));
|
|
178
|
+
const E = x === void 0 ? void 0 : { filePath: x, contents: await M(e.dirname(x)) }, O = {
|
|
179
|
+
typeScriptConfig: {
|
|
180
|
+
filePath: s,
|
|
181
|
+
compilerOptions: u.options
|
|
182
|
+
},
|
|
183
|
+
packageJson: E,
|
|
184
|
+
logName: S("blue", E?.contents?.name ?? k),
|
|
185
|
+
cwd: k,
|
|
186
|
+
filePaths: N
|
|
187
|
+
};
|
|
188
|
+
p.push(O);
|
|
189
|
+
})
|
|
190
|
+
), f.size > 0) {
|
|
191
|
+
const s = m === void 0 ? void 0 : {
|
|
192
|
+
filePath: m,
|
|
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;
|
|
204
|
+
}
|
|
205
|
+
let _ = !1;
|
|
206
|
+
function oe() {
|
|
207
|
+
_ || (_ = !0, process.exitCode !== void 0 && process.exitCode !== 0 ? h(
|
|
208
|
+
"warn",
|
|
209
|
+
j.codemodName,
|
|
210
|
+
"One or more exceptions occurred during the codemod run. Please review the output above."
|
|
211
|
+
) : h(
|
|
212
|
+
"info",
|
|
213
|
+
j.codemodName,
|
|
214
|
+
`${S("green", "Codemod completed successfully.")} Recommended next steps:
|
|
215
|
+
- Review the codemod changes.
|
|
216
|
+
- If your project uses ESLint, run ESLint autofix on the changed files.
|
|
217
|
+
- If your project uses Prettier, run Prettier on the changed files.
|
|
218
|
+
- If your project uses TypeScript, run type checking to ensure there are no type errors.`
|
|
219
|
+
));
|
|
220
|
+
}
|
|
221
|
+
async function te(o, t) {
|
|
222
|
+
j.codemod = o, j.codemodName = t;
|
|
223
|
+
const n = await ee();
|
|
224
|
+
if (n.length === 0) {
|
|
225
|
+
h("error", t, `Failed to find any .js or .ts files in ${process.cwd()} to run the codemod on.`), process.exitCode = 1;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
await o.run(n), oe();
|
|
229
|
+
}
|
|
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);
|
|
233
|
+
async function ne(o, t) {
|
|
234
|
+
const n = U(t, { throwIfNoEntry: !1 });
|
|
235
|
+
if (n === void 0) {
|
|
236
|
+
h("error", "@arcgis/codemod", `Failed to find the target path: ${t}`), process.exitCode = 1;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const r = n.isFile();
|
|
240
|
+
process.chdir(r ? e.dirname(t) : t);
|
|
241
|
+
let c;
|
|
242
|
+
try {
|
|
243
|
+
c = await q(/* @__PURE__ */ Object.assign({ "./codemods/api-extractor-strict-mode/codemod.ts": () => import("./codemod-BnKQVsF8.js"), "./codemods/node-toolkit/codemod.ts": () => import("./codemod-BcgYxPxD.js"), "./codemods/normalize-calcite-icon-names/codemod.ts": () => import("./codemod-CjvNjSDv.js"), "./codemods/refactor-out-esri-namespace/codemod.ts": () => import("./codemod-CJUchJW_.js"), "./codemods/toolkit-5.2-renames/codemod.ts": () => import("./codemod-Q9pmw-JU.js") }), `./codemods/${o}/codemod.ts`, 4);
|
|
244
|
+
} catch (i) {
|
|
245
|
+
if (
|
|
246
|
+
// direct Node execution
|
|
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}${o}${e.sep}codemod.ts`) || // Vite build execution
|
|
248
|
+
String(i).includes("Unknown variable dynamic import:")
|
|
249
|
+
) {
|
|
250
|
+
h("error", "@arcgis/codemod", `Can't find codemod by name "${o}".`), process.exitCode = 1;
|
|
251
|
+
return;
|
|
252
|
+
} else
|
|
253
|
+
throw i;
|
|
254
|
+
}
|
|
255
|
+
if (typeof c.codemod != "object" || c.codemod === null) {
|
|
256
|
+
h("error", "@arcgis/codemod", `Can't find codemod by name "${o}".`), process.exitCode = 1;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
await te(c.codemod, S("blue", o));
|
|
260
|
+
}
|
|
261
|
+
R.parse();
|
|
262
|
+
export {
|
|
263
|
+
ye as d,
|
|
264
|
+
j as g,
|
|
265
|
+
oe as p
|
|
266
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -29,11 +29,11 @@ var g = (i, o, a) => {
|
|
|
29
29
|
};
|
|
30
30
|
return r();
|
|
31
31
|
};
|
|
32
|
-
import { f as h, p as P } from "./actions-
|
|
32
|
+
import { f as h, p as P } from "./actions-D_zMP7bV.js";
|
|
33
33
|
import { log as k } from "@arcgis/toolkit/log";
|
|
34
34
|
import { writeFile as u } from "node:fs/promises";
|
|
35
|
-
import { c as y } from "./useProjectInstance-
|
|
36
|
-
import { p as x, g as J } from "./cli-
|
|
35
|
+
import { c as y } from "./useProjectInstance-B86v8eX5.js";
|
|
36
|
+
import { p as x, g as J } from "./cli-qKUUieac.js";
|
|
37
37
|
async function v(i, o) {
|
|
38
38
|
const a = /* @__PURE__ */ new Set();
|
|
39
39
|
for (const n of i) {
|
|
@@ -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-
|
|
33
|
+
import { c as V } from "./useProjectInstance-B86v8eX5.js";
|
|
34
34
|
import { mergeApiExtractorConfigs as O, loadApiExtractorConfig as _ } from "@arcgis/api-extractor/extractor/config";
|
|
35
|
-
import { g as F } from "./cli-
|
|
35
|
+
import { g as F } from "./cli-qKUUieac.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";
|
|
@@ -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.
|
|
185
|
+
const te = "5.2.0-next.86", ne = {
|
|
186
186
|
version: te
|
|
187
187
|
};
|
|
188
188
|
async function oe(n) {
|