|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thank you for helping improve webpack-codemods. This project provides automated migrations (codemods) to help the community adopt new Webpack features and upgrade across breaking changes. |
| 4 | + |
| 5 | +## How we work |
| 6 | + |
| 7 | +- Propose: Open an issue for discussion before large changes. |
| 8 | +- Safety: Codemods must be safe, predictable, and idempotent. |
| 9 | +- Tests: Every codemod requires tests with multiple fixtures (positive, negative, idempotency). |
| 10 | +- Style: Keep original formatting/indentation whenever reasonable. |
| 11 | +- Documentation: Update per-recipe README and root docs when adding/altering a codemod. |
| 12 | + |
| 13 | +For workflow structure and orchestration details, see Codemod Workflows: |
| 14 | + |
| 15 | +- Codemod Workflows (reference): https://docs.codemod.com/cli/workflows |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- Node.js LTS (>=18 recommended) |
| 20 | +- npm |
| 21 | + |
| 22 | +## Repository layout (high-level) |
| 23 | + |
| 24 | +- `recipes/<codemod-name>/` — Each codemod or recipe bundle (manifest, workflow, source, tests, docs) |
| 25 | +- `recipes/<codemod-name>/codemod.yaml` — Codemod manifest (name, version, metadata) |
| 26 | +- `recipes/<codemod-name>/workflow.yaml` — Codemod Workflow definition (steps/orchestration) |
| 27 | +- `recipes/<codemod-name>/src/workflow.ts` — JS AST-Grep transform entry (if applicable) |
| 28 | +- `recipes/<codemod-name>/tests/{input,expected}` — Test fixtures |
| 29 | +- `.github/workflows/ci.yml` — CI for lint, typecheck, validate, test |
| 30 | + |
| 31 | +For workflow structure and capabilities (nodes, steps, templates, state), see: https://docs.codemod.com/cli/workflows |
| 32 | + |
| 33 | +## Getting started |
| 34 | + |
| 35 | +```bash |
| 36 | +# Install dev deps and set up git hooks (husky) |
| 37 | +npm install |
| 38 | + |
| 39 | +# Lint and format |
| 40 | +npm run lint |
| 41 | +npm run format |
| 42 | + |
| 43 | +# Validate all workflows |
| 44 | +npm run validate |
| 45 | + |
| 46 | +# Typecheck (TypeScript) |
| 47 | +npm run typecheck |
| 48 | + |
| 49 | +# Run tests across all recipes |
| 50 | +npm run test |
| 51 | +``` |
| 52 | + |
| 53 | +## Scaffolding a new codemod |
| 54 | + |
| 55 | +Use Codemod CLI interactively to scaffold under `recipes/`: |
| 56 | + |
| 57 | +```bash |
| 58 | +npx codemod@latest init recipes/my-codemod |
| 59 | +``` |
| 60 | + |
| 61 | +During prompts, select: |
| 62 | +- Project type: JavaScript ast-grep codemod, YAML ast-grep codemod, Shell command workflow codemod |
| 63 | +- Language |
| 64 | +- Package manager of your preference |
| 65 | +- Package name |
| 66 | +- Description |
| 67 | +- Author |
| 68 | +- License |
| 69 | +- Package visibility |
| 70 | + |
| 71 | +You can also run a recipe’s own test script: `npm --prefix recipes/my-codemod run test`. |
| 72 | + |
| 73 | +Optional next steps: |
| 74 | +- Add a brief `README.md` in the recipe with Before/After examples and links to relevant Webpack docs. |
| 75 | +- Add more fixtures under the generated tests directory. |
| 76 | + |
| 77 | +## Developing a new codemod (checklist) |
| 78 | + |
| 79 | +1. Scaffold with `codemod init` (see above). |
| 80 | +2. Adapt files to repo conventions (paths, workflow step, tests layout, metadata). |
| 81 | +3. Add comprehensive fixtures (positive, negative, idempotent cases). |
| 82 | +4. Document behavior and edge cases in the recipe `README.md`. |
| 83 | +5. Run repo checks: `npm run lint && npm run typecheck && npm run validate && npm run test`. |
| 84 | + |
| 85 | +Notes: |
| 86 | +- Author transforms to preserve original indentation style (tabs vs spaces) and trailing commas where practical. |
| 87 | +- Make transforms idempotent: running twice should yield the same result. |
| 88 | +- Keep scopes tight (only touch files/matches needed). Exclude build/coverage directories in workflow inputs. |
| 89 | + |
| 90 | +## Making changes to existing codemods |
| 91 | + |
| 92 | +- Add/adjust fixtures first; then change the transform. |
| 93 | +- Ensure no semantic regressions. Only formatting should change when necessary. |
| 94 | +- Keep naming/version metadata consistent in `codemod.yaml`. |
| 95 | + |
| 96 | +## Versioning and naming |
| 97 | + |
| 98 | +- Use namespaced identifiers that reflect Webpack major: e.g., `webpack/v5/<codemod>`. |
| 99 | +- Bump recipe `version` when behavior changes. |
| 100 | + |
| 101 | +## Commit messages |
| 102 | + |
| 103 | +Use Conventional Commits: |
| 104 | + |
| 105 | +- `feat(scope):` add a new codemod or capability |
| 106 | +- `fix(scope):` bugfixes in a transform or tests |
| 107 | +- `docs(scope):` docs only changes (README, contributing) |
| 108 | +- `refactor(scope):` code changes that neither fix a bug nor add a feature |
| 109 | +- `test(scope):` add or adjust fixtures/tests |
| 110 | +- `chore(scope):` tooling, CI, formatting, or repo hygiene |
| 111 | + |
| 112 | +Examples: |
| 113 | + |
| 114 | +- `feat(json-imports-to-default-imports): support alias imports` |
| 115 | +- `fix(set-target-to-false): preserve indentation in plugins block` |
| 116 | +- `docs(contributing): add interactive scaffold instructions` |
| 117 | + |
| 118 | +## Pre-commit hooks |
| 119 | + |
| 120 | +Husky runs basic checks locally (lint, format, validate, typecheck). You can run them manually: |
| 121 | + |
| 122 | +```bash |
| 123 | +npm run lint |
| 124 | +npm run format |
| 125 | +npm run validate |
| 126 | +npm run typecheck |
| 127 | +npm run test |
| 128 | +``` |
| 129 | + |
| 130 | +## Opening a Pull Request |
| 131 | + |
| 132 | +- Link to the discussion/issue. |
| 133 | +- Include a summary of changes and why. |
| 134 | +- Include before/after examples in the PR where applicable. |
| 135 | +- Ensure CI is green (lint, typecheck, validate, test). |
| 136 | + |
| 137 | +## Security |
| 138 | + |
| 139 | +If you discover a security issue, please follow SECURITY.md and report privately. |
| 140 | + |
| 141 | +## License |
| 142 | + |
| 143 | +By contributing, you agree that your contributions are licensed under the MIT License. |
| 144 | + |
0 commit comments