Skip to content

Commit a734fad

Browse files
committed
update repo
1 parent 592cdc1 commit a734fad

File tree

53 files changed

+766
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+766
-313
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* text=auto eol=lf
2+
3+
*.ts diff=javascript
4+
*.tsx diff=javascript
5+
*.js diff=javascript
6+
*.jsx diff=javascript
7+
*.json linguist-language=JSON
8+
*.yaml linguist-language=YAML
9+
*.yml linguist-language=YAML

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
- name: Install biome
17+
run: npm -g install @biomejs/biome@^1.7.0
18+
- name: Lint
19+
run: npm run lint --if-present
20+
- name: Typecheck
21+
run: npm run typecheck --if-present
22+
- name: Validate codemod workflows
23+
run: npm run validate
24+
- name: Test recipes
25+
run: npm run test
26+

.gitignore

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
node_modules
2-
npm-debug.log
3-
.npm
4-
.env.*
1+
# Node
2+
node_modules/
3+
*.log
4+
npm-debug.log*
5+
yarn-error.log
6+
pnpm-debug.log*
57

6-
package-lock.json
8+
# Editor
9+
.vscode/
10+
.idea/
711

12+
# Builds and caches
13+
coverage/
14+
dist/
15+
build/
16+
.out/
17+
.next/
18+
.cache/
819
.DS_Store
20+
21+
# Lockfiles
22+
package-lock.json
23+
yarn.lock
24+
pnpm-lock.yaml

.husky/pre-commit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run lint
5+
npm run format
6+
npm run validate
7+
npm run typecheck

CONTRIBUTING.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 webpack-codemods contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,49 @@
44
</a>
55
</div>
66

7-
<h1 align="center">webpack codemods</h1>
7+
<h1 align="center">webpack codemods</h1>
8+
9+
This repository contains codemods (automated migrations) for webpack. These codemods facilitate adopting new features and upgrading to versions with breaking changes.
10+
11+
## Quickstart
12+
13+
```bash
14+
# Run a specific codemod from the registry
15+
npx codemod@latest webpack/v5/json-imports-to-default-imports
16+
17+
# Run the combined migration recipe
18+
npx codemod@latest webpack/v5/migration-recipe
19+
20+
# Run locally from a recipe directory
21+
codemod run -w workflow.yaml
22+
```
23+
24+
See the [codemod CLI doc](https://go.codemod.com/cli-docs) for a full list of available commands.
25+
26+
## Available codemods
27+
28+
> [!CAUTION]
29+
> These scripts change source code. Remember to commit any wanted and unsaved changes before running them.
30+
31+
To run codemods, use [`codemod`](https://go.codemod.com/github) command below:
32+
33+
```console
34+
npx codemod @webpack/<recipe>
35+
```
36+
37+
- `webpack/v5/json-imports-to-default-imports` — replace JSON named imports with default import
38+
- `webpack/v5/migrate-library-target-to-library-object` — migrate `output.library` and `output.libraryTarget` to v5 format
39+
- `webpack/v5/set-target-to-false-and-update-plugins` — move functional `target` into `plugins` and set `target: false`
40+
- `webpack/v5/migration-recipe` — orchestrates the above in sequence
41+
42+
## Contributing
43+
44+
See [CONTRIBUTING.md](./CONTRIBUTING.md). Please commit or stash your changes before running codemods.
45+
46+
## Security
47+
48+
See [SECURITY.md](./SECURITY.md). Report vulnerabilities privately.
49+
50+
## License
51+
52+
MIT

SECURITY.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
This repository contains codemods. We aim to keep them safe to run, but they modify source code. Always commit your work before running.
6+
7+
## Reporting a Vulnerability
8+
9+
If you discover a security issue, please email the maintainers privately:
10+
11+
- security contact: [email protected]
12+
13+
Please do not open public issues for security reports. We will acknowledge receipt, investigate, and provide a timeline for a fix when possible.

biome.jsonc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
3+
"files": {
4+
"includes": ["."],
5+
"experimentalScannerIgnores": ["recipes/**/tests/**/fixtures/**"]
6+
},
7+
"formatter": {
8+
"enabled": true,
9+
"lineWidth": 100
10+
},
11+
"linter": {
12+
"enabled": true
13+
},
14+
"javascript": {
15+
"formatter": {
16+
"quoteStyle": "double"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)