@arcgis/codemod 5.2.0-next.0 → 5.2.0-next.10
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/dist/actions-MCoDW3-M.js +354 -0
- package/dist/{cli-mQ3ZNyiH.js → cli-CEoOkVsW.js} +86 -80
- package/dist/cli.js +2 -1
- package/dist/{codemod-ul_pPsIY.js → codemod-BBCNLiaZ.js} +5 -4
- package/dist/codemod-CeeI5u5I.js +436 -0
- package/dist/{codemod-wiEaN6_r.js → codemod-DqK7tHmC.js} +9 -8
- package/dist/useProjectInstance-C2IpDULI.js +50 -0
- package/package.json +4 -3
- package/dist/useProjectInstance-BeTuT4eH.js +0 -398
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
import { path as T } from "@arcgis/components-build-utils";
|
|
2
|
-
import { SyntaxKind as y, Project as j } from "ts-morph";
|
|
3
|
-
import { g as h, d as C } from "./cli-mQ3ZNyiH.js";
|
|
4
|
-
import { ModuleResolutionKind as D } from "typescript";
|
|
5
|
-
import { capitalize as q } from "@arcgis/toolkit/string";
|
|
6
|
-
import { log as w } from "@arcgis/toolkit/log";
|
|
7
|
-
import { styleText as S } from "node:util";
|
|
8
|
-
function b(e) {
|
|
9
|
-
const t = e.typeScriptConfig?.compilerOptions?.moduleResolution ?? D.Bundler;
|
|
10
|
-
return t >= D.Node16 && t <= D.NodeNext;
|
|
11
|
-
}
|
|
12
|
-
function A(e) {
|
|
13
|
-
return K(e.getFilePath());
|
|
14
|
-
}
|
|
15
|
-
function K(e) {
|
|
16
|
-
return T.relative(process.cwd(), e);
|
|
17
|
-
}
|
|
18
|
-
function Z(e, t) {
|
|
19
|
-
const n = {};
|
|
20
|
-
E(e);
|
|
21
|
-
const { specifiers: r, names: f, lastImportIndex: s } = F(e), d = [], o = {};
|
|
22
|
-
let m = b(h.project.projectData);
|
|
23
|
-
for (const [a, p] of Object.entries(t)) {
|
|
24
|
-
let i = r.get(a) ?? (a.startsWith(".") ? r.get(
|
|
25
|
-
T.relative(e.getDirectoryPath(), T.resolve(h.project.projectData.cwd, a))
|
|
26
|
-
) : void 0);
|
|
27
|
-
if (i === void 0) {
|
|
28
|
-
const c = r.get(`${a}.js`);
|
|
29
|
-
c !== void 0 && (m = !0, i === void 0 ? i = c : i = [...i, ...c]);
|
|
30
|
-
}
|
|
31
|
-
for (const [c, g] of Object.entries(p)) {
|
|
32
|
-
const N = Array.isArray(g) ? g : [g];
|
|
33
|
-
for (const I of N)
|
|
34
|
-
I.do === "deprecate" ? $(c, a, n, i) : I.do === "add" ? k(a, c, I, i, d, o, f) : I.do === "rename" && M(a, c, I, i, d, o, f);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const u = Object.entries(o);
|
|
38
|
-
let l = s;
|
|
39
|
-
for (let a = 0; a < u.length; a += 1) {
|
|
40
|
-
const [p, i] = u[a], c = p.startsWith(".") ? R(
|
|
41
|
-
T.relative(e.getDirectoryPath(), T.resolve(h.project.projectData.cwd, p))
|
|
42
|
-
) : p, g = m && c.startsWith("@arcgis/core") ? `${c}.js` : c, N = i.afterDeclaration === void 0 ? l : i.afterDeclaration.getChildIndex() + 1;
|
|
43
|
-
if (i.named.length > 0) {
|
|
44
|
-
let I = !0;
|
|
45
|
-
for (let v = 0; v < i.named.length; v += 1)
|
|
46
|
-
I &&= i.named[v].isTypeOnly;
|
|
47
|
-
e.insertImportDeclaration(N, {
|
|
48
|
-
isTypeOnly: I,
|
|
49
|
-
moduleSpecifier: g,
|
|
50
|
-
namedImports: i.named.map((v) => ({
|
|
51
|
-
name: v.name,
|
|
52
|
-
alias: v.alias,
|
|
53
|
-
isTypeOnly: v.isTypeOnly && !I
|
|
54
|
-
}))
|
|
55
|
-
}), l += 1;
|
|
56
|
-
}
|
|
57
|
-
i.default !== void 0 && (e.insertImportDeclaration(N, {
|
|
58
|
-
isTypeOnly: i.default.isTypeOnly,
|
|
59
|
-
moduleSpecifier: g,
|
|
60
|
-
defaultImport: i.default.name
|
|
61
|
-
}), l += 1), i["*"] !== void 0 && (e.insertImportDeclaration(N, {
|
|
62
|
-
isTypeOnly: i["*"].isTypeOnly,
|
|
63
|
-
moduleSpecifier: g,
|
|
64
|
-
namespaceImport: i["*"].name
|
|
65
|
-
}), l += 1);
|
|
66
|
-
}
|
|
67
|
-
if (Object.keys(n).length > 0) {
|
|
68
|
-
const a = Object.entries(n).map(([p, i]) => `${i.join(", ")} from ${p}`).join("; ");
|
|
69
|
-
w("warn", A(e), `Deprecated API usages found: ${a}`);
|
|
70
|
-
}
|
|
71
|
-
return d;
|
|
72
|
-
}
|
|
73
|
-
function E(e) {
|
|
74
|
-
const t = e.getChildSyntaxList()?.getFirstChild();
|
|
75
|
-
if (P === t)
|
|
76
|
-
return;
|
|
77
|
-
P = t, O.clear();
|
|
78
|
-
const n = /* @__PURE__ */ new Set();
|
|
79
|
-
r(e);
|
|
80
|
-
function r(f) {
|
|
81
|
-
for (const s of f.getStatements())
|
|
82
|
-
if (s.isKind(y.ImportDeclaration)) {
|
|
83
|
-
const d = s.getDefaultImport(), o = s.getNamespaceImport(), m = s.getNamedImports();
|
|
84
|
-
d && n.add(d.getText()), o && n.add(o.getText());
|
|
85
|
-
for (const u of m)
|
|
86
|
-
n.add(u.getAliasNode()?.getText() ?? u.getName());
|
|
87
|
-
} else s.isKind(y.ImportEqualsDeclaration) ? n.add(s.getName()) : s.isKind(y.ModuleDeclaration) ? r(s) : f.forEachDescendant((d) => {
|
|
88
|
-
if (!d.isKind(y.Identifier))
|
|
89
|
-
return;
|
|
90
|
-
const o = d.getParent();
|
|
91
|
-
if (o.isKind(y.QualifiedName) && o.getLeft() !== d || o.isKind(y.PropertyAccessExpression) && o.getExpression() !== d || (o.isKind(y.PropertyDeclaration) || o.isKind(y.PropertySignature) || o.isKind(y.PropertyAssignment)) && o.getNameNode() === d)
|
|
92
|
-
return;
|
|
93
|
-
const m = d.getText();
|
|
94
|
-
n.has(m) || O.add(d.getText());
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function F(e) {
|
|
99
|
-
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = e.getStatements();
|
|
100
|
-
let f;
|
|
101
|
-
for (let d = 0; d < r.length; d += 1) {
|
|
102
|
-
const o = r[d];
|
|
103
|
-
if (!o.isKind(y.ImportDeclaration)) {
|
|
104
|
-
const c = o.getName?.();
|
|
105
|
-
c !== void 0 && n.add(c);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
f = o;
|
|
109
|
-
const m = o.getModuleSpecifierValue(), u = t.get(m);
|
|
110
|
-
u === void 0 ? t.set(m, [o]) : u.push(o);
|
|
111
|
-
const l = o.getImportClause();
|
|
112
|
-
if (l === void 0)
|
|
113
|
-
continue;
|
|
114
|
-
const a = l.getDefaultImport()?.getText();
|
|
115
|
-
a !== void 0 && n.add(a);
|
|
116
|
-
const p = l.getNamedBindings();
|
|
117
|
-
if (p !== void 0)
|
|
118
|
-
if (p.isKind(y.NamedImports))
|
|
119
|
-
for (const i of p.getElements()) {
|
|
120
|
-
const c = i.getName();
|
|
121
|
-
n.add(c);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
const i = p.getName();
|
|
125
|
-
n.add(i);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const s = f === void 0 ? 0 : f.getChildIndex() + 1;
|
|
129
|
-
return { specifiers: t, names: n, lastImportIndex: s };
|
|
130
|
-
}
|
|
131
|
-
function $(e, t, n, r) {
|
|
132
|
-
if (r !== void 0) {
|
|
133
|
-
if (e === "default")
|
|
134
|
-
for (const f of r) {
|
|
135
|
-
const s = f.getDefaultImport();
|
|
136
|
-
if (s !== void 0) {
|
|
137
|
-
n[t] ??= [], n[t].push(s.getText());
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else if (e === "*")
|
|
142
|
-
for (const f of r) {
|
|
143
|
-
const s = f.getNamespaceImport();
|
|
144
|
-
if (s !== void 0) {
|
|
145
|
-
n[t] ??= [], n[t].push(s.getText());
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else
|
|
150
|
-
for (const f of r)
|
|
151
|
-
for (const s of f.getNamedImports())
|
|
152
|
-
if (s.getName() === e) {
|
|
153
|
-
n[t] ??= [], n[t].push(s.getName());
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function k(e, t, n, r, f, s, d) {
|
|
159
|
-
const o = t === "default";
|
|
160
|
-
if (o || t === "*") {
|
|
161
|
-
if (r !== void 0)
|
|
162
|
-
for (const u of r) {
|
|
163
|
-
const l = o ? u.getDefaultImport() : u.getNamespaceImport();
|
|
164
|
-
if (l !== void 0) {
|
|
165
|
-
n.isTypeOnly !== !0 && u.isTypeOnly() && u.setIsTypeOnly(!1), f.push({
|
|
166
|
-
specifier: e,
|
|
167
|
-
requestedName: t,
|
|
168
|
-
actualName: l.getText()
|
|
169
|
-
});
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const m = x(n.preferredAlias, void 0, e, d);
|
|
174
|
-
f.push({ specifier: e, requestedName: t, actualName: m }), s[e] ??= {
|
|
175
|
-
afterDeclaration: void 0,
|
|
176
|
-
named: [],
|
|
177
|
-
default: void 0,
|
|
178
|
-
"*": void 0
|
|
179
|
-
}, s[e].afterDeclaration ??= r?.[0], s[e][t] = {
|
|
180
|
-
name: m,
|
|
181
|
-
isTypeOnly: n.isTypeOnly === !0
|
|
182
|
-
};
|
|
183
|
-
} else {
|
|
184
|
-
let m, u;
|
|
185
|
-
if (r !== void 0) {
|
|
186
|
-
let p = !1;
|
|
187
|
-
for (const i of r)
|
|
188
|
-
if (i.getNamespaceImport() === void 0) {
|
|
189
|
-
u ??= i, m ??= i.isTypeOnly() && i.getDefaultImport() === void 0 ? i : void 0;
|
|
190
|
-
for (const c of i.getNamedImports())
|
|
191
|
-
if (c.getNameNode().getText() === t) {
|
|
192
|
-
if (p = !0, n.isTypeOnly !== !0) {
|
|
193
|
-
if (c.isTypeOnly())
|
|
194
|
-
c.setIsTypeOnly(!1);
|
|
195
|
-
else if (i.isTypeOnly()) {
|
|
196
|
-
for (const g of i.getNamedImports())
|
|
197
|
-
g !== c && g.setIsTypeOnly(!0);
|
|
198
|
-
i.setIsTypeOnly(!1);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
f.push({
|
|
202
|
-
specifier: e,
|
|
203
|
-
requestedName: t,
|
|
204
|
-
actualName: c.getAliasNode()?.getText() ?? t
|
|
205
|
-
});
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (p)
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const l = x(
|
|
213
|
-
n.preferAlias === !0 ? n.preferredAlias : t,
|
|
214
|
-
n.preferAlias === !0 ? t : n.preferredAlias,
|
|
215
|
-
e,
|
|
216
|
-
d
|
|
217
|
-
), a = t === l ? void 0 : l;
|
|
218
|
-
if (n.isTypeOnly && m !== void 0)
|
|
219
|
-
m.addNamedImport({
|
|
220
|
-
name: t,
|
|
221
|
-
alias: a
|
|
222
|
-
});
|
|
223
|
-
else if (u !== void 0 && (!n.isTypeOnly || u.getDefaultImport() === void 0)) {
|
|
224
|
-
if (u.isTypeOnly() && !n.isTypeOnly) {
|
|
225
|
-
u.setIsTypeOnly(!1);
|
|
226
|
-
for (const p of u.getNamedImports())
|
|
227
|
-
p.setIsTypeOnly(!0);
|
|
228
|
-
}
|
|
229
|
-
u.addNamedImport({
|
|
230
|
-
name: t,
|
|
231
|
-
alias: a,
|
|
232
|
-
isTypeOnly: n.isTypeOnly && !u.isTypeOnly()
|
|
233
|
-
});
|
|
234
|
-
} else
|
|
235
|
-
s[e] ??= {
|
|
236
|
-
afterDeclaration: void 0,
|
|
237
|
-
named: [],
|
|
238
|
-
default: void 0,
|
|
239
|
-
"*": void 0
|
|
240
|
-
}, s[e].afterDeclaration ??= r?.[0], s[e].named.push({
|
|
241
|
-
name: t,
|
|
242
|
-
alias: a,
|
|
243
|
-
isTypeOnly: n.isTypeOnly === !0
|
|
244
|
-
});
|
|
245
|
-
f.push({ specifier: e, requestedName: t, actualName: l });
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function M(e, t, n, r, f, s, d) {
|
|
249
|
-
if (r === void 0)
|
|
250
|
-
return;
|
|
251
|
-
const o = n.name ?? t, m = n.specifier ?? e, u = t === "default";
|
|
252
|
-
if (u || t === "*") {
|
|
253
|
-
for (const l of r) {
|
|
254
|
-
const a = u ? l.getDefaultImport() : l.getNamespaceImport();
|
|
255
|
-
if (a === void 0)
|
|
256
|
-
continue;
|
|
257
|
-
if (n.isTypeOnly === !1 && l.isTypeOnly()) {
|
|
258
|
-
l.setIsTypeOnly(!1);
|
|
259
|
-
for (const i of l.getNamedImports())
|
|
260
|
-
i.setIsTypeOnly(!0);
|
|
261
|
-
}
|
|
262
|
-
let p = o;
|
|
263
|
-
if (o !== t) {
|
|
264
|
-
const i = x(o, t, e, d);
|
|
265
|
-
o === i ? a.rename(o) : p = a.getText();
|
|
266
|
-
} else
|
|
267
|
-
p = a.getText();
|
|
268
|
-
e !== m && (l.getNamedImports().length === 0 ? l.setModuleSpecifier(m) : (u ? l.removeDefaultImport() : l.removeNamespaceImport(), s[m] ??= {
|
|
269
|
-
afterDeclaration: void 0,
|
|
270
|
-
named: [],
|
|
271
|
-
default: void 0,
|
|
272
|
-
"*": void 0
|
|
273
|
-
}, s[m].afterDeclaration ??= l, s[m][t] = {
|
|
274
|
-
name: p,
|
|
275
|
-
isTypeOnly: l.isTypeOnly()
|
|
276
|
-
})), f.push({
|
|
277
|
-
specifier: m,
|
|
278
|
-
requestedName: t,
|
|
279
|
-
actualName: p
|
|
280
|
-
});
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
for (const l of r)
|
|
286
|
-
for (const a of l.getNamedImports()) {
|
|
287
|
-
if (a.getNameNode().getText() !== t)
|
|
288
|
-
continue;
|
|
289
|
-
if (n.isTypeOnly === !1) {
|
|
290
|
-
if (a.isTypeOnly())
|
|
291
|
-
a.setIsTypeOnly(!1);
|
|
292
|
-
else if (l.isTypeOnly()) {
|
|
293
|
-
l.setIsTypeOnly(!1);
|
|
294
|
-
for (const c of l.getNamedImports())
|
|
295
|
-
c !== a && c.setIsTypeOnly(!0);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
let p = o;
|
|
299
|
-
const i = a.getAliasNode();
|
|
300
|
-
if (o !== t)
|
|
301
|
-
if (i === void 0) {
|
|
302
|
-
const c = x(o, t, e, d);
|
|
303
|
-
o === c ? a.getNameNode().asKind(y.Identifier)?.rename(o) : (a.setAlias(t), a.getNameNode().replaceWithText(o), p = t);
|
|
304
|
-
} else
|
|
305
|
-
a.getNameNode().replaceWithText(o), p = i.getText();
|
|
306
|
-
if (m !== e) {
|
|
307
|
-
const g = (b(h.project.projectData) || l.getModuleSpecifierValue().endsWith(".js")) && m.startsWith("@arcgis/core") ? `${m}.js` : m;
|
|
308
|
-
l.getNamedImports().length === 1 && l.getDefaultImport() === void 0 ? l.setModuleSpecifier(g) : (s[g] ??= {
|
|
309
|
-
afterDeclaration: void 0,
|
|
310
|
-
named: [],
|
|
311
|
-
default: void 0,
|
|
312
|
-
"*": void 0
|
|
313
|
-
}, s[g].afterDeclaration ??= r?.[0], s[g].named.push({
|
|
314
|
-
name: o,
|
|
315
|
-
alias: o === p ? void 0 : p,
|
|
316
|
-
isTypeOnly: a.isTypeOnly()
|
|
317
|
-
}), a.remove());
|
|
318
|
-
}
|
|
319
|
-
f.push({
|
|
320
|
-
specifier: m,
|
|
321
|
-
requestedName: o,
|
|
322
|
-
actualName: i?.getText() ?? p
|
|
323
|
-
});
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
function x(e, t, n, r) {
|
|
328
|
-
if (e !== void 0) {
|
|
329
|
-
if (!r.has(e) && !O.has(e))
|
|
330
|
-
return r.add(e), e;
|
|
331
|
-
if (t !== void 0)
|
|
332
|
-
return x(t, void 0, n, r);
|
|
333
|
-
}
|
|
334
|
-
n.startsWith("@arcgis/core") && (n = `arcgisCore${n.slice(12)}`);
|
|
335
|
-
const f = n.split("/");
|
|
336
|
-
let s = e ?? "";
|
|
337
|
-
for (let d = f.length - 1; d >= 0; d--) {
|
|
338
|
-
const o = f[d].replaceAll(W, "");
|
|
339
|
-
if (o !== s && (s = o + q(s), !r.has(s) && !O.has(s)))
|
|
340
|
-
return r.add(s), s;
|
|
341
|
-
}
|
|
342
|
-
for (let d = 2; ; d++) {
|
|
343
|
-
const o = s + d;
|
|
344
|
-
if (!r.has(o) && !O.has(o))
|
|
345
|
-
return r.add(o), o;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
const W = /[^a-zA-Z0-9$_]/gu, R = (e) => e.startsWith(".") ? e : `./${e}`, O = /* @__PURE__ */ new Set();
|
|
349
|
-
let P;
|
|
350
|
-
function _(e) {
|
|
351
|
-
if (h.project !== void 0)
|
|
352
|
-
throw Error(
|
|
353
|
-
"A different ts-morph Project is already in use. Dispose of it before creating a new one. Example: using project = createProjectInstance(...)"
|
|
354
|
-
);
|
|
355
|
-
const t = h.codemod.meta.needsTypeInformation, n = new j({
|
|
356
|
-
// If tsconfig is missing, or project is untyped, use a permissive and
|
|
357
|
-
// compatible default config
|
|
358
|
-
compilerOptions: e.typeScriptConfig?.compilerOptions ?? {
|
|
359
|
-
...C,
|
|
360
|
-
// Read types from JSDoc annotations if present
|
|
361
|
-
checkJs: t
|
|
362
|
-
},
|
|
363
|
-
// We take care of reading the config file
|
|
364
|
-
tsConfigFilePath: void 0,
|
|
365
|
-
// We add files manually below
|
|
366
|
-
skipAddingFilesFromTsConfig: !0,
|
|
367
|
-
// We call this manually if needed below.
|
|
368
|
-
skipFileDependencyResolution: !0,
|
|
369
|
-
skipLoadingLibFiles: !t
|
|
370
|
-
});
|
|
371
|
-
for (const s of e.filePaths)
|
|
372
|
-
n.addSourceFileAtPath(s);
|
|
373
|
-
t && n.resolveSourceFileDependencies();
|
|
374
|
-
const r = T.relative(process.cwd(), e.cwd);
|
|
375
|
-
w(
|
|
376
|
-
"info",
|
|
377
|
-
r === "" ? process.cwd() : r,
|
|
378
|
-
`Running the codemod on ${S("blue", String(e.filePaths.length))} file${e.filePaths.length !== 1 ? "s" : ""}${e.packageJson?.contents.name === void 0 ? "" : ` from ${S("blue", e.packageJson.contents.name)}`}`
|
|
379
|
-
);
|
|
380
|
-
const f = {
|
|
381
|
-
[Symbol.dispose]() {
|
|
382
|
-
n.saveSync(), n.getRootDirectories().forEach((s) => s.forget()), h.project = void 0;
|
|
383
|
-
},
|
|
384
|
-
projectData: e,
|
|
385
|
-
// Any files added after projectData.filePaths are supporting files for type
|
|
386
|
-
// checking, but are not codemod targets.
|
|
387
|
-
getCodemodFiles: () => n.getSourceFiles().slice(0, e.filePaths.length),
|
|
388
|
-
tsMorph: n
|
|
389
|
-
};
|
|
390
|
-
return h.project = f, f;
|
|
391
|
-
}
|
|
392
|
-
export {
|
|
393
|
-
A as a,
|
|
394
|
-
_ as c,
|
|
395
|
-
K as f,
|
|
396
|
-
Z as p,
|
|
397
|
-
E as u
|
|
398
|
-
};
|