@arcgis/codemod 5.2.0-next.12 → 5.2.0-next.121

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,240 @@
1
+ import { readFile as E } from "node:fs/promises";
2
+ import { log as w } from "@arcgis/toolkit/log";
3
+ import { a as T, b as h, c as P, d as j, e as A, f as y } from "./config-BP6HDIQa.js";
4
+ import { collectOutput as m } from "@arcgis/node-toolkit/shell";
5
+ const C = `<!-- ${h} -->`, O = `<!-- ${h}`, M = 65536;
6
+ function b(n) {
7
+ const e = /* @__PURE__ */ new Map();
8
+ for (const t of n.findings) {
9
+ const o = f(t.codeowners), s = o.join(","), i = e.get(s) ?? [];
10
+ i.push({ ...t, codeowners: o }), e.set(s, i);
11
+ }
12
+ return [...e.entries()].map(([t, o]) => {
13
+ const s = t === "" ? [] : t.split(","), i = B(n, o);
14
+ return {
15
+ title: T[n.kind],
16
+ owners: s,
17
+ assignees: s.filter((r) => /^@[^/@\s]+$/u.test(r)).map((r) => r.slice(1)),
18
+ chunks: N(i, M, R(s))
19
+ };
20
+ }).sort((t, o) => t.title.localeCompare(o.title));
21
+ }
22
+ function B(n, e) {
23
+ const t = P[n.kind], o = f(e.flatMap((a) => a.codeowners)).filter(
24
+ (a) => /^@[^/@\s]+\/[^@\s]+$/u.test(a)
25
+ ), s = o.length === 0 ? "" : `
26
+
27
+ CODEOWNERS: ${o.join(", ")}`, r = [...Map.groupBy(e, (a) => a.package).entries()].sort(([a], [p]) => a.localeCompare(p)).map(([a, p]) => {
28
+ const S = [...Map.groupBy(p, (u) => D(n.kind, u)).entries()].sort(([u], [l]) => u.localeCompare(l)).map(([, u]) => {
29
+ const [{ api: l }] = u, $ = [
30
+ ...new Set(
31
+ u.map(({ reason: c }) => c).filter((c) => c !== null && c !== "")
32
+ )
33
+ ], x = $.length === 0 ? "" : ` - ${$.map(G).join(" ")}`, d = [
34
+ ...new Set(
35
+ u.toSorted((c, g) => c.file.localeCompare(g.file) || c.line - g.line).map((c) => J(n.repository, n.ref, c.file, c.line))
36
+ )
37
+ ], v = d.length === 1 ? ` ${d[0]}` : d.map((c) => ` - ${c}`).join(`
38
+ `);
39
+ return `- [ ] \`${l}\`${x}
40
+ ${v}`;
41
+ });
42
+ return `#### ${a}'s deprecations
43
+
44
+ ${S.join(`
45
+ `)}`;
46
+ });
47
+ return `${t}${s}
48
+
49
+ ${j}
50
+
51
+ ${r.join(`
52
+
53
+ `)}`;
54
+ }
55
+ function N(n, e = M, t = C) {
56
+ const o = `${t}
57
+ `, s = e - o.length;
58
+ if (s < 1)
59
+ throw new Error("Issue content limit is too small for the managed marker.");
60
+ const i = [];
61
+ let r = n;
62
+ for (; r.length > s; ) {
63
+ const a = r.lastIndexOf(`
64
+ `, s), p = a > 0 ? a : s;
65
+ i.push(o + r.slice(0, p)), r = r.slice(p + (a > 0 ? 1 : 0));
66
+ }
67
+ return i.push(o + r), i;
68
+ }
69
+ function R(n) {
70
+ return n.length === 0 ? C : `<!-- ${h} ${f(n).join(",")} -->`;
71
+ }
72
+ function f(n) {
73
+ return [...new Set(n)].sort((e, t) => e.localeCompare(t));
74
+ }
75
+ function D(n, e) {
76
+ return n === "definitions" ? `${e.api}\0${L(e.file)}` : e.api;
77
+ }
78
+ function L(n) {
79
+ const e = "/src/", t = "/dist/", o = n.lastIndexOf(e), s = n.lastIndexOf(t), i = Math.max(o, s), r = s > o ? t : e;
80
+ return (i === -1 ? n : n.slice(i + r.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
81
+ }
82
+ function G(n) {
83
+ const e = [], t = (i) => `\0${e.push(i) - 1}\0`, s = n.replaceAll(`\r
84
+ `, `
85
+ `).replaceAll("\r", `
86
+ `).replace(
87
+ /\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
88
+ (i, r, a) => t(`[${I(r)}](${a})`)
89
+ ).replace(/https?:\/\/[^\s<>()]+/gu, (i) => {
90
+ const r = /[.,;:!?]+$/u.exec(i)?.[0] ?? "";
91
+ return `${t(i.slice(0, -r.length || void 0))}${r}`;
92
+ });
93
+ return I(s).replace(/\0(\d+)\0/gu, (i, r) => e[Number(r)]).replaceAll(`
94
+ `, `
95
+ `);
96
+ }
97
+ function I(n) {
98
+ return n.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
99
+ }
100
+ function J(n, e, t, o) {
101
+ const s = e.split("/").map(encodeURIComponent).join("/"), i = t.split("/").map(encodeURIComponent).join("/");
102
+ return `https://${n}/blob/${s}/${i}#L${o}`;
103
+ }
104
+ class z {
105
+ #s;
106
+ #e;
107
+ constructor(e) {
108
+ const [t, o, s, ...i] = e.split("/");
109
+ if (t === void 0 || o === void 0 || s === void 0 || i.length > 0)
110
+ throw new Error(`Invalid repository: ${e}`);
111
+ this.#s = t, this.#e = `${o}/${s}`;
112
+ }
113
+ async #t(e, t, o) {
114
+ if (process.env.VITEST !== void 0)
115
+ throw new Error("GitHub requests are disabled while running Vitest.");
116
+ const s = await m(
117
+ "gh",
118
+ ["api", "--hostname", this.#s, "--method", e, t, ...o === void 0 ? [] : ["--input", "-"]],
119
+ o === void 0 ? {} : { input: JSON.stringify(o) }
120
+ );
121
+ return s === "" ? void 0 : JSON.parse(s);
122
+ }
123
+ async listOpenIssues(e) {
124
+ const t = await m("gh", [
125
+ "api",
126
+ "--hostname",
127
+ this.#s,
128
+ "--method",
129
+ "GET",
130
+ "--paginate",
131
+ "--slurp",
132
+ "-f",
133
+ `q="${e}" in:title repo:${this.#e} is:issue is:open`,
134
+ "-f",
135
+ "per_page=100",
136
+ "/search/issues"
137
+ ]);
138
+ return JSON.parse(t).flatMap(({ items: o }) => o);
139
+ }
140
+ async createIssue(e, t, o, s) {
141
+ return await this.#t("POST", `/repos/${this.#e}/issues`, {
142
+ title: e,
143
+ body: t,
144
+ assignees: o,
145
+ labels: s,
146
+ type: A
147
+ });
148
+ }
149
+ async updateIssueBody(e, t) {
150
+ await this.#t("PATCH", `/repos/${this.#e}/issues/${e}`, { body: t });
151
+ }
152
+ async listComments(e) {
153
+ const t = await m("gh", [
154
+ "api",
155
+ "--hostname",
156
+ this.#s,
157
+ "--method",
158
+ "GET",
159
+ "--paginate",
160
+ "--slurp",
161
+ `/repos/${this.#e}/issues/${e}/comments?per_page=100`
162
+ ]);
163
+ return JSON.parse(t).flat();
164
+ }
165
+ async createComment(e, t) {
166
+ await this.#t("POST", `/repos/${this.#e}/issues/${e}/comments`, { body: t });
167
+ }
168
+ async updateComment(e, t) {
169
+ await this.#t("PATCH", `/repos/${this.#e}/issues/comments/${e}`, { body: t });
170
+ }
171
+ async deleteComment(e) {
172
+ await this.#t("DELETE", `/repos/${this.#e}/issues/comments/${e}`);
173
+ }
174
+ }
175
+ async function Z(n, e, t = 0, o, s = []) {
176
+ const i = W(await E(n, "utf8")), r = H(b(i), t, o);
177
+ if (e) {
178
+ process.stdout.write(`${_(r)}
179
+ `);
180
+ return;
181
+ }
182
+ const a = new z(i.repository);
183
+ await U(r, a, s);
184
+ }
185
+ function H(n, e, t) {
186
+ return n.slice(e, t === void 0 ? void 0 : e + t);
187
+ }
188
+ async function U(n, e, t = []) {
189
+ const o = /* @__PURE__ */ new Map();
190
+ for (const s of n) {
191
+ let i = o.get(s.title);
192
+ i === void 0 && (i = await e.listOpenIssues(s.title), o.set(s.title, i));
193
+ const r = q(i, s);
194
+ let a;
195
+ r === void 0 ? (a = (await e.createIssue(s.title, s.chunks[0], s.assignees, t)).number, w("info", y, `Created issue #${a}: ${s.title}`)) : (a = r.number, r.body !== s.chunks[0] && (await e.updateIssueBody(a, s.chunks[0]), w("info", y, `Updated issue #${a}: ${s.title}`))), await V(e, a, s.chunks.slice(1));
196
+ }
197
+ }
198
+ function W(n) {
199
+ const e = JSON.parse(n);
200
+ if (e.kind !== "usages" && e.kind !== "definitions" || typeof e.repository != "string" || typeof e.ref != "string" || !Array.isArray(e.findings))
201
+ throw new Error("Invalid deprecation audit JSON.");
202
+ return e;
203
+ }
204
+ function _(n) {
205
+ return n.map(
206
+ (e) => `CODEOWNERS: ${e.owners.length === 0 ? "unowned" : e.owners.join(", ")}
207
+ ASSIGNEES: ${e.assignees.length === 0 ? "none" : e.assignees.join(", ")}
208
+ TITLE: ${e.title}
209
+
210
+ ${e.chunks.map((t, o) => `--- ${o === 0 ? "BODY" : "COMMENT"} (${o + 1}/${e.chunks.length}) ---
211
+ ${t}`).join(`
212
+
213
+ `)}`
214
+ ).join(`
215
+
216
+ `);
217
+ }
218
+ function q(n, e) {
219
+ const t = k(e.chunks[0]);
220
+ return n.find((o) => o.title === e.title && k(o.body) === t);
221
+ }
222
+ function k(n) {
223
+ const e = n?.split(`
224
+ `, 1)[0];
225
+ return e?.startsWith(O) === !0 ? e : void 0;
226
+ }
227
+ async function V(n, e, t) {
228
+ const o = (await n.listComments(e)).filter(({ body: s }) => s.startsWith(O));
229
+ for (const [s, i] of t.entries()) {
230
+ const r = o[s];
231
+ r === void 0 ? await n.createComment(e, i) : r.body !== i && await n.updateComment(r.id, i);
232
+ }
233
+ for (const s of o.slice(t.length))
234
+ await n.deleteComment(s.id);
235
+ }
236
+ export {
237
+ H as sliceIssuePlans,
238
+ Z as syncDeprecationIssues,
239
+ U as synchronizeIssuePlans
240
+ };
@@ -0,0 +1,48 @@
1
+ import { Project as p } from "ts-morph";
2
+ import { log as d } from "@arcgis/toolkit/log";
3
+ import { path as f } from "@arcgis/node-toolkit/path";
4
+ import { g as i, d as m } from "./cli-DfAgo-jb.js";
5
+ import { styleText as s } from "node:util";
6
+ function y(e, c = !0) {
7
+ if (i.project !== void 0)
8
+ throw Error(
9
+ "A different ts-morph Project is already in use. Dispose of it before creating a new one. Example: using project = createProjectInstance(...)"
10
+ );
11
+ const n = i.codemod.meta.needsTypeInformation, t = new p({
12
+ // If tsconfig is missing, or project is untyped, use a permissive and
13
+ // compatible default config
14
+ compilerOptions: e.typeScriptConfig?.compilerOptions ?? {
15
+ ...m,
16
+ // Read types from JSDoc annotations if present
17
+ checkJs: n
18
+ },
19
+ // We take care of reading the config file
20
+ tsConfigFilePath: void 0,
21
+ // We add files manually below
22
+ skipAddingFilesFromTsConfig: !0,
23
+ // We call this manually if needed below.
24
+ skipFileDependencyResolution: !0,
25
+ skipLoadingLibFiles: !n
26
+ }), l = e.filePaths.map((o) => t.addSourceFileAtPath(o));
27
+ if (n && t.resolveSourceFileDependencies(), c) {
28
+ const o = f.relative(process.cwd(), e.cwd);
29
+ process.stdout.write(""), d(
30
+ "info",
31
+ s("blue", o === "" ? process.cwd() : o),
32
+ `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)}`}`
33
+ );
34
+ }
35
+ const r = {
36
+ [Symbol.dispose]() {
37
+ t.saveSync(), t.getRootDirectories().forEach((o) => o.forget()), i.project = void 0;
38
+ },
39
+ projectData: e,
40
+ // Resolved dependencies support type checking but are not codemod targets.
41
+ getCodemodFiles: () => l,
42
+ tsMorph: t
43
+ };
44
+ return i.project = r, r;
45
+ }
46
+ export {
47
+ y as c
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/codemod",
3
- "version": "5.2.0-next.12",
3
+ "version": "5.2.0-next.121",
4
4
  "description": "A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,17 +9,20 @@
9
9
  "files": [
10
10
  "dist/"
11
11
  ],
12
- "bin": "./bin/cli.js",
13
12
  "license": "SEE LICENSE IN LICENSE.md",
14
13
  "dependencies": {
15
- "@commander-js/extra-typings": "^14.0.0",
16
- "commander": "^14.0.0",
17
- "tinyglobby": "^0.2.15",
14
+ "@arcgis/api-extractor": "5.2.0-next.121",
15
+ "@arcgis/node-toolkit": "5.2.0-next.121",
16
+ "@arcgis/toolkit": "5.2.0-next.121",
17
+ "@commander-js/extra-typings": "^15.0.0",
18
+ "commander": "^15.0.0",
19
+ "picomatch": "^4.0.4",
20
+ "tinyglobby": "~0.2.17",
18
21
  "ts-morph": "^28.0.0",
19
22
  "tslib": "^2.8.1",
20
- "typescript": "~6.0.2",
21
- "@arcgis/components-build-utils": "5.2.0-next.12",
22
- "@arcgis/toolkit": "5.2.0-next.12",
23
- "@arcgis/api-extractor": "5.2.0-next.12"
23
+ "typescript": "~6.0.3"
24
+ },
25
+ "bin": {
26
+ "codemod": "./bin/cli.js"
24
27
  }
25
28
  }
@@ -1,354 +0,0 @@
1
- import { path as T } from "@arcgis/components-build-utils";
2
- import { SyntaxKind as g } from "ts-morph";
3
- import { g as x } from "./cli-C2S8UH1H.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
- };