Thanks for your interest in contributing to webpack codemods!
git clone https://github.com/webpack/codemods.git
cd codemods
npm installShared helpers used by several codemods live in packages/codemod-utils/ (@webpack/codemod-utils). Each codemod lives in its own directory under codemods/ and is an npm workspace:
codemods/<codemod-name>/
├── README.md # What the codemod does, before/after examples
├── codemod.yaml # Codemod registry manifest
├── workflow.yaml # Workflow definition (steps, file globs)
├── package.json # Workspace package with the `test` script
├── src/
│ └── workflow.ts # The transform, written with jssg (ast-grep)
└── tests/
└── <case-name>/ # One directory per case: input.js + expected.js
- Create a new directory under
codemods/with the structure above. Use a short, kebab-case name that describes the migration (see AGENTS.md for file templates). - Update
codemod.yaml,workflow.yaml,package.json, andREADME.mdwith the new name and description. The package name must be scoped as@webpack/<codemod-name>. - Write the transform in
src/workflow.ts. See the jssg documentation and the ast-grep rule reference. - Add fixtures: one directory per case under
tests/, each with aninput.<ext>and anexpected.<ext>file. - Add the codemod to the table in the root README.md.
Run all codemod tests:
npm testRun the tests of a single codemod:
npm test --workspace=codemods/<codemod-name>npm run lint # eslint .
npm run lint:fix # eslint . --fix
npm run type-check # tsc --noEmitCodemods are published to the Codemod Registry from CI when changes land on main.