@arcgis/codemod 5.2.0-next.98 → 6.0.0-next.0
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 +83 -33
- package/dist/chunks/actions.js +395 -0
- package/dist/chunks/cli.js +380 -0
- package/dist/{codemod-BWZ_CtnT.js → chunks/codemod.js} +3 -3
- package/dist/chunks/codemod2.js +417 -0
- package/dist/{codemod-v9PNv3xH.js → chunks/codemod3.js} +2 -2
- package/dist/chunks/codemod4.js +88 -0
- package/dist/{codemod-Bk-5zHaA.js → chunks/codemod5.js} +44 -76
- package/dist/{codemod-DgXtIN7a.js → chunks/codemod6.js} +1 -1
- package/dist/{codemod-DkEa3nwr.js → chunks/codemod7.js} +19 -18
- package/dist/{codemod-B9tWi9M_.js → chunks/codemod8.js} +3 -3
- package/dist/chunks/format.js +255 -0
- package/dist/chunks/hardcodedBehavior.js +93 -0
- package/dist/chunks/index.js +404 -0
- package/dist/chunks/index2.js +143 -0
- package/dist/chunks/log.js +11 -0
- package/dist/chunks/packageJson.js +39 -0
- package/dist/chunks/sync.js +165 -0
- package/dist/chunks/useProjectInstance.js +51 -0
- package/dist/cli.js +3 -2
- package/package.json +4 -4
- package/dist/actions-CE74rP-z.js +0 -354
- package/dist/cli-x1Uhjnb_.js +0 -269
- package/dist/useProjectInstance-BAlKm1ad.js +0 -47
package/README.md
CHANGED
|
@@ -2,30 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.
|
|
4
4
|
|
|
5
|
-
This package provides automated refactors to help migrate away from deprecated or legacy patterns.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- Converts global namespace types to explicit `@arcgis/core` imports
|
|
11
|
-
- Normalizes legacy Calcite icon names
|
|
12
|
-
- Detects edge cases and warns when changes can’t be safely automated
|
|
13
|
-
- Respects `.gitignore` by default
|
|
5
|
+
This package provides automated refactors to help migrate away from deprecated or legacy patterns.
|
|
6
|
+
These include codemods for removing the `__esri` namespace and
|
|
7
|
+
converting global namespace types to explicit `@arcgis/core` imports,
|
|
8
|
+
normalizing legacy Calcite icon names,
|
|
9
|
+
and updating geometry operator usage.
|
|
14
10
|
|
|
15
11
|
## Requirements
|
|
16
12
|
|
|
17
13
|
- Node.js 24
|
|
18
14
|
- A project using the ArcGIS Maps SDK for JavaScript
|
|
19
|
-
- This codemod operates exclusively on TypeScript files.
|
|
15
|
+
- This codemod operates exclusively on TypeScript files. You do not need to run this tool if the project does not use TypeScript.
|
|
20
16
|
|
|
21
17
|
## Before you begin
|
|
22
18
|
|
|
19
|
+
Ensure your project's dependencies are up to date, for example by running `pnpm install`.
|
|
20
|
+
|
|
23
21
|
If your project uses **ESLint, Prettier, or other formatters/linters**, run them after the codemod to ensure consistent formatting.
|
|
24
22
|
|
|
25
23
|
> [!Note]
|
|
26
|
-
>
|
|
24
|
+
> Codemods modify files in place and do not provide an interactive dry-run mode. We recommend running it in a project
|
|
25
|
+
> that is under version control (Git) so you can review changes using `git diff` or your IDE’s diff tools. If your
|
|
26
|
+
> project is not under version control, create a backup before running the codemod.
|
|
27
|
+
|
|
28
|
+
By default, codemods run on all TypeScript files in the current directory and subdirectories.
|
|
29
|
+
You can manually run it on a different directory by providing it as an argument.
|
|
30
|
+
|
|
31
|
+
Codemods respect `.gitignore` files and will not modify any files ignored by them.
|
|
32
|
+
|
|
33
|
+
## Available codemods
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
- [`refactor-out-esri-namespace`](#refactor-out-the-__esri-namespace)
|
|
36
|
+
- [`normalize-calcite-icon-names`](#normalize-calcite-icon-names)
|
|
37
|
+
- [`geometry-operator-renames`](#rename-geometry-operators)
|
|
29
38
|
|
|
30
39
|
### Refactor out the `__esri` namespace
|
|
31
40
|
|
|
@@ -33,21 +42,12 @@ The `refactor-out-esri-namespace` codemod replaces `__esri` types with explicit
|
|
|
33
42
|
|
|
34
43
|
> Note: Before running the codemod, update all `@arcgis/*` packages in your `package.json` to the most recent version.
|
|
35
44
|
|
|
36
|
-
Run it in the root of your project:
|
|
45
|
+
Run it in the root of your project or with an explicit target directory:
|
|
37
46
|
|
|
38
47
|
```sh
|
|
39
|
-
npx @arcgis/codemod run refactor-out-esri-namespace
|
|
48
|
+
npx @arcgis/codemod run refactor-out-esri-namespace [<target-directory>]
|
|
40
49
|
```
|
|
41
50
|
|
|
42
|
-
By default, the codemod runs on all TypeScript files in the current directory and subdirectories, excluding files ignored by your `.gitignore`.
|
|
43
|
-
You can manually run it on a different directory by providing an argument:
|
|
44
|
-
|
|
45
|
-
```sh
|
|
46
|
-
npx @arcgis/codemod run refactor-out-esri-namespace target-directory
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
#### What the codemod does
|
|
50
|
-
|
|
51
51
|
**Before:**
|
|
52
52
|
|
|
53
53
|
```tsx
|
|
@@ -74,22 +74,20 @@ The codemod will emit warnings for cases it cannot safely rewrite, including:
|
|
|
74
74
|
- Complex computed or dynamic type usage
|
|
75
75
|
- Unresolvable symbols
|
|
76
76
|
|
|
77
|
-
These will be reported in the console
|
|
77
|
+
These will be reported in the console. Manually review all changes before committing.
|
|
78
78
|
|
|
79
79
|
### Normalize Calcite icon names
|
|
80
80
|
|
|
81
|
-
The `normalize-calcite-icon-names` codemod updates camelCase and legacy Calcite icon names to their normalized
|
|
81
|
+
The `normalize-calcite-icon-names` codemod updates camelCase and legacy Calcite icon names to their normalized
|
|
82
|
+
kebab-case equivalents. It handles icon attributes on Calcite components and traces icon values through variables,
|
|
83
|
+
properties, assignments, function returns, and forwarded component properties. This helps prepare for
|
|
84
|
+
[calcite-design-system#14967](https://github.com/Esri/calcite-design-system/issues/14967) and
|
|
85
|
+
[calcite-design-system#14966](https://github.com/Esri/calcite-design-system/issues/14966).
|
|
82
86
|
|
|
83
|
-
Run it in the root of your project:
|
|
87
|
+
Run it in the root of your project or with an explicit target directory:
|
|
84
88
|
|
|
85
89
|
```sh
|
|
86
|
-
npx @arcgis/codemod run normalize-calcite-icon-names
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
You can also provide a target directory:
|
|
90
|
-
|
|
91
|
-
```sh
|
|
92
|
-
npx @arcgis/codemod run normalize-calcite-icon-names target-directory
|
|
90
|
+
npx @arcgis/codemod run normalize-calcite-icon-names [<target-directory>]
|
|
93
91
|
```
|
|
94
92
|
|
|
95
93
|
**Before:**
|
|
@@ -104,6 +102,58 @@ npx @arcgis/codemod run normalize-calcite-icon-names target-directory
|
|
|
104
102
|
<calcite-button iconStart="3d-glasses" iconEnd="arrow-left-10" />
|
|
105
103
|
```
|
|
106
104
|
|
|
105
|
+
### Rename Geometry Operators
|
|
106
|
+
|
|
107
|
+
In version 5.2, geometry operator exports and option types were renamed to improve consistency and discoverability.
|
|
108
|
+
The `geometry-operator-renames` codemod updates geometry operator calls to use the new names.
|
|
109
|
+
It additionally inlines namespace imports, which are no longer necessary.
|
|
110
|
+
|
|
111
|
+
Run it in the root of your project or with an explicit target directory:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
npx @arcgis/codemod run geometry-operator-renames [<target-directory>]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Before:**
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import * as bufferOperator from "@arcgis/core/geometry/operators/bufferOperator";
|
|
121
|
+
const options: bufferOperator.Options = { unit: "meters" };
|
|
122
|
+
const buffered = bufferOperator.execute(polyline, 250, options);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**After:**
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { bufferExecute, type BufferExecuteOptions } from "@arcgis/core/geometry/operators/bufferOperator";
|
|
129
|
+
const options: BufferExecuteOptions = { unit: "meters" };
|
|
130
|
+
const buffered = bufferExecute(polyline, 250, options);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Versioning
|
|
134
|
+
|
|
135
|
+
The codemods are available until the corresponding deprecated feature is removed.
|
|
136
|
+
If migrating from a much older release, the codemod might no longer be available in the most recent version of the `@arcgis/codemod` package.
|
|
137
|
+
In such cases, run the codemod from an older version, matching the version in the release notes:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
npx @arcgis/codemod@5.2 run refactor-out-esri-namespace
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Troubleshooting
|
|
144
|
+
|
|
145
|
+
Some codemods rely on type information to perform more accurate migrations.
|
|
146
|
+
On large codebases, this may require more RAM than the default Node.js limit.
|
|
147
|
+
If you encounter an out-of-memory error (like `Allocation failed - JavaScript heap out of memory`), re-run the codemod with a higher RAM limit:
|
|
148
|
+
|
|
149
|
+
Example on Linux/macOS:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
NODE_OPTIONS="--max-old-space-size=10240" npx @arcgis/codemod run normalize-calcite-icon-names
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
[Windows command line](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1) and [PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.6) use a different environment variable syntax.
|
|
156
|
+
|
|
107
157
|
## License
|
|
108
158
|
|
|
109
159
|
This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.2/LICENSE.txt.
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { path as x } from "@arcgis/node-toolkit/path";
|
|
2
|
+
import { SyntaxKind as I } from "ts-morph";
|
|
3
|
+
import { g as D } from "./cli.js";
|
|
4
|
+
import { ModuleResolutionKind as K } from "typescript";
|
|
5
|
+
import { a as w } from "./log.js";
|
|
6
|
+
import { capitalize as A } from "@arcgis/toolkit/string";
|
|
7
|
+
import { log as P } from "@arcgis/toolkit/log";
|
|
8
|
+
function j(t) {
|
|
9
|
+
const e = t.typeScriptConfig?.compilerOptions?.moduleResolution ?? K.Bundler;
|
|
10
|
+
return e >= K.Node16 && e <= K.NodeNext;
|
|
11
|
+
}
|
|
12
|
+
function V(t, e) {
|
|
13
|
+
const s = {};
|
|
14
|
+
q(t);
|
|
15
|
+
const { specifiers: i, names: m, lastImportIndex: r } = b(t), l = [], n = {}, c = [];
|
|
16
|
+
let p = j(D.project.projectData);
|
|
17
|
+
for (const [o, f] of Object.entries(e)) {
|
|
18
|
+
let a = i.get(o) ?? (o.startsWith(".") ? i.get(
|
|
19
|
+
x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, o))
|
|
20
|
+
) : void 0);
|
|
21
|
+
if (a === void 0) {
|
|
22
|
+
const y = i.get(`${o}.js`);
|
|
23
|
+
y !== void 0 && (p = !0, a === void 0 ? a = y : a = [...a, ...y]);
|
|
24
|
+
}
|
|
25
|
+
for (const [y, g] of Object.entries(f)) {
|
|
26
|
+
const v = Array.isArray(g) ? g : [g];
|
|
27
|
+
for (const N of v)
|
|
28
|
+
N.do === "deprecate" ? R(y, o, s, a) : N.do === "add" ? C(o, y, N, a, l, n, m) : N.do === "rename" ? E(o, y, N, a, l, n, m) : N.do === "remove-namespace-import" && W(
|
|
29
|
+
o,
|
|
30
|
+
a,
|
|
31
|
+
l,
|
|
32
|
+
n,
|
|
33
|
+
c,
|
|
34
|
+
m
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const d = Object.entries(n);
|
|
39
|
+
let u = r;
|
|
40
|
+
for (let o = 0; o < d.length; o += 1) {
|
|
41
|
+
const [f, a] = d[o], y = f.startsWith(".") ? M(
|
|
42
|
+
x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, f))
|
|
43
|
+
) : f, g = p && y.startsWith("@arcgis/core") ? `${y}.js` : y, v = a.afterDeclaration === void 0 ? u : a.afterDeclaration.getChildIndex() + 1;
|
|
44
|
+
if (a.named.length > 0) {
|
|
45
|
+
let N = !0;
|
|
46
|
+
for (let h = 0; h < a.named.length; h += 1)
|
|
47
|
+
N &&= a.named[h].isTypeOnly;
|
|
48
|
+
t.insertImportDeclaration(v, {
|
|
49
|
+
isTypeOnly: N,
|
|
50
|
+
moduleSpecifier: g,
|
|
51
|
+
namedImports: a.named.map((h) => ({
|
|
52
|
+
name: h.name,
|
|
53
|
+
alias: h.alias,
|
|
54
|
+
isTypeOnly: h.isTypeOnly && !N
|
|
55
|
+
}))
|
|
56
|
+
}), u += 1;
|
|
57
|
+
}
|
|
58
|
+
a.default !== void 0 && (t.insertImportDeclaration(v, {
|
|
59
|
+
isTypeOnly: a.default.isTypeOnly,
|
|
60
|
+
moduleSpecifier: g,
|
|
61
|
+
defaultImport: a.default.name
|
|
62
|
+
}), u += 1), a["*"] !== void 0 && (t.insertImportDeclaration(v, {
|
|
63
|
+
isTypeOnly: a["*"].isTypeOnly,
|
|
64
|
+
moduleSpecifier: g,
|
|
65
|
+
namespaceImport: a["*"].name
|
|
66
|
+
}), u += 1);
|
|
67
|
+
}
|
|
68
|
+
if (Object.keys(s).length > 0) {
|
|
69
|
+
const o = Object.entries(s).map(([f, a]) => `${a.join(", ")} from ${f}`).join("; ");
|
|
70
|
+
P("warn", w(t), `Deprecated API usages found: ${o}`);
|
|
71
|
+
}
|
|
72
|
+
for (const o of c)
|
|
73
|
+
o.remove();
|
|
74
|
+
return l;
|
|
75
|
+
}
|
|
76
|
+
function q(t) {
|
|
77
|
+
const e = t.getChildSyntaxList()?.getFirstChild();
|
|
78
|
+
if (S === e)
|
|
79
|
+
return;
|
|
80
|
+
S = e, O.clear();
|
|
81
|
+
const s = /* @__PURE__ */ new Set();
|
|
82
|
+
i(t);
|
|
83
|
+
function i(m) {
|
|
84
|
+
for (const r of m.getStatements())
|
|
85
|
+
if (r.isKind(I.ImportDeclaration)) {
|
|
86
|
+
const l = r.getDefaultImport(), n = r.getNamespaceImport(), c = r.getNamedImports();
|
|
87
|
+
l && s.add(l.getText()), n && s.add(n.getText());
|
|
88
|
+
for (const p of c)
|
|
89
|
+
s.add(p.getAliasNode()?.getText() ?? p.getName());
|
|
90
|
+
} else r.isKind(I.ImportEqualsDeclaration) ? s.add(r.getName()) : r.isKind(I.ModuleDeclaration) ? i(r) : m.forEachDescendant((l) => {
|
|
91
|
+
if (!l.isKind(I.Identifier))
|
|
92
|
+
return;
|
|
93
|
+
const n = l.getParent();
|
|
94
|
+
if (n.isKind(I.QualifiedName) && n.getLeft() !== l || n.isKind(I.PropertyAccessExpression) && n.getExpression() !== l || (n.isKind(I.PropertyDeclaration) || n.isKind(I.PropertySignature) || n.isKind(I.PropertyAssignment)) && n.getNameNode() === l)
|
|
95
|
+
return;
|
|
96
|
+
const c = l.getText();
|
|
97
|
+
s.has(c) || O.add(l.getText());
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function b(t) {
|
|
102
|
+
const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), i = t.getStatements();
|
|
103
|
+
let m;
|
|
104
|
+
for (let l = 0; l < i.length; l += 1) {
|
|
105
|
+
const n = i[l];
|
|
106
|
+
if (!n.isKind(I.ImportDeclaration)) {
|
|
107
|
+
const a = n.getName?.();
|
|
108
|
+
a !== void 0 && s.add(a);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
m = n;
|
|
112
|
+
const c = n.getModuleSpecifierValue(), p = e.get(c);
|
|
113
|
+
p === void 0 ? e.set(c, [n]) : p.push(n);
|
|
114
|
+
const d = n.getImportClause();
|
|
115
|
+
if (d === void 0)
|
|
116
|
+
continue;
|
|
117
|
+
const u = d.getDefaultImport()?.getText();
|
|
118
|
+
u !== void 0 && s.add(u);
|
|
119
|
+
const o = d.getNamedBindings();
|
|
120
|
+
if (o !== void 0)
|
|
121
|
+
if (o.isKind(I.NamedImports))
|
|
122
|
+
for (const f of o.getElements()) {
|
|
123
|
+
const a = f.getName();
|
|
124
|
+
s.add(a);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const f = o.getName();
|
|
128
|
+
s.add(f);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const r = m === void 0 ? 0 : m.getChildIndex() + 1;
|
|
132
|
+
return { specifiers: e, names: s, lastImportIndex: r };
|
|
133
|
+
}
|
|
134
|
+
function R(t, e, s, i) {
|
|
135
|
+
if (i !== void 0) {
|
|
136
|
+
if (t === "default")
|
|
137
|
+
for (const m of i) {
|
|
138
|
+
const r = m.getDefaultImport();
|
|
139
|
+
if (r !== void 0) {
|
|
140
|
+
s[e] ??= [], s[e].push(r.getText());
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (t === "*")
|
|
145
|
+
for (const m of i) {
|
|
146
|
+
const r = m.getNamespaceImport();
|
|
147
|
+
if (r !== void 0) {
|
|
148
|
+
s[e] ??= [], s[e].push(r.getText());
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
for (const m of i)
|
|
154
|
+
for (const r of m.getNamedImports())
|
|
155
|
+
if (r.getName() === t) {
|
|
156
|
+
s[e] ??= [], s[e].push(r.getName());
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function C(t, e, s, i, m, r, l) {
|
|
162
|
+
const n = e === "default";
|
|
163
|
+
if (n || e === "*") {
|
|
164
|
+
if (i !== void 0)
|
|
165
|
+
for (const p of i) {
|
|
166
|
+
const d = n ? p.getDefaultImport() : p.getNamespaceImport();
|
|
167
|
+
if (d !== void 0) {
|
|
168
|
+
s.isTypeOnly !== !0 && p.isTypeOnly() && p.setIsTypeOnly(!1), m.push({
|
|
169
|
+
specifier: t,
|
|
170
|
+
requestedName: e,
|
|
171
|
+
actualName: d.getText()
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const c = T(s.preferredAlias, void 0, t, l);
|
|
177
|
+
m.push({ specifier: t, requestedName: e, actualName: c }), r[t] ??= {
|
|
178
|
+
afterDeclaration: void 0,
|
|
179
|
+
named: [],
|
|
180
|
+
default: void 0,
|
|
181
|
+
"*": void 0
|
|
182
|
+
}, r[t].afterDeclaration ??= i?.[0], r[t][e] = {
|
|
183
|
+
name: c,
|
|
184
|
+
isTypeOnly: s.isTypeOnly === !0
|
|
185
|
+
};
|
|
186
|
+
} else {
|
|
187
|
+
let c, p;
|
|
188
|
+
if (i !== void 0) {
|
|
189
|
+
let o = !1;
|
|
190
|
+
for (const f of i)
|
|
191
|
+
if (f.getNamespaceImport() === void 0) {
|
|
192
|
+
p ??= f, c ??= f.isTypeOnly() && f.getDefaultImport() === void 0 ? f : void 0;
|
|
193
|
+
for (const a of f.getNamedImports())
|
|
194
|
+
if (a.getNameNode().getText() === e) {
|
|
195
|
+
if (o = !0, s.isTypeOnly !== !0) {
|
|
196
|
+
if (a.isTypeOnly())
|
|
197
|
+
a.setIsTypeOnly(!1);
|
|
198
|
+
else if (f.isTypeOnly()) {
|
|
199
|
+
for (const y of f.getNamedImports())
|
|
200
|
+
y !== a && y.setIsTypeOnly(!0);
|
|
201
|
+
f.setIsTypeOnly(!1);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
m.push({
|
|
205
|
+
specifier: t,
|
|
206
|
+
requestedName: e,
|
|
207
|
+
actualName: a.getAliasNode()?.getText() ?? e
|
|
208
|
+
});
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (o)
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const d = T(
|
|
216
|
+
s.preferAlias === !0 ? s.preferredAlias : e,
|
|
217
|
+
s.preferAlias === !0 ? e : s.preferredAlias,
|
|
218
|
+
t,
|
|
219
|
+
l
|
|
220
|
+
), u = e === d ? void 0 : d;
|
|
221
|
+
if (s.isTypeOnly && c !== void 0)
|
|
222
|
+
c.addNamedImport({
|
|
223
|
+
name: e,
|
|
224
|
+
alias: u
|
|
225
|
+
});
|
|
226
|
+
else if (p !== void 0 && (!s.isTypeOnly || p.getDefaultImport() === void 0)) {
|
|
227
|
+
if (p.isTypeOnly() && !s.isTypeOnly) {
|
|
228
|
+
p.setIsTypeOnly(!1);
|
|
229
|
+
for (const o of p.getNamedImports())
|
|
230
|
+
o.setIsTypeOnly(!0);
|
|
231
|
+
}
|
|
232
|
+
p.addNamedImport({
|
|
233
|
+
name: e,
|
|
234
|
+
alias: u,
|
|
235
|
+
isTypeOnly: s.isTypeOnly && !p.isTypeOnly()
|
|
236
|
+
});
|
|
237
|
+
} else
|
|
238
|
+
r[t] ??= {
|
|
239
|
+
afterDeclaration: void 0,
|
|
240
|
+
named: [],
|
|
241
|
+
default: void 0,
|
|
242
|
+
"*": void 0
|
|
243
|
+
}, r[t].afterDeclaration ??= i?.[0], r[t].named.push({
|
|
244
|
+
name: e,
|
|
245
|
+
alias: u,
|
|
246
|
+
isTypeOnly: s.isTypeOnly === !0
|
|
247
|
+
});
|
|
248
|
+
m.push({ specifier: t, requestedName: e, actualName: d });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function E(t, e, s, i, m, r, l) {
|
|
252
|
+
if (i === void 0)
|
|
253
|
+
return;
|
|
254
|
+
const n = s.name ?? e, c = s.specifier ?? t, p = e === "default";
|
|
255
|
+
if (p || e === "*") {
|
|
256
|
+
for (const d of i) {
|
|
257
|
+
const u = p ? d.getDefaultImport() : d.getNamespaceImport();
|
|
258
|
+
if (u === void 0)
|
|
259
|
+
continue;
|
|
260
|
+
if (s.isTypeOnly === !1 && d.isTypeOnly()) {
|
|
261
|
+
d.setIsTypeOnly(!1);
|
|
262
|
+
for (const f of d.getNamedImports())
|
|
263
|
+
f.setIsTypeOnly(!0);
|
|
264
|
+
}
|
|
265
|
+
let o = n;
|
|
266
|
+
if (n !== e) {
|
|
267
|
+
const f = T(n, e, t, l);
|
|
268
|
+
n === f ? u.rename(n) : o = u.getText();
|
|
269
|
+
} else
|
|
270
|
+
o = u.getText();
|
|
271
|
+
t !== c && (d.getNamedImports().length === 0 ? d.setModuleSpecifier(c) : (p ? d.removeDefaultImport() : d.removeNamespaceImport(), r[c] ??= {
|
|
272
|
+
afterDeclaration: void 0,
|
|
273
|
+
named: [],
|
|
274
|
+
default: void 0,
|
|
275
|
+
"*": void 0
|
|
276
|
+
}, r[c].afterDeclaration ??= d, r[c][e] = {
|
|
277
|
+
name: o,
|
|
278
|
+
isTypeOnly: d.isTypeOnly()
|
|
279
|
+
})), m.push({
|
|
280
|
+
specifier: c,
|
|
281
|
+
requestedName: e,
|
|
282
|
+
actualName: o
|
|
283
|
+
});
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
for (const d of i) {
|
|
289
|
+
for (const o of d.getNamedImports()) {
|
|
290
|
+
if (o.getNameNode().getText() !== e)
|
|
291
|
+
continue;
|
|
292
|
+
if (s.isTypeOnly === !1) {
|
|
293
|
+
if (o.isTypeOnly())
|
|
294
|
+
o.setIsTypeOnly(!1);
|
|
295
|
+
else if (d.isTypeOnly()) {
|
|
296
|
+
d.setIsTypeOnly(!1);
|
|
297
|
+
for (const y of d.getNamedImports())
|
|
298
|
+
y !== o && y.setIsTypeOnly(!0);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
let f = n;
|
|
302
|
+
const a = o.getAliasNode();
|
|
303
|
+
if (n !== e)
|
|
304
|
+
if (a === void 0) {
|
|
305
|
+
const y = T(n, e, t, l);
|
|
306
|
+
n === y ? o.getNameNode().asKind(I.Identifier)?.rename(n) : (o.setAlias(e), o.getNameNode().replaceWithText(n), f = e);
|
|
307
|
+
} else
|
|
308
|
+
o.getNameNode().replaceWithText(n), f = a.getText();
|
|
309
|
+
if (c !== t) {
|
|
310
|
+
const g = (j(D.project.projectData) || d.getModuleSpecifierValue().endsWith(".js")) && c.startsWith("@arcgis/core") ? `${c}.js` : c;
|
|
311
|
+
d.getNamedImports().length === 1 && d.getDefaultImport() === void 0 ? d.setModuleSpecifier(g) : (r[g] ??= { named: [] }, r[g].afterDeclaration ??= i?.[0], r[g].named.push({
|
|
312
|
+
name: n,
|
|
313
|
+
alias: n === f ? void 0 : f,
|
|
314
|
+
isTypeOnly: o.isTypeOnly()
|
|
315
|
+
}), o.remove());
|
|
316
|
+
}
|
|
317
|
+
m.push({
|
|
318
|
+
specifier: c,
|
|
319
|
+
requestedName: n,
|
|
320
|
+
actualName: a?.getText() ?? f
|
|
321
|
+
});
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const u = d.getNamespaceImport();
|
|
325
|
+
if (u)
|
|
326
|
+
for (const o of u.findReferencesAsNodes().slice(1)) {
|
|
327
|
+
const f = o.getParentIfKind(I.PropertyAccessExpression), a = o.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), y = f ?? a;
|
|
328
|
+
if (!y)
|
|
329
|
+
continue;
|
|
330
|
+
const g = y.getText();
|
|
331
|
+
g.endsWith(e) && y.replaceWithText(g.replaceAll(e, n));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function W(t, e, s, i, m, r) {
|
|
336
|
+
if (e = e?.filter((u) => u.getNamespaceImport() != null), e === void 0 || e.length === 0)
|
|
337
|
+
return;
|
|
338
|
+
if (e.length !== 1)
|
|
339
|
+
throw Error(
|
|
340
|
+
`Multiple namespace imports of the same specifier (${JSON.stringify(t)}, #${e.length}) are not supported.`
|
|
341
|
+
);
|
|
342
|
+
const [l] = e, n = l.getNamespaceImport(), c = {}, p = /* @__PURE__ */ new Set();
|
|
343
|
+
for (const u of n.findReferencesAsNodes()) {
|
|
344
|
+
const o = u.getParentIfKind(I.PropertyAccessExpression), f = u.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), a = o ?? f;
|
|
345
|
+
if (!a)
|
|
346
|
+
continue;
|
|
347
|
+
const y = a.getText().split(".").pop().trim();
|
|
348
|
+
c[y] ??= T(y, void 0, t, r);
|
|
349
|
+
const g = c[y];
|
|
350
|
+
a.replaceWithText(g), f || p.add(g);
|
|
351
|
+
}
|
|
352
|
+
i[t] ??= {
|
|
353
|
+
afterDeclaration: l,
|
|
354
|
+
named: []
|
|
355
|
+
};
|
|
356
|
+
const { named: d } = i[t];
|
|
357
|
+
for (const [u, o] of Object.entries(c))
|
|
358
|
+
d.push({
|
|
359
|
+
name: u,
|
|
360
|
+
alias: o === u ? void 0 : o,
|
|
361
|
+
isTypeOnly: !p.has(o)
|
|
362
|
+
}), s.push({
|
|
363
|
+
specifier: t,
|
|
364
|
+
requestedName: u,
|
|
365
|
+
actualName: o
|
|
366
|
+
});
|
|
367
|
+
m.push(l);
|
|
368
|
+
}
|
|
369
|
+
function T(t, e, s, i) {
|
|
370
|
+
if (t !== void 0) {
|
|
371
|
+
if (!i.has(t) && !O.has(t))
|
|
372
|
+
return i.add(t), t;
|
|
373
|
+
if (e !== void 0)
|
|
374
|
+
return T(e, void 0, s, i);
|
|
375
|
+
}
|
|
376
|
+
s.startsWith("@arcgis/core") && (s = `arcgisCore${s.slice(12)}`);
|
|
377
|
+
const m = s.split("/");
|
|
378
|
+
let r = t ?? "";
|
|
379
|
+
for (let l = m.length - 1; l >= 0; l--) {
|
|
380
|
+
const n = m[l].replaceAll($, "");
|
|
381
|
+
if (n !== r && (r = n + A(r), !i.has(r) && !O.has(r)))
|
|
382
|
+
return i.add(r), r;
|
|
383
|
+
}
|
|
384
|
+
for (let l = 2; ; l++) {
|
|
385
|
+
const n = r + l;
|
|
386
|
+
if (!i.has(n) && !O.has(n))
|
|
387
|
+
return i.add(n), n;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const $ = /[^a-zA-Z0-9$_]/gu, M = (t) => t.startsWith(".") ? t : `./${t}`, O = /* @__PURE__ */ new Set();
|
|
391
|
+
let S;
|
|
392
|
+
export {
|
|
393
|
+
V as p,
|
|
394
|
+
q as u
|
|
395
|
+
};
|