@atlaskit/codemod-utils

中文文档
5.2.0发布于 2026/11/06Apache-2.0TypeScriptESM + CJS近 30 天下载 35.7万

jscodeshift-compatible codemod utilities

原始使用文档
文档目录3 节
  1. Home for codemods
  2. Examples
  3. Advanced usage

Home for codemods

As part of lite mode conversion for components in atlaskit, we found codemods with jscodeshift are extremely helpful for migrating some breaking changes for our consumers. However, one pain point for us who need to write and maintain them is that we have to copy-paste the code snippet in many places.

So the purpose of this package is to relief that pain and centric all reusable codemods snippets into a single place, and all the further changes should happen in this repo only.

The goal is to release this repo as a npm package, so our users can simply introduce those generic functions and compose in their codebase.

Examples

For example, when you want to depracate a prop called isLoading from your consumer's codebase, you can introduce some helper function into a file transformer.ts from @atlaskit/codemod-utils:

import {
  createRemoveFuncFor,
  createTransformer,
} from '@atlaskit/codemod-utils';

const removeIsLoading = createRemoveFuncFor(
  '@atlaskit/fancycomponent',
  'ComponentName',
  'isLoading',
);

const transformer = createTransformer([removeIsLoading]);

export default transformer;

And then run the transformer like:

npx jscodeshift -t transformer.ts  --ignore-pattern node_modules --parser babel --extensions ts path/to/your/codebase

Advanced usage

If you need more than one mutation against your codebase and want to apply all of them in one go, it's recommended to structure them properly into a separate folder.

For example, if you need 3 separate steps:

  • remove isLoading prop
  • rename isDefaultChecked to defaultChecked
  • add a new prop title

then you can have a folder called migrates that contains:

  • remove-isLoading.ts
  • rename-isDefaultChecked-to-defaultChecked.ts
  • add-title.ts

and for each file, you can have some code like:

import { createAddingPropFor } from '@atlaskit/codemod-utils';

export const addTitle = createAddingPropFor('@atlaskit/fancycomponent', {
  prop: 'title',
  defaultValue: '',
});

and in your entrypoint for jscodeshift to pick up, you can introduce all those migrates:

import { addTitle } from './migrates/add-title';
import { removeIsLoading } from './migrates/remove-isLoading';
import { renameDefaultChecked } from './migrates/rename-isDefaultChecked-to-defaultChecked.ts';

import { createTransformer } from './utils';

const transformer = createTransformer([
  renameDefaultChecked,
  removeIsLoading,
  addTitle,
]);

export default transformer;

This way, you can easily test those migrates separately with all the possible scenario, and compose them freely as well to see if they can work together to make the whole transform.

版本与发布记录

@atlaskit/codemod-utils 共发布 31 个版本,首次发布于 2020/12/08;过去 12 个月发布了 4 个版本。

版本发布日期距今
5.2.0latest2026/11/061 天前
5.1.02026/08/302 个月前
5.0.02026/06/164 个月前
4.3.02026/05/205 个月前
4.2.52025/03/251.6 年前
4.2.42024/03/202 年前

其他发布通道:next → 4.2.2。

关于 @atlaskit/codemod-utils 的常见问题

@atlaskit/codemod-utils 是什么?

jscodeshift-compatible codemod utilities

如何安装 @atlaskit/codemod-utils?

在项目目录运行 npm install @atlaskit/codemod-utils,或使用 pnpm add / yarn add / bun add。

@atlaskit/codemod-utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atlaskit/codemod-utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atlaskit/codemod-utils 可以商用吗?

@atlaskit/codemod-utils 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@atlaskit/codemod-utils 的下载量有多少?

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

@atlaskit/codemod-utils 还在维护吗?

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