Skip to content

Commit b9aefe0

Browse files
authored
Merge pull request #2768 from reduxjs/feature/rtk-reducer-codemods
2 parents d9fe1fd + 81f30f4 commit b9aefe0

Some content is hidden

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

41 files changed

+1450
-1935
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/dist/**
22
**/etc/**
3-
**/temp/**
3+
**/temp/**
4+
**/__testfixtures__/**

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737
"release-it": "^14.12.5"
3838
},
3939
"resolutions": {
40+
"@babel/core": "7.19.3",
41+
"@babel/code-frame": "7.18.6",
42+
"@babel/generator": "7.19.3",
43+
"@babel/helper-compilation-targets": "7.19.3",
44+
"@babel/traverse": "7.19.3",
45+
"@babel/types": "7.19.3",
4046
"console-testing-library": "patch:console-testing-library@npm:0.3.1#.yarn/patches/console-testing-library__npm_0.3.1.patch",
4147
"msw": "patch:msw@npm:0.40.2#.yarn/patches/msw-npm-0.40.2-2107d48752",
48+
"jscodeshift": "0.13.1",
4249
"react-redux": "npm:8.0.2",
4350
"react": "npm:18.1.0",
4451
"react-dom": "npm:18.1.0",
52+
"resolve": "1.22.1",
53+
"ts-node": "10.4.0",
4554
"@types/react": "npm:18.0.12",
4655
"@types/react-dom": "npm:18.0.5",
4756
"@types/inquirer": "npm:8.2.1",

packages/rtk-codemods/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!.*
2+
__testfixtures__

packages/rtk-codemods/.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
parserOptions: {
3+
ecmaVersion: 2018,
4+
},
5+
6+
plugins: ['prettier', 'node'],
7+
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:node/recommended'],
8+
env: {
9+
node: true,
10+
},
11+
rules: {},
12+
overrides: [
13+
{
14+
files: ['__tests__/**/*.js'],
15+
env: {
16+
jest: true,
17+
},
18+
},
19+
],
20+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
- 'v*' # older version branches
9+
tags:
10+
- '*'
11+
pull_request: {}
12+
schedule:
13+
- cron: '0 6 * * 0' # weekly, on sundays
14+
15+
jobs:
16+
lint:
17+
name: Linting
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v1
22+
- uses: actions/setup-node@v1
23+
with:
24+
node-version: 12.x
25+
- name: install dependencies
26+
run: yarn install --frozen-lockfile
27+
- name: linting
28+
run: yarn lint
29+
30+
test:
31+
name: Tests
32+
runs-on: ubuntu-latest
33+
34+
strategy:
35+
matrix:
36+
node: ['10', '12', '14']
37+
38+
steps:
39+
- uses: actions/checkout@v1
40+
- uses: actions/setup-node@v1
41+
with:
42+
node-version: ${{ matrix.node }}
43+
- name: install dependencies
44+
run: yarn install --frozen-lockfile
45+
- name: test
46+
run: yarn test
47+
48+
floating-test:
49+
name: Floating dependencies
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v1
54+
- uses: actions/setup-node@v1
55+
with:
56+
node-version: '12.x'
57+
- name: install dependencies
58+
run: yarn install --no-lockfile
59+
- name: test
60+
run: yarn test

packages/rtk-codemods/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/.eslintcache

packages/rtk-codemods/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"printWidth": 100
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"hooks": {
3+
"after:bump": "yarn && git add -u"
4+
},
5+
"git": {
6+
"commitMessage": "Release @reduxjs/rtk-codemods ${version}",
7+
"tagName": "@reduxjs/rtk-codemods@${version}"
8+
}
9+
}

packages/rtk-codemods/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
11
# RTK Codemods
22

3-
This needs some actual content and needs to be an actual package.
3+
A collection of codemods for updating legacy Redux Toolkit API usage patterns to modern patterns.
4+
5+
## Usage
6+
7+
To run a specific codemod from this project, you would run the following:
8+
9+
```bash
10+
npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
11+
12+
# or
13+
14+
yarn global add @reduxjs/rtk-codemods
15+
rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
16+
```
17+
18+
## Local Usage
19+
20+
```
21+
node ./bin/cli.js <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
22+
```
23+
24+
## Transforms
25+
26+
<!--TRANSFORMS_START-->
27+
28+
- [createReducerBuilder](transforms/createReducerBuilder/README.md)
29+
- [createSliceBuilder](transforms/createSliceBuilder/README.md)
30+
<!--TRANSFORMS_END-->
31+
32+
## Contributing
33+
34+
### Installation
35+
36+
- clone the repo
37+
- change into the repo directory
38+
- `yarn`
39+
40+
### Running tests
41+
42+
- `yarn test`
43+
44+
### Update Documentation
45+
46+
- `yarn update-docs`

packages/rtk-codemods/bin/cli.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
const path = require('path');
3+
4+
require('ts-node').register({
5+
project: path.join(__dirname, './tsconfig.json'),
6+
});
7+
8+
require('codemod-cli').runTransform(
9+
__dirname,
10+
process.argv[2] /* transform name */,
11+
process.argv.slice(3) /* paths or globs */
12+
);

0 commit comments

Comments
 (0)