@wise/wds-codemods 0.0.1-experimental-6c2101b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/better-impalas-drop.md +5 -0
- package/.changeset/config.json +13 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/actions/bootstrap/action.yml +49 -0
- package/.github/actions/commitlint/action.yml +27 -0
- package/.github/actions/test/action.yml +23 -0
- package/.github/workflows/cd-cd.yml +127 -0
- package/.github/workflows/renovate.yml +16 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc.js +5 -0
- package/README.md +184 -0
- package/babel.config.js +28 -0
- package/codemod-report.md +81 -0
- package/commitlint.config.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2448 -0
- package/dist/index.js.map +1 -0
- package/dist/transforms/button.d.ts +20 -0
- package/dist/transforms/button.js +640 -0
- package/dist/transforms/button.js.map +1 -0
- package/eslint.config.js +15 -0
- package/jest.config.js +9 -0
- package/mkdocs.yml +4 -0
- package/package.json +68 -0
- package/renovate.json +9 -0
- package/scripts/build.sh +10 -0
- package/src/__tests__/runCodemod.test.ts +109 -0
- package/src/index.ts +4 -0
- package/src/runCodemod.ts +149 -0
- package/src/transforms/button/__tests__/button.test.tsx +175 -0
- package/src/transforms/button/button.ts +453 -0
- package/src/transforms/helpers/__tests__/createTestTransform.test.ts +27 -0
- package/src/transforms/helpers/__tests__/hasImport.test.ts +52 -0
- package/src/transforms/helpers/__tests__/iconUtils.test.ts +207 -0
- package/src/transforms/helpers/__tests__/jsxElementUtils.test.ts +130 -0
- package/src/transforms/helpers/__tests__/jsxReportingUtils.test.ts +265 -0
- package/src/transforms/helpers/__tests__/packageValidation.test.ts +45 -0
- package/src/transforms/helpers/createTestTransform.ts +59 -0
- package/src/transforms/helpers/hasImport.ts +60 -0
- package/src/transforms/helpers/iconUtils.ts +87 -0
- package/src/transforms/helpers/index.ts +5 -0
- package/src/transforms/helpers/jsxElementUtils.ts +67 -0
- package/src/transforms/helpers/jsxReportingUtils.ts +224 -0
- package/src/transforms/helpers/packageValidation.ts +53 -0
- package/src/utils/__tests__/getOptions.test.ts +219 -0
- package/src/utils/__tests__/handleError.test.ts +18 -0
- package/src/utils/__tests__/hasPackageVersion.test.ts +191 -0
- package/src/utils/__tests__/loadTransformModules.test.ts +51 -0
- package/src/utils/__tests__/reportManualReview.test.ts +42 -0
- package/src/utils/getOptions.ts +78 -0
- package/src/utils/handleError.ts +6 -0
- package/src/utils/hasPackageVersion.ts +482 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/loadTransformModules.ts +28 -0
- package/src/utils/reportManualReview.ts +17 -0
- package/test-button.tsx +230 -0
- package/test-file.js +2 -0
- package/tsconfig.json +14 -0
- package/tsup.config.js +13 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
|
|
3
|
+
"changelog": ["@changesets/changelog-github", { "repo": "transferwise/wds-codemods" }],
|
|
4
|
+
"commit": false,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "minor",
|
|
10
|
+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
|
11
|
+
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @transferwise/design-system-web
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: 'Bootstrap'
|
|
2
|
+
description: 'Set up Node.js and install dependencies'
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
github-token:
|
|
6
|
+
description: 'GitHub token for authentication'
|
|
7
|
+
required: true
|
|
8
|
+
npm-token-automation:
|
|
9
|
+
description: 'NPM token for authentication'
|
|
10
|
+
required: false
|
|
11
|
+
|
|
12
|
+
runs:
|
|
13
|
+
using: 'composite'
|
|
14
|
+
steps:
|
|
15
|
+
- name: Setup Node.js
|
|
16
|
+
uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version-file: '.nvmrc'
|
|
19
|
+
registry-url: 'https://registry.npmjs.org'
|
|
20
|
+
|
|
21
|
+
- name: Setup pnpm
|
|
22
|
+
uses: pnpm/action-setup@v4
|
|
23
|
+
|
|
24
|
+
- name: Configure npm registry
|
|
25
|
+
shell: bash
|
|
26
|
+
run: |
|
|
27
|
+
echo "registry=https://registry.npmjs.org/" > .npmrc
|
|
28
|
+
echo "//registry.npmjs.org/:_authToken=${{ inputs.npm-token-automation }}" >> .npmrc
|
|
29
|
+
env:
|
|
30
|
+
NODE_AUTH_TOKEN: ${{ inputs.npm-token-automation }}
|
|
31
|
+
|
|
32
|
+
- name: Get pnpm store directory
|
|
33
|
+
shell: bash
|
|
34
|
+
run: |
|
|
35
|
+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
36
|
+
|
|
37
|
+
- name: Setup pnpm cache
|
|
38
|
+
uses: actions/cache@v4
|
|
39
|
+
with:
|
|
40
|
+
path: ${{ env.STORE_PATH }}
|
|
41
|
+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
42
|
+
restore-keys: |
|
|
43
|
+
${{ runner.os }}-pnpm-store-
|
|
44
|
+
|
|
45
|
+
- name: Install dependencies
|
|
46
|
+
shell: bash
|
|
47
|
+
run: pnpm install --frozen-lockfile
|
|
48
|
+
env:
|
|
49
|
+
NODE_AUTH_TOKEN: ${{ inputs.npm-token-automation }}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Commitlint
|
|
2
|
+
description: 'Lint all commit messages for the project'
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
github-token:
|
|
6
|
+
required: true
|
|
7
|
+
description: 'secrets.GITHUB_TOKEN'
|
|
8
|
+
|
|
9
|
+
runs:
|
|
10
|
+
using: composite
|
|
11
|
+
steps:
|
|
12
|
+
- name: 🔐 Mark repo directory as safe for git # https://github.blog/2022-04-12-git-security-vulnerability-announced/
|
|
13
|
+
run: git config --global --add safe.directory $GITHUB_WORKSPACE
|
|
14
|
+
shell: bash
|
|
15
|
+
|
|
16
|
+
- name: 🛠️ Bootstrap dependencies
|
|
17
|
+
uses: ./.github/actions/bootstrap
|
|
18
|
+
with:
|
|
19
|
+
github-token: ${{ inputs.github-token }}
|
|
20
|
+
|
|
21
|
+
- name: Fetch full commit history
|
|
22
|
+
run: git fetch --unshallow
|
|
23
|
+
shell: bash
|
|
24
|
+
|
|
25
|
+
- name: Run Commitlint
|
|
26
|
+
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
|
|
27
|
+
shell: bash
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
description: 'Run all tests for the project'
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
github-token:
|
|
6
|
+
required: true
|
|
7
|
+
description: 'secrets.GITHUB_TOKEN'
|
|
8
|
+
|
|
9
|
+
runs:
|
|
10
|
+
using: composite
|
|
11
|
+
steps:
|
|
12
|
+
- name: 🔐 Mark repo directory as safe for git # https://github.blog/2022-04-12-git-security-vulnerability-announced/
|
|
13
|
+
run: git config --global --add safe.directory $GITHUB_WORKSPACE
|
|
14
|
+
shell: bash
|
|
15
|
+
|
|
16
|
+
- name: 🛠️ Bootstrap dependencies
|
|
17
|
+
uses: ./.github/actions/bootstrap
|
|
18
|
+
with:
|
|
19
|
+
github-token: ${{ inputs.github-token }}
|
|
20
|
+
|
|
21
|
+
- name: 🧪 Run tests
|
|
22
|
+
run: pnpm run test
|
|
23
|
+
shell: bash
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
name: '🚀 CI/CD'
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
12
|
+
|
|
13
|
+
env:
|
|
14
|
+
DO_NOT_TRACK: 1
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
pipeline:
|
|
18
|
+
name: '🚀 Build, Lint & Test'
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- name: 🛒 Check out repository
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- name: ⚙️ Bootstrap
|
|
26
|
+
uses: ./.github/actions/bootstrap
|
|
27
|
+
with:
|
|
28
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
29
|
+
npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
|
|
30
|
+
|
|
31
|
+
- name: 📝 Lint
|
|
32
|
+
run: pnpm run lint
|
|
33
|
+
|
|
34
|
+
- name: 🧪 Run Tests
|
|
35
|
+
run: pnpm test
|
|
36
|
+
|
|
37
|
+
- name: 🏗️ Build
|
|
38
|
+
run: pnpm run build
|
|
39
|
+
|
|
40
|
+
publish-branch:
|
|
41
|
+
name: 🚀 Publish experimental packages
|
|
42
|
+
if: ${{ github.event_name == 'pull_request' && !startsWith(github.head_ref, 'changeset-release/') }}
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
timeout-minutes: 10
|
|
45
|
+
needs: [pipeline]
|
|
46
|
+
|
|
47
|
+
steps:
|
|
48
|
+
- name: 🛒 Check out repository
|
|
49
|
+
uses: actions/checkout@v4
|
|
50
|
+
with:
|
|
51
|
+
token: ${{ secrets.GH_ACCESS_TOKEN }}
|
|
52
|
+
|
|
53
|
+
- name: ⚙️ Bootstrap
|
|
54
|
+
uses: ./.github/actions/bootstrap
|
|
55
|
+
with:
|
|
56
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
57
|
+
npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
|
|
58
|
+
|
|
59
|
+
- name: 🏗️ Build
|
|
60
|
+
run: pnpm run build
|
|
61
|
+
|
|
62
|
+
- name: Setup npm token
|
|
63
|
+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_AUTOMATION }}" >> ~/.npmrc
|
|
64
|
+
shell: bash
|
|
65
|
+
|
|
66
|
+
- name: Publish snapshot release on npm
|
|
67
|
+
run: |
|
|
68
|
+
# Get current version from package.json
|
|
69
|
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
70
|
+
EXPERIMENTAL_VERSION="${CURRENT_VERSION}-experimental-${GITHUB_SHA:0:7}"
|
|
71
|
+
|
|
72
|
+
# Update package.json version directly
|
|
73
|
+
npm version $EXPERIMENTAL_VERSION --no-git-tag-version
|
|
74
|
+
|
|
75
|
+
# Publish the experimental version
|
|
76
|
+
npm publish --tag experimental
|
|
77
|
+
env:
|
|
78
|
+
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
|
|
79
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_AUTOMATION }}
|
|
80
|
+
|
|
81
|
+
publish:
|
|
82
|
+
name: 🚀 Publish stable packages
|
|
83
|
+
if: ${{ github.ref == 'refs/heads/main' }}
|
|
84
|
+
runs-on: ubuntu-latest
|
|
85
|
+
needs: [pipeline]
|
|
86
|
+
|
|
87
|
+
steps:
|
|
88
|
+
- name: 🛒 Check out repository
|
|
89
|
+
uses: actions/checkout@v4
|
|
90
|
+
with:
|
|
91
|
+
token: ${{ secrets.GH_ACCESS_TOKEN }}
|
|
92
|
+
|
|
93
|
+
- name: ⚙️ Bootstrap
|
|
94
|
+
uses: ./.github/actions/bootstrap
|
|
95
|
+
with:
|
|
96
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
97
|
+
npm-token-automation: ${{ secrets.NPM_TOKEN_AUTOMATION }}
|
|
98
|
+
|
|
99
|
+
- name: 🏗️ Build
|
|
100
|
+
run: pnpm run build
|
|
101
|
+
|
|
102
|
+
- name: 👩💻 Set GitHub credentials
|
|
103
|
+
run: |
|
|
104
|
+
mkdir -p ~/.ssh
|
|
105
|
+
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
|
106
|
+
git config --global user.name "tw-actions"
|
|
107
|
+
git config --global user.email circle@circle.tw.ee
|
|
108
|
+
|
|
109
|
+
- name: 🔐 Set up commit signing
|
|
110
|
+
uses: crazy-max/ghaction-import-gpg@v6
|
|
111
|
+
with:
|
|
112
|
+
gpg_private_key: ${{ secrets.GPG_SIGN_KEY }}
|
|
113
|
+
git_config_global: true
|
|
114
|
+
git_user_signingkey: true
|
|
115
|
+
git_commit_gpgsign: true
|
|
116
|
+
|
|
117
|
+
- name: Create changesets release PR
|
|
118
|
+
id: changesets
|
|
119
|
+
uses: changesets/action@v1
|
|
120
|
+
with:
|
|
121
|
+
publish: pnpm release
|
|
122
|
+
commit: 'chore: release'
|
|
123
|
+
title: 'chore: release new version and update changelog'
|
|
124
|
+
setupGitUser: false
|
|
125
|
+
env:
|
|
126
|
+
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
|
|
127
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN_AUTOMATION }}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Renovate
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- pnpm-lock.yaml
|
|
9
|
+
schedule:
|
|
10
|
+
- cron: '0 2 * * 1' # Run every Monday at 2AM
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
renovate:
|
|
15
|
+
uses: transferwise/renovate-workflows/.github/workflows/run.yaml@v1
|
|
16
|
+
secrets: inherit
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx --no -- commitlint --edit $1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pnpm lint
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lts/*
|
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pnpm-lock.yaml
|
package/.prettierrc.js
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
[](https://github.com/transferwise/wds-codemods/actions)
|
|
2
|
+
|
|
3
|
+
# WDS Codemods
|
|
4
|
+
|
|
5
|
+
> WDS Codemods is a collection of codemod scripts designed to automate codebase transformations
|
|
6
|
+
> specifically for the Wise Design System. This package leverages the power of [jscodeshift](https://github.com/facebook/jscodeshift)
|
|
7
|
+
> to perform AST-based code modifications, enabling large-scale refactoring and updates
|
|
8
|
+
> with minimal manual effort.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [The Repository](#-the-repository)
|
|
13
|
+
- [Getting started](#-getting-started)
|
|
14
|
+
- [Commands](#commands)
|
|
15
|
+
- [Working with the Project Locally](#-working-with-the-project-locally)
|
|
16
|
+
- [Writing Codemod Transforms](#-writing-codemod-transforms)
|
|
17
|
+
- [Notes on Key Tools](#-notes-on-key-tools)
|
|
18
|
+
- [Feedback](#-feedback)
|
|
19
|
+
|
|
20
|
+
## 👨💻 The Repository
|
|
21
|
+
|
|
22
|
+
The project provides a flexible CLI interface that allows you to run codemods either interactively
|
|
23
|
+
via prompts or directly through command-line arguments.
|
|
24
|
+
|
|
25
|
+
## 🚀 Getting started
|
|
26
|
+
|
|
27
|
+
You can run codemods against your project in two ways: using interactive prompts or via CLI
|
|
28
|
+
arguments. Here's how to do both:
|
|
29
|
+
|
|
30
|
+
### To get started, install the package
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm i -g @wise/wds-codemods
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Using Interactive Prompts
|
|
37
|
+
|
|
38
|
+
Simply run the codemod runner without any arguments:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
wds-codemods
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or, if you prefer, you can run it directly using `npx` without installing globally:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx wds-codemods
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You will be prompted to:
|
|
51
|
+
|
|
52
|
+
- Select a codemod transform from the available list.
|
|
53
|
+
- Enter the target directory or file path to apply the codemod.
|
|
54
|
+
- Choose whether to run in dry mode (no files are modified).
|
|
55
|
+
- Choose whether to print the transformed source code to the console.
|
|
56
|
+
|
|
57
|
+
### Using CLI Arguments
|
|
58
|
+
|
|
59
|
+
You can also run codemods directly by providing arguments:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
wds-codemods <transformFile> <targetPath> [--dry] [--print]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or using `npx`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx wds-codemods <transformFile> <targetPath> [--dry] [--print]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Commands
|
|
72
|
+
|
|
73
|
+
- `npx wds-codemods <transform> <targetPath>`: Run a specific codemod transform on the target path.
|
|
74
|
+
- `--dry` or `--dry-run`: Run in dry mode without writing changes to files.
|
|
75
|
+
- `--print`: Print transformed source to the console.
|
|
76
|
+
- `--ignore-pattern=GLOB`: Ignore files matching the provided glob pattern(s). Multiple patterns can be comma separated.
|
|
77
|
+
- `--gitignore`: Respect `.gitignore` files to ignore files/folders during codemod runs.
|
|
78
|
+
- `--no-gitignore`: Do not respect `.gitignore` files.
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
wds-codemods simple-rename ./src --dry
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 👨💻 Working with the Project Locally
|
|
89
|
+
|
|
90
|
+
To work with the project locally, follow these steps:
|
|
91
|
+
|
|
92
|
+
1. **Install dependencies**
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm install
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
2. **Build the project**
|
|
99
|
+
|
|
100
|
+
This compiles the main source and all transform scripts into the `dist` directory:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pnpm run build
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
3. **Run codemods**
|
|
107
|
+
|
|
108
|
+
After building, you can run the codemods using the instructions above.
|
|
109
|
+
|
|
110
|
+
### Requirements
|
|
111
|
+
|
|
112
|
+
This project uses [pnpm](https://pnpm.io/) and [Node](https://nodejs.org/en/).
|
|
113
|
+
Ensure you are using version `9.15.4` for `pnpm`, to install please follow
|
|
114
|
+
the [installation guide](https://pnpm.io/installation).
|
|
115
|
+
|
|
116
|
+
For node make sure you've set you local to the one found in `.nvmrc`. Use
|
|
117
|
+
[nvm](https://github.com/nvm-sh/nvm) to manage your local development versions.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## ⚛️ Writing Codemod Transforms
|
|
122
|
+
|
|
123
|
+
Codemod transforms are located in the `src/transforms` directory. Each transform is a
|
|
124
|
+
standalone TypeScript file exporting a default function that follows the [jscodeshift](https://github.com/facebook/jscodeshift) transformer API.
|
|
125
|
+
|
|
126
|
+
### Example: Simple Rename Transform
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import type { API, FileInfo } from 'jscodeshift';
|
|
130
|
+
|
|
131
|
+
const transformer = (file: FileInfo, api: API) => {
|
|
132
|
+
const j = api.jscodeshift;
|
|
133
|
+
const root = j(file.source);
|
|
134
|
+
|
|
135
|
+
// Find all identifiers named 'foo' and rename them to 'bar'
|
|
136
|
+
root.find(j.Identifier, { name: 'foo' }).replaceWith(() => j.identifier('bar'));
|
|
137
|
+
|
|
138
|
+
return root.toSource();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export default transformer;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Adding a New Transform
|
|
145
|
+
|
|
146
|
+
1. Create a new `.ts` file in `src/transforms/your-transform-name/`.
|
|
147
|
+
2. Export a default function following the jscodeshift transformer signature.
|
|
148
|
+
3. Write unit tests for your transform using the `createTestTransform` utility found in `src/utils/createTestTransform.ts`.
|
|
149
|
+
4. Build the project to compile your transform.
|
|
150
|
+
5. Run the codemod runner and select your new transform.
|
|
151
|
+
|
|
152
|
+
#### Writing Unit Tests for Transforms
|
|
153
|
+
|
|
154
|
+
It is important that all codemod transforms have corresponding unit tests to ensure correctness and prevent regressions. Use the `createTestTransform` utility to simplify writing tests for your transforms. This utility helps set up the testing environment and provides helpers to run your transform against sample input and verify the output.
|
|
155
|
+
|
|
156
|
+
Example usage of `createTestTransform` can be found in the existing tests under `src/transforms/simple-rename/__tests__/simple-rename.test.ts`.
|
|
157
|
+
|
|
158
|
+
Make sure to run your tests regularly using:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
pnpm test
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 📝 Notes on Key Tools
|
|
167
|
+
|
|
168
|
+
### jscodeshift
|
|
169
|
+
|
|
170
|
+
[jscodeshift](https://github.com/facebook/jscodeshift) is a toolkit for running codemods over multiple JavaScript or TypeScript files. It provides an API to parse source code into an Abstract Syntax Tree (AST), manipulate it, and print the transformed code back.
|
|
171
|
+
|
|
172
|
+
This project uses jscodeshift as the core engine to perform code transformations.
|
|
173
|
+
|
|
174
|
+
### @inquirer/prompts
|
|
175
|
+
|
|
176
|
+
[@inquirer/prompts](https://github.com/SBoudrias/Inquirer.js/tree/main/packages/prompts) is a modern, promise-based library for interactive command-line prompts.
|
|
177
|
+
|
|
178
|
+
This project uses @inquirer/prompts to provide a user-friendly interactive experience when running codemods without CLI arguments, allowing you to select transforms and options easily.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## ✍️ Feedback
|
|
183
|
+
|
|
184
|
+
Please ask any questions on this project, you can do so by reaching out on Slack. Or contributing to any [active issues](https://transferwise.atlassian.net/jira/software/projects/DS/boards/277/backlog).
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
presets: [
|
|
3
|
+
[
|
|
4
|
+
'@babel/preset-env',
|
|
5
|
+
{
|
|
6
|
+
targets: { node: 'current' },
|
|
7
|
+
modules: false,
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
'@babel/preset-typescript',
|
|
11
|
+
],
|
|
12
|
+
plugins: ['@babel/plugin-syntax-import-meta', 'babel-plugin-transform-import-meta'],
|
|
13
|
+
env: {
|
|
14
|
+
test: {
|
|
15
|
+
presets: [
|
|
16
|
+
[
|
|
17
|
+
'@babel/preset-env',
|
|
18
|
+
{
|
|
19
|
+
targets: { node: 'current' },
|
|
20
|
+
modules: 'commonjs',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
'@babel/preset-typescript',
|
|
24
|
+
],
|
|
25
|
+
plugins: ['@babel/plugin-syntax-import-meta', 'babel-plugin-transform-import-meta'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[test-button.tsx:27] Manual review required: <Button> contains spread props that need manual review.
|
|
2
|
+
[test-button.tsx:36] Manual review required: prop "priority" on <Button> contains a member (Priority.TERTIARY).
|
|
3
|
+
[test-button.tsx:34] Manual review required: prop "priority" on <Button> contains a member (Priority.PRIMARY).
|
|
4
|
+
[test-button.tsx:28] Manual review required: <Button> contains spread props that need manual review.
|
|
5
|
+
[test-button.tsx:39] Manual review required: prop "priority" on <Button> contains a identifier (somePriority).
|
|
6
|
+
[test-button.tsx:41] Manual review required: prop "priority" on <Button> contains a complex call expression.
|
|
7
|
+
[test-button.tsx:43] Manual review required: prop "priority" on <Button> contains a complex conditional expression.
|
|
8
|
+
[test-button.tsx:45] Manual review required: prop "priority" on <Button> contains a member (props.priority).
|
|
9
|
+
[test-button.tsx:49] Manual review required: prop "text" on <Button> conflicts with children - both "text" prop and children are present.
|
|
10
|
+
[test-button.tsx:57] Manual review required: <Button> contains spread props that need manual review.
|
|
11
|
+
[test-button.tsx:57] Manual review required: prop "priority" on <Button> contains a identifier (foo).
|
|
12
|
+
[test-button.tsx:57] Manual review required: prop "text" on <Button> contains a identifier (bar).
|
|
13
|
+
[test-button.tsx:57] Manual review required: prop "text" on <Button> conflicts with children - both "text" prop and children are present.
|
|
14
|
+
[test-button.tsx:37] Manual review required: prop "priority" on <Button> contains a member (Priority.UNKNOWN).
|
|
15
|
+
[test-button.tsx:61] Manual review required: <Button> contains ambiguous icon that needs manual review.
|
|
16
|
+
[test-button.tsx:66] Manual review required: <Button> contains ambiguous icon that needs manual review.
|
|
17
|
+
[test-button.tsx:71] Manual review required: <Button> contains ambiguous icon that needs manual review.
|
|
18
|
+
[test-button.tsx:76] Manual review required: <Button> contains ambiguous icon that needs manual review.
|
|
19
|
+
[test-button.tsx:81] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
20
|
+
[test-button.tsx:35] Manual review required: prop "priority" on <Button> contains a member (Priority.SECONDARY).
|
|
21
|
+
[test-button.tsx:91] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
22
|
+
[test-button.tsx:86] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
23
|
+
[test-button.tsx:97] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
24
|
+
[test-button.tsx:123] Manual review required: prop "priority" on <Button> contains a identifier (somePriority).
|
|
25
|
+
[test-button.tsx:103] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
26
|
+
[test-button.tsx:133] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
27
|
+
[test-button.tsx:138] Manual review required: <Button> contains spread props that need manual review.
|
|
28
|
+
[test-button.tsx:140] Manual review required: prop "size" on <Button> has unsupported value "huge".
|
|
29
|
+
[test-button.tsx:137] Manual review required: <Button> contains spread props that need manual review.
|
|
30
|
+
[test-button.tsx:142] Manual review required: prop "type" on <Button> has unsupported value "unknown".
|
|
31
|
+
[test-button.tsx:143] Manual review required: prop "sentiment" on <Button> has unsupported value "neutral".
|
|
32
|
+
[test-button.tsx:141] Manual review required: prop "priority" on <Button> has unsupported value "super-primary".
|
|
33
|
+
[test-button.tsx:146] Manual review required: prop "size" on <Button> has unsupported value "Size.UNKNOWN".
|
|
34
|
+
[test-button.tsx:147] Manual review required: prop "priority" on <Button> has unsupported value "Priority.UNKNOWN".
|
|
35
|
+
[test-button.tsx:150] Manual review required: prop "size" on <Button> has unsupported value "dynamicSize".
|
|
36
|
+
[test-button.tsx:152] Manual review required: prop "type" on <Button> has unsupported value "someType".
|
|
37
|
+
[test-button.tsx:154] Manual review required: prop "size" on <Button> has unsupported value "getSize()".
|
|
38
|
+
[test-button.tsx:155] Manual review required: prop "priority" on <Button> has unsupported value "getPriority()".
|
|
39
|
+
[test-button.tsx:148] Manual review required: prop "type" on <Button> has unsupported value "ControlType.UNKNOWN".
|
|
40
|
+
[test-button.tsx:156] Manual review required: prop "type" on <Button> has unsupported value "getType()".
|
|
41
|
+
[test-button.tsx:151] Manual review required: prop "priority" on <Button> has unsupported value "somePriority".
|
|
42
|
+
[test-button.tsx:158] Manual review required: prop "size" on <Button> has unsupported value "isBig ? 'lg' : 'sm".
|
|
43
|
+
[test-button.tsx:159] Manual review required: prop "priority" on <Button> has unsupported value "isPrimary ? 'primary' : 'secondary".
|
|
44
|
+
[test-button.tsx:108] Manual review required: prop "size" on <Button> has unsupported value "getSize()".
|
|
45
|
+
[test-button.tsx:160] Manual review required: prop "type" on <Button> has unsupported value "isAccent ? 'accent' : 'primary".
|
|
46
|
+
[test-button.tsx:164] Manual review required: prop "type" on <Button> has unsupported value "props.type".
|
|
47
|
+
[test-button.tsx:128] Manual review required: <Button> contains spread props that need manual review.
|
|
48
|
+
[test-button.tsx:167] Manual review required: prop "type" on <Button> has unsupported value "getHtmlType()".
|
|
49
|
+
[test-button.tsx:166] Manual review required: prop "type" on <Button> has unsupported value "magic".
|
|
50
|
+
[test-button.tsx:169] Manual review required: prop "priority" on <Button> has unsupported value "somePriority".
|
|
51
|
+
[test-button.tsx:169] Manual review required: prop "size" on <Button> has unsupported value "getSize()".
|
|
52
|
+
[test-button.tsx:169] Manual review required: prop "type" on <Button> has unsupported value "unknown".
|
|
53
|
+
[test-button.tsx:177] Manual review required: prop "size" on <Button> has unsupported value "foo".
|
|
54
|
+
[test-button.tsx:175] Manual review required: <Button> contains spread props that need manual review.
|
|
55
|
+
[test-button.tsx:177] Manual review required: prop "type" on <Button> has unsupported value "baz".
|
|
56
|
+
[test-button.tsx:177] Manual review required: prop "priority" on <Button> has unsupported value "bar".
|
|
57
|
+
[test-button.tsx:177] Manual review required: prop "type" on <Button> has unsupported value "baz".
|
|
58
|
+
[test-button.tsx:177] Manual review required: prop "sentiment" on <Button> has unsupported value "quux".
|
|
59
|
+
[test-button.tsx:181] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
60
|
+
[test-button.tsx:183] Manual review required: prop "type" on <Button> has unsupported value "danger".
|
|
61
|
+
[test-button.tsx:184] Manual review required: prop "type" on <Button> has unsupported value "link".
|
|
62
|
+
[test-button.tsx:195] Manual review required: prop "type" on <Button> has unsupported value "ControlType.DANGER".
|
|
63
|
+
[test-button.tsx:196] Manual review required: prop "priority" on <Button> has unsupported value "Priority.SECONDARY_NEUTRAL".
|
|
64
|
+
[test-button.tsx:196] Manual review required: prop "type" on <Button> has unsupported value "ControlType.LINK".
|
|
65
|
+
[test-button.tsx:219] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
66
|
+
[test-button.tsx:201] Manual review required: prop "type" on <Button> has unsupported value "ControlType.PAY".
|
|
67
|
+
[test-button.tsx:185] Manual review required: prop "type" on <Button> has unsupported value "pay".
|
|
68
|
+
[test-button.tsx:163] Manual review required: prop "priority" on <Button> has unsupported value "props.priority".
|
|
69
|
+
[test-button.tsx:162] Manual review required: prop "size" on <Button> has unsupported value "props.size".
|
|
70
|
+
[undefined:5] Manual review required: prop "sentiment" on <Button> has unsupported value "positive".
|
|
71
|
+
[undefined:5] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
72
|
+
[undefined:4] Manual review required: prop "size" on <Button> has unsupported value "dynamicSize".
|
|
73
|
+
[undefined:5] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
74
|
+
[undefined:5] Manual review required: prop "sentiment" on <Button> has unsupported value "positive".
|
|
75
|
+
[undefined:4] Manual review required: prop "size" on <Button> has unsupported value "dynamicSize".
|
|
76
|
+
[undefined:5] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
77
|
+
[undefined:4] Manual review required: prop "size" on <Button> has unsupported value "dynamicSize".
|
|
78
|
+
[undefined:5] Manual review required: prop "sentiment" on <Button> has unsupported value "positive".
|
|
79
|
+
[undefined:5] Manual review required: prop "type" on <Button> has unsupported value "accent".
|
|
80
|
+
[undefined:4] Manual review required: prop "size" on <Button> has unsupported value "dynamicSize".
|
|
81
|
+
[undefined:5] Manual review required: prop "sentiment" on <Button> has unsupported value "positive".
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|