Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 2.05 KB

File metadata and controls

61 lines (44 loc) · 2.05 KB

Contributing

Thanks for your interest in contributing to webpack codemods!

Setup

git clone https://github.com/webpack/codemods.git
cd codemods
npm install

Repository structure

Shared 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

Adding a new codemod

  1. 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).
  2. Update codemod.yaml, workflow.yaml, package.json, and README.md with the new name and description. The package name must be scoped as @webpack/<codemod-name>.
  3. Write the transform in src/workflow.ts. See the jssg documentation and the ast-grep rule reference.
  4. Add fixtures: one directory per case under tests/, each with an input.<ext> and an expected.<ext> file.
  5. Add the codemod to the table in the root README.md.

Testing

Run all codemod tests:

npm test

Run the tests of a single codemod:

npm test --workspace=codemods/<codemod-name>

Linting and type checking

npm run lint        # eslint .
npm run lint:fix    # eslint . --fix
npm run type-check  # tsc --noEmit

Publishing

Codemods are published to the Codemod Registry from CI when changes land on main.