Skip to content

Add codemods-cli and rewrite "object reducer" codemods #2768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/dist/**
**/etc/**
**/temp/**
**/temp/**
**/__testfixtures__/**
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
"release-it": "^14.12.5"
},
"resolutions": {
"@babel/core": "7.19.3",
"@babel/code-frame": "7.18.6",
"@babel/generator": "7.19.3",
"@babel/helper-compilation-targets": "7.19.3",
"@babel/traverse": "7.19.3",
"@babel/types": "7.19.3",
"console-testing-library": "patch:console-testing-library@npm:0.3.1#.yarn/patches/console-testing-library__npm_0.3.1.patch",
"msw": "patch:msw@npm:0.40.2#.yarn/patches/msw-npm-0.40.2-2107d48752",
"jscodeshift": "0.13.1",
"react-redux": "npm:8.0.2",
"react": "npm:18.1.0",
"react-dom": "npm:18.1.0",
"resolve": "1.22.1",
"ts-node": "10.4.0",
"@types/react": "npm:18.0.12",
"@types/react-dom": "npm:18.0.5",
"@types/inquirer": "npm:8.2.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/rtk-codemods/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!.*
__testfixtures__
20 changes: 20 additions & 0 deletions packages/rtk-codemods/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
parserOptions: {
ecmaVersion: 2018,
},

plugins: ['prettier', 'node'],
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:node/recommended'],
env: {
node: true,
},
rules: {},
overrides: [
{
files: ['__tests__/**/*.js'],
env: {
jest: true,
},
},
],
};
60 changes: 60 additions & 0 deletions packages/rtk-codemods/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
push:
branches:
- master
- main
- 'v*' # older version branches
tags:
- '*'
pull_request: {}
schedule:
- cron: '0 6 * * 0' # weekly, on sundays

jobs:
lint:
name: Linting
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: install dependencies
run: yarn install --frozen-lockfile
- name: linting
run: yarn lint

test:
name: Tests
runs-on: ubuntu-latest

strategy:
matrix:
node: ['10', '12', '14']

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: install dependencies
run: yarn install --frozen-lockfile
- name: test
run: yarn test

floating-test:
name: Floating dependencies
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: install dependencies
run: yarn install --no-lockfile
- name: test
run: yarn test
2 changes: 2 additions & 0 deletions packages/rtk-codemods/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.eslintcache
5 changes: 5 additions & 0 deletions packages/rtk-codemods/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100
}
9 changes: 9 additions & 0 deletions packages/rtk-codemods/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"hooks": {
"after:bump": "yarn && git add -u"
},
"git": {
"commitMessage": "Release @reduxjs/rtk-codemods ${version}",
"tagName": "@reduxjs/rtk-codemods@${version}"
}
}
45 changes: 44 additions & 1 deletion packages/rtk-codemods/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# RTK Codemods

This needs some actual content and needs to be an actual package.
A collection of codemods for updating legacy Redux Toolkit API usage patterns to modern patterns.

## Usage

To run a specific codemod from this project, you would run the following:

```bash
npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

# or

yarn global add @reduxjs/rtk-codemods
rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
```

## Local Usage

```
node ./bin/cli.js <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
```

## Transforms

<!--TRANSFORMS_START-->

- [createReducerBuilder](transforms/createReducerBuilder/README.md)
- [createSliceBuilder](transforms/createSliceBuilder/README.md)
<!--TRANSFORMS_END-->

## Contributing

### Installation

- clone the repo
- change into the repo directory
- `yarn`

### Running tests

- `yarn test`

### Update Documentation

- `yarn update-docs`
12 changes: 12 additions & 0 deletions packages/rtk-codemods/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node
const path = require('path');

require('ts-node').register({
project: path.join(__dirname, './tsconfig.json'),
});

require('codemod-cli').runTransform(
__dirname,
process.argv[2] /* transform name */,
process.argv.slice(3) /* paths or globs */
);
14 changes: 14 additions & 0 deletions packages/rtk-codemods/bin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs" ,
"strict": true ,
"noUnusedLocals": false,
"resolveJsonModule": true,
"moduleResolution": "node",
"types": ["node"],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
5 changes: 3 additions & 2 deletions packages/rtk-codemods/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
testEnvironment: 'node',
automock: false,
roots: ['v2.0/__tests__'],
// roots: ['v2.0/__tests__'],
transform: { '\\.ts$': ['ts-jest'] },
}
};
53 changes: 35 additions & 18 deletions packages/rtk-codemods/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
{
"name": "@reduxjs/rtk-codemods",
"version": "0.0.1",
"author": {
"name": "Lenz Weber",
"email": "[email protected]",
"url": "https://phryneas.de/"
},
"license": "MIT",
"type": "module",
"version": "0.0.2",
"scripts": {
"test:codemods": "jest --config codemods/jest.config.js"
"lint": "eslint --cache .",
"test": "codemod-cli test",
"test:coverage": "codemod-cli test --coverage",
"update-docs": "codemod-cli update-docs"
},
"bin": "./bin/cli.js",
"files": [
"bin/*",
"transforms/**/index.ts",
"transforms/**/README.md",
"package.json",
"README.md"
],
"keywords": [
"codemod-cli",
"redux",
"redux-toolkit",
"codemod"
],
"dependencies": {
"jest": "^27",
"jscodeshift": "^0.13.1"
"@types/jest": "^27",
"@types/jscodeshift": "^0.11.5",
"codemod-cli": "^3.2.0",
"ts-node": "10.4.0",
"typescript": "^4.8.0"
},
"devDependencies": {
"@types/jest": "^27",
"@types/jscodeshift": "^0.11.5"
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27",
"prettier": "^2.2.1",
"ts-jest": "^27"
},
"engines": {
"node": ">= 14"
},
"publishConfig": {
"access": "public"
},
"files": [
"src",
"dist"
]
}
}
Empty file.
Loading