Introduction to Codemod Kit
codemod-kit is a codemod library built on top of jscodeshift. It provides utilities to simplify the creation of codemods, specifically offering support for managing components and imports.
website·Indexed 30 days ago
https://codemod-kit.netlify.appA tool for performing automated code transformations via CLI or programmatic methods. It provides a set of transformers to modify import modules, change or remove component props, and modify function arguments.
change-named-specifier transformer to rename a specific named import (the specifier) and update all corresponding identifiers that use it throughout the file. Note that this transformer only converts global values; local variables that shadow the import name are not converted.remove-import transformer removes import statements that do not include specifiers (e.g., import "module";). It specifically does not remove imports that contain specifiers because removing those would require identifying and removing all associated identifiers throughout the codebase, which is not currently supported.// Before
import "utils";
import "lib";
// After
(empty)codemod-kit package as a development dependency using npm, yarn, or pnpm.npm install --save-dev codemod-kitExecute the codemod-kit CLI using npx. The tool will prompt you for the following inputs in order:
npx codemod-kityarn installcodemod-kit globally using npm, yarn, or pnpm to enable code transformation capabilities via the command line.npm install -g codemod-kitadd-props transformer programmatically to change an import specifier from sum to calculateSum for a specific file.import { transformMap } from "codemod-kit/programmatic"
transformMap['add-props']({
toConvertPaths: "src/test.ts",
customOptions: {
source: "utils",
sourceType: "absolute",
fromSpecifier: "sum",
toSpecifier: "calculateSum",
},
jscodeshiftOptions: {
parser: "tsx"
}
})