@arcgis/codemod 5.0.0-next.162
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/LICENSE.md +17 -0
- package/README.md +78 -0
- package/dist/cli-DB4-Ai2J.js +256 -0
- package/dist/cli.js +6 -0
- package/dist/codemod-ZSjsrLkq.js +6077 -0
- package/dist/codemod-mjvq6uf5.js +156 -0
- package/dist/useProjectInstance-CK5Fhtu-.js +398 -0
- package/package.json +24 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
var m = (o, i) => (i = Symbol[o]) ? i : Symbol.for("Symbol." + o), d = (o) => {
|
|
2
|
+
throw TypeError(o);
|
|
3
|
+
};
|
|
4
|
+
var p = (o, i, r) => {
|
|
5
|
+
if (i != null) {
|
|
6
|
+
typeof i != "object" && typeof i != "function" && d("Object expected");
|
|
7
|
+
var a, t;
|
|
8
|
+
r && (a = i[m("asyncDispose")]), a === void 0 && (a = i[m("dispose")], r && (t = a)), typeof a != "function" && d("Object not disposable"), t && (a = function() {
|
|
9
|
+
try {
|
|
10
|
+
t.call(this);
|
|
11
|
+
} catch (s) {
|
|
12
|
+
return Promise.reject(s);
|
|
13
|
+
}
|
|
14
|
+
}), o.push([r, a, i]);
|
|
15
|
+
} else r && o.push([r]);
|
|
16
|
+
return i;
|
|
17
|
+
}, f = (o, i, r) => {
|
|
18
|
+
var a = typeof SuppressedError == "function" ? SuppressedError : function(e, n, c, l) {
|
|
19
|
+
return l = Error(c), l.name = "SuppressedError", l.error = e, l.suppressed = n, l;
|
|
20
|
+
}, t = (e) => i = r ? new a(e, i, "An error was suppressed during disposal") : (r = !0, e), s = (e) => {
|
|
21
|
+
for (; e = o.pop(); )
|
|
22
|
+
try {
|
|
23
|
+
var n = e[1] && e[1].call(e[2]);
|
|
24
|
+
if (e[0]) return Promise.resolve(n).then(s, (c) => (t(c), s()));
|
|
25
|
+
} catch (c) {
|
|
26
|
+
t(c);
|
|
27
|
+
}
|
|
28
|
+
if (r) throw i;
|
|
29
|
+
};
|
|
30
|
+
return s();
|
|
31
|
+
};
|
|
32
|
+
import { f as k, c as u, p as E } from "./useProjectInstance-CK5Fhtu-.js";
|
|
33
|
+
import { log as g } from "@arcgis/toolkit/log";
|
|
34
|
+
import { writeFile as b } from "node:fs/promises";
|
|
35
|
+
import { p as h, g as y } from "./cli-DB4-Ai2J.js";
|
|
36
|
+
async function L(o, i) {
|
|
37
|
+
const r = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const a of o) {
|
|
39
|
+
const t = a.packageJson;
|
|
40
|
+
if (t === void 0 || r.has(t.filePath))
|
|
41
|
+
continue;
|
|
42
|
+
r.add(t.filePath);
|
|
43
|
+
const s = t.contents;
|
|
44
|
+
try {
|
|
45
|
+
const e = await i(s, t.filePath);
|
|
46
|
+
s !== e && await b(t.filePath, `${JSON.stringify(e, null, 2)}
|
|
47
|
+
`, "utf8");
|
|
48
|
+
} catch (e) {
|
|
49
|
+
process.exitCode = 1, g(
|
|
50
|
+
"error",
|
|
51
|
+
k(t.filePath),
|
|
52
|
+
`Error occurred while migrating: ${String(e)}`,
|
|
53
|
+
typeof e == "object" && e !== null && "stack" in e ? { detail: { stack: e.stack } } : void 0
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function P(o, i) {
|
|
59
|
+
for (const r of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
60
|
+
const a = o[r];
|
|
61
|
+
if (a) {
|
|
62
|
+
const t = i(a, r);
|
|
63
|
+
t !== a && (o = { ...o, [r]: t });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return o;
|
|
67
|
+
}
|
|
68
|
+
const C = {
|
|
69
|
+
meta: {
|
|
70
|
+
needsTypeInformation: !1
|
|
71
|
+
},
|
|
72
|
+
async run(o) {
|
|
73
|
+
await L(
|
|
74
|
+
o,
|
|
75
|
+
(s) => P(
|
|
76
|
+
s,
|
|
77
|
+
(e) => e["@arcgis/components-utils"] ? {
|
|
78
|
+
...e,
|
|
79
|
+
"@arcgis/components-utils": void 0,
|
|
80
|
+
"@arcgis/toolkit": e["@arcgis/components-utils"]
|
|
81
|
+
} : e
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
for (const s of o) {
|
|
85
|
+
var i = [];
|
|
86
|
+
try {
|
|
87
|
+
const e = p(i, u(s));
|
|
88
|
+
for (const n of e.getCodemodFiles())
|
|
89
|
+
E(n, {
|
|
90
|
+
"@arcgis/components-utils": {
|
|
91
|
+
// Deprecated
|
|
92
|
+
setFocusOnElement: [{ do: "deprecate" }, { do: "rename", specifier: "@arcgis/toolkit/dom" }],
|
|
93
|
+
setValuesInString: [{ do: "deprecate" }, { do: "rename", specifier: "@arcgis/toolkit/string" }],
|
|
94
|
+
IHandle: [{ do: "deprecate" }, { do: "rename", specifier: "@arcgis/toolkit/type" }],
|
|
95
|
+
Deferred: [{ do: "deprecate" }, { do: "rename", specifier: "@arcgis/toolkit/promise" }],
|
|
96
|
+
// Renamed
|
|
97
|
+
addLTRMark: { do: "rename", specifier: "@arcgis/toolkit/string", name: "addLtrMark" },
|
|
98
|
+
getElementTheme: { do: "rename", specifier: "@arcgis/toolkit/dom", name: "unsafeGetCalciteModeName" },
|
|
99
|
+
getElementDir: { do: "rename", specifier: "@arcgis/toolkit/dom", name: "unsafeGetElementDirection" },
|
|
100
|
+
unsafeGetModeName: { do: "rename", specifier: "@arcgis/toolkit/dom", name: "unsafeGetCalciteModeName" },
|
|
101
|
+
getElementLocales: { do: "rename", specifier: "@arcgis/toolkit/intl", name: "getElementLocale" },
|
|
102
|
+
LocaleObserver: { do: "rename", specifier: "@arcgis/toolkit/intl", name: "LocaleObserverResult" },
|
|
103
|
+
Nil: { do: "rename", specifier: "@arcgis/toolkit/type", name: "nil" },
|
|
104
|
+
closestElement: { do: "rename", specifier: "@arcgis/toolkit/dom", name: "getClosestElement" },
|
|
105
|
+
extractMinorVersion: { do: "rename", specifier: "@arcgis/toolkit/string", name: "getMinorVersion" },
|
|
106
|
+
isURL: { do: "rename", specifier: "@arcgis/toolkit/string", name: "isUrl" },
|
|
107
|
+
mappedFind: { do: "rename", specifier: "@arcgis/toolkit/array" },
|
|
108
|
+
classes: { do: "rename", specifier: "@arcgis/toolkit/dom" },
|
|
109
|
+
// Relocated
|
|
110
|
+
observeAncestorsMutation: { do: "rename", specifier: "@arcgis/toolkit/dom" },
|
|
111
|
+
getElementAttribute: { do: "rename", specifier: "@arcgis/toolkit/dom" },
|
|
112
|
+
FocusableElement: { do: "rename", specifier: "@arcgis/toolkit/dom" },
|
|
113
|
+
focusElement: { do: "rename", specifier: "@arcgis/toolkit/dom" },
|
|
114
|
+
devToolsAwareTimeout: { do: "rename", specifier: "@arcgis/toolkit/promise" },
|
|
115
|
+
isEsriInternalEnv: { do: "rename", specifier: "@arcgis/toolkit/error" },
|
|
116
|
+
safeCall: { do: "rename", specifier: "@arcgis/toolkit/error" },
|
|
117
|
+
safeAsyncCall: { do: "rename", specifier: "@arcgis/toolkit/error" },
|
|
118
|
+
generateGuid: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
119
|
+
getPreamble: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
120
|
+
quoteString: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
121
|
+
createFilterExpression: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
122
|
+
kebabToPascal: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
123
|
+
camelToKebab: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
124
|
+
camelToHuman: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
125
|
+
capitalize: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
126
|
+
uncapitalize: { do: "rename", specifier: "@arcgis/toolkit/string" },
|
|
127
|
+
GenericT9nStrings: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
128
|
+
supportedLocales: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
129
|
+
SupportedLocale: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
130
|
+
defaultLocale: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
131
|
+
fetchT9nStringsBundle: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
132
|
+
normalizeLocale: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
133
|
+
startLocaleObserver: { do: "rename", specifier: "@arcgis/toolkit/intl" },
|
|
134
|
+
isNotNull: { do: "rename", specifier: "@arcgis/toolkit/predicate" },
|
|
135
|
+
isNotUndefined: { do: "rename", specifier: "@arcgis/toolkit/predicate" },
|
|
136
|
+
debounce: { do: "rename", specifier: "@arcgis/toolkit/function" },
|
|
137
|
+
identity: { do: "rename", specifier: "@arcgis/toolkit/function" },
|
|
138
|
+
hasSameOrigin: { do: "rename", specifier: "@arcgis/toolkit/url" }
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
} catch (r) {
|
|
142
|
+
var a = r, t = !0;
|
|
143
|
+
} finally {
|
|
144
|
+
f(i, a, t);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
h(), g(
|
|
148
|
+
"info",
|
|
149
|
+
y.codemodName,
|
|
150
|
+
"Next step: run npm install/pnpm install/yarn install to get @arcgis/toolkit package installed."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
export {
|
|
155
|
+
C as codemod
|
|
156
|
+
};
|
|
@@ -0,0 +1,398 @@
|
|
|
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-DB4-Ai2J.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
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcgis/codemod",
|
|
3
|
+
"version": "5.0.0-next.162",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./package.json": "./package.json"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
11
|
+
"bin": "./dist/cli.js",
|
|
12
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
15
|
+
"commander": "^14.0.0",
|
|
16
|
+
"tinyglobby": "^0.2.15",
|
|
17
|
+
"ts-morph": "^27.0.2",
|
|
18
|
+
"tslib": "^2.8.1",
|
|
19
|
+
"typescript": "~5.9.3",
|
|
20
|
+
"vite": "^7.2.2",
|
|
21
|
+
"@arcgis/components-build-utils": "5.0.0-next.162",
|
|
22
|
+
"@arcgis/toolkit": "5.0.0-next.162"
|
|
23
|
+
}
|
|
24
|
+
}
|