@arcgis/codemod

中文文档
5.2.2发布于 2026/11/11SEE LICENSE IN LICENSE.mdES Module近 30 天下载 9989

A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.

原始使用文档
文档目录9 节
  1. Requirements
  2. Before you begin
  3. Available codemods
  4. Refactor out the __esri namespace
  5. Normalize Calcite icon names
  6. Rename Geometry Operators
  7. Versioning
  8. Troubleshooting
  9. License

@arcgis/codemod

A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.

This package provides automated refactors to help migrate away from deprecated or legacy patterns. These include codemods for removing the __esri namespace and converting global namespace types to explicit @arcgis/core imports, normalizing legacy Calcite icon names, and updating geometry operator usage.

Requirements

  • Node.js 24
  • A project using the ArcGIS Maps SDK for JavaScript
  • This codemod operates exclusively on TypeScript files. You do not need to run this tool if the project does not use TypeScript.

Before you begin

Ensure your project's dependencies are up to date, for example by running pnpm install.

If your project uses ESLint, Prettier, or other formatters/linters, run them after the codemod to ensure consistent formatting.

[!Note] Codemods modify files in place and do not provide an interactive dry-run mode. We recommend running it in a project that is under version control (Git) so you can review changes using git diff or your IDE’s diff tools. If your project is not under version control, create a backup before running the codemod.

By default, codemods run on all TypeScript files in the current directory and subdirectories. You can manually run it on a different directory by providing it as an argument.

Codemods respect .gitignore files and will not modify any files ignored by them.

Available codemods

Refactor out the __esri namespace

The refactor-out-esri-namespace codemod replaces __esri types with explicit imports from @arcgis/core.

Note: Before running the codemod, update all @arcgis/* packages in your package.json to the most recent version.

Run it in the root of your project or with an explicit target directory:

npx @arcgis/codemod run refactor-out-esri-namespace [<target-directory>]

Before:

let geometry: __esri.Geometry;
let featureSet: __esri.FeatureSet;

After:

import type Geometry from "@arcgis/core/geometry/Geometry";
import type FeatureSet from "@arcgis/core/rest/support/FeatureSet";

let geometry: Geometry;

let featureSet: FeatureSet;

Warnings (manual review required)

The codemod will emit warnings for cases it cannot safely rewrite, including:

  • __esri references inside JSDoc comments
  • Complex computed or dynamic type usage
  • Unresolvable symbols

These will be reported in the console. Manually review all changes before committing.

Normalize Calcite icon names

The normalize-calcite-icon-names codemod updates camelCase and legacy Calcite icon names to their normalized kebab-case equivalents. It handles icon attributes on Calcite components and traces icon values through variables, properties, assignments, function returns, and forwarded component properties. This helps prepare for calcite-design-system#14967 and calcite-design-system#14966.

Run it in the root of your project or with an explicit target directory:

npx @arcgis/codemod run normalize-calcite-icon-names [<target-directory>]

Before:

<calcite-button iconStart="i3dGlasses" iconEnd="arrowLeft10" />

After:

<calcite-button iconStart="3d-glasses" iconEnd="arrow-left-10" />

Rename Geometry Operators

In version 5.2, geometry operator exports and option types were renamed to improve consistency and discoverability. The geometry-operator-renames codemod updates geometry operator calls to use the new names. It additionally inlines namespace imports, which are no longer necessary.

Run it in the root of your project or with an explicit target directory:

npx @arcgis/codemod run geometry-operator-renames [<target-directory>]

Before:

import * as bufferOperator from "@arcgis/core/geometry/operators/bufferOperator";
const options: bufferOperator.Options = { unit: "meters" };
const buffered = bufferOperator.execute(polyline, 250, options);

After:

import { bufferExecute, type BufferExecuteOptions } from "@arcgis/core/geometry/operators/bufferOperator";
const options: BufferExecuteOptions = { unit: "meters" };
const buffered = bufferExecute(polyline, 250, options);

Versioning

The codemods are available until the corresponding deprecated feature is removed. If migrating from a much older release, the codemod might no longer be available in the most recent version of the @arcgis/codemod package. In such cases, run the codemod from an older version, matching the version in the release notes:

npx @arcgis/[email protected] run refactor-out-esri-namespace

Troubleshooting

Some codemods rely on type information to perform more accurate migrations. On large codebases, this may require more RAM than the default Node.js limit. 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:

Example on Linux/macOS:

NODE_OPTIONS="--max-old-space-size=10240" npx @arcgis/codemod run normalize-calcite-icon-names

Windows command line and PowerShell use a different environment variable syntax.

License

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. For third party notices, see https://js.arcgis.com/5.2/third-party-notices.txt.

版本与发布记录

@arcgis/codemod 共发布 390 个版本,首次发布于 2026/02/10;过去 12 个月发布了 390 个版本。

版本发布日期距今
5.2.2latest2026/11/11今天
6.0.0-next.34next2026/11/10今天
6.0.0-next.332026/11/091 天前
6.0.0-next.322026/11/082 天前
6.0.0-next.312026/11/073 天前
5.2.12026/11/074 天前

其他发布通道:rc → 5.2.0-next.170,next → 6.0.0-next.34。

关于 @arcgis/codemod 的常见问题

@arcgis/codemod 是什么?

A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.

如何安装 @arcgis/codemod?

在项目目录运行 npm install @arcgis/codemod,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 codemod,可以用 npx codemod 直接运行。

@arcgis/codemod 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/arcgis__codemod 是否存在。

@arcgis/codemod 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@arcgis/codemod 可以商用吗?

@arcgis/codemod 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@arcgis/codemod 的下载量有多少?

根据 npm 官方下载统计,@arcgis/codemod 在 2026/10/07 – 2026/11/05 这 30 天内被下载 9,989 次,日均约 333 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arcgis/codemod 还在维护吗?

最新版本 5.2.2 发布于 2026/11/11(今天);至今共发布 390 个版本,其中过去 12 个月发布了 390 个;首次发布于 2026/02/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。