@wise/wds-codemods 1.0.0-experimental-7597060 → 1.0.0-experimental-1fe0062
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/README.md +83 -101
- package/dist/{helpers-IFtIGywc.js → helpers-A50d9jU_.js} +368 -365
- package/dist/helpers-A50d9jU_.js.map +1 -0
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/{transformer-DoAMzZmy.js → transformer-DT78W0S6.js} +100 -167
- package/dist/transformer-DT78W0S6.js.map +1 -0
- package/dist/transforms/button/transformer.js +1 -2
- package/dist/transforms/button/transformer.js.map +1 -1
- package/dist/transforms/list-item/transformer.js +1 -2
- package/package.json +5 -4
- package/dist/helpers-IFtIGywc.js.map +0 -1
- package/dist/transformer-DoAMzZmy.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,19 +3,17 @@
|
|
|
3
3
|
# WDS Codemods
|
|
4
4
|
|
|
5
5
|
> WDS Codemods is a collection of codemod scripts designed to automate codebase transformations
|
|
6
|
-
> specifically for the Wise Design System. This package
|
|
7
|
-
>
|
|
8
|
-
>
|
|
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
9
|
|
|
10
10
|
## Table of Contents
|
|
11
11
|
|
|
12
12
|
- [The Repository](#-the-repository)
|
|
13
|
-
- [Getting
|
|
14
|
-
- [
|
|
15
|
-
- [Available Transforms](#-available-transforms)
|
|
16
|
-
- [Button Transform](./button.md)
|
|
17
|
-
- [ListItem Transform](./list-item.md)
|
|
13
|
+
- [Getting started](#-getting-started)
|
|
14
|
+
- [Commands](#commands)
|
|
18
15
|
- [Key Features](#-key-features)
|
|
16
|
+
- [Available Transforms](#-available-transforms)
|
|
19
17
|
- [Working with the Project Locally](#-working-with-the-project-locally)
|
|
20
18
|
- [Writing Codemod Transforms](#-writing-codemod-transforms)
|
|
21
19
|
- [Developer Documentation](#-developer-documentation)
|
|
@@ -28,11 +26,12 @@ The project provides a flexible CLI interface that allows you to run codemods ei
|
|
|
28
26
|
via prompts or directly through command-line arguments. It includes intelligent package validation,
|
|
29
27
|
monorepo support, and comprehensive reporting for manual review cases.
|
|
30
28
|
|
|
31
|
-
## 🚀 Getting
|
|
29
|
+
## 🚀 Getting started
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
You can run codemods against your project in two ways: using interactive prompts or via CLI
|
|
32
|
+
arguments. Here's how to do both:
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
### To get started, install the package
|
|
36
35
|
|
|
37
36
|
```bash
|
|
38
37
|
# Using npm
|
|
@@ -45,7 +44,7 @@ pnpm add -g @wise/wds-codemods
|
|
|
45
44
|
yarn global add @wise/wds-codemods
|
|
46
45
|
```
|
|
47
46
|
|
|
48
|
-
Or run directly without installing:
|
|
47
|
+
Or, if you prefer, you can run it directly without installing globally:
|
|
49
48
|
|
|
50
49
|
```bash
|
|
51
50
|
# Using npx
|
|
@@ -58,60 +57,53 @@ pnpm dlx @wise/wds-codemods
|
|
|
58
57
|
yarn dlx @wise/wds-codemods
|
|
59
58
|
```
|
|
60
59
|
|
|
61
|
-
###
|
|
60
|
+
### Using Interactive Prompts
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
Simply run the codemod runner without any arguments:
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
```bash
|
|
65
|
+
wds-codemods
|
|
66
|
+
```
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
Or, if you prefer, you can run it directly using `npx` without installing globally:
|
|
68
69
|
|
|
69
70
|
```bash
|
|
70
|
-
wds-codemods
|
|
71
|
+
npx wds-codemods
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
You
|
|
74
|
+
You will be prompted to:
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
6. Answer transform-specific configuration questions (🔘 `button` only)
|
|
76
|
+
- Select a codemod transform from the available list.
|
|
77
|
+
- Enter the target directory or file path to apply the codemod.
|
|
78
|
+
- Choose whether to run in dry mode (no files are modified).
|
|
79
|
+
- Choose whether to print the transformed source code to the console.
|
|
80
|
+
- Configure monorepo detection (automatically detected in most cases).
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
### Using CLI Arguments
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
You can also run codemods directly by providing arguments:
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
wds-codemods <transform> <targetPath> [
|
|
87
|
+
wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
Or using package runners:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
wds-codemods
|
|
93
|
+
npx @wise/wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
##
|
|
97
|
-
|
|
98
|
-
All codemods support these command-line options:
|
|
99
|
-
|
|
100
|
-
| Option | Description |
|
|
101
|
-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
102
|
-
| `--print` | Print transformed source to console |
|
|
103
|
-
| `--ignore-pattern=GLOB` | Ignore files matching [glob pattern(s)](https://code.visualstudio.com/docs/editor/glob-patterns) (comma-separated) |
|
|
104
|
-
| `--monorepo` | Enable monorepo package checking across workspace folders |
|
|
105
|
-
|
|
106
|
-
Only button transform supports the following options:
|
|
96
|
+
## Commands
|
|
107
97
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
- `npx wds-codemods <transform> <targetPath>`: Run a specific codemod transform on the target path.
|
|
99
|
+
- `--dry` or `--dry-run`: Run in dry mode without writing changes to files. This is useful for previewing what changes would be made before actually applying them, allowing you to review the transformations safely.
|
|
100
|
+
- `--print`: Print transformed source to the console.
|
|
101
|
+
- `--ignore-pattern=GLOB`: Ignore files matching the provided [glob pattern(s)](https://code.visualstudio.com/docs/editor/glob-patterns). Multiple patterns can be comma separated.
|
|
102
|
+
- `--gitignore`: Respect `.gitignore` files to ignore files/folders during codemod runs.
|
|
103
|
+
- `--no-gitignore`: Do not respect `.gitignore` files.
|
|
104
|
+
- `--monorepo`: Enable monorepo package checking across multiple workspace folders.
|
|
113
105
|
|
|
114
|
-
|
|
106
|
+
Examples:
|
|
115
107
|
|
|
116
108
|
```bash
|
|
117
109
|
# Basic transform with dry run
|
|
@@ -135,83 +127,73 @@ wds-codemods button ./src --print --dry
|
|
|
135
127
|
|
|
136
128
|
## 💻 Available Transforms
|
|
137
129
|
|
|
138
|
-
|
|
130
|
+
### Button Transform (`button`)
|
|
139
131
|
|
|
140
|
-
|
|
132
|
+
Migrates `Button` and `ActionButton` components from `@transferwise/components` (v46.5.0+) to the new v2 API.
|
|
141
133
|
|
|
142
|
-
|
|
134
|
+
**Key Features:**
|
|
143
135
|
|
|
144
|
-
- **
|
|
145
|
-
- **
|
|
136
|
+
- **ActionButton Migration**: Converts deprecated `ActionButton` to `Button` with `v2` prop and default size
|
|
137
|
+
- **Legacy Prop Transformations**:
|
|
138
|
+
- `priority`: Maps legacy values to new API (`primary`, `secondary`, `tertiary`, `secondary-neutral`)
|
|
139
|
+
- `size`: Converts to new size tokens (`sm`, `md`, `lg`, `xl`)
|
|
140
|
+
- `type` & `htmlType`: Handles legacy button types and HTML types appropriately
|
|
141
|
+
- `sentiment`: Manages sentiment values with special ControlType handling
|
|
142
|
+
- `text`: Converts ActionButton text prop to children
|
|
143
|
+
- **Smart Enum Handling**:
|
|
144
|
+
- **Preserves** valid `ControlType` enums (`ControlType.NEGATIVE`, `ControlType.POSITIVE`, `ControlType.ACCENT`)
|
|
145
|
+
- Converts `Priority` and `Size` enums to string equivalents
|
|
146
|
+
- Reports deprecated `Type` enum values for manual review
|
|
147
|
+
- **Icon Processing**: Automatically converts icon children to `addonStart`/`addonEnd` props
|
|
148
|
+
- **Link Button Support**: Removes `as="a"` and manages `href` attributes properly
|
|
149
|
+
- **Configurable Mapping**: Interactive prompts for accent/positive secondary button priority mapping
|
|
146
150
|
|
|
147
|
-
**
|
|
151
|
+
**Configuration Options:**
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
- Migrates legacy props (`priority`, `size`, `type`, `sentiment`)
|
|
151
|
-
- Processes icon children into addon props
|
|
152
|
-
- Handles link buttons and enum conversions
|
|
153
|
+
During transform execution, you'll be prompted to choose:
|
|
153
154
|
|
|
154
|
-
|
|
155
|
+
- `accentSecondaryMapping`: How accent + secondary buttons are mapped (`secondary-neutral` recommended or `secondary`)
|
|
156
|
+
- `positiveSecondaryMapping`: How positive + secondary buttons are mapped (`secondary-neutral` recommended or `secondary`)
|
|
155
157
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### 📋 [ListItem Transform (`list-item`)](./README-LIST-ITEM.md)
|
|
159
|
-
|
|
160
|
-
Migrates legacy `Option` and `Summary` components to `ListItem` component and subcomponents.
|
|
161
|
-
|
|
162
|
-
- **Engine**: Claude AI (context-aware transformations)
|
|
163
|
-
- **Prerequisites**: `@transferwise/components >=46.104.0` + LLM Gateway access
|
|
164
|
-
|
|
165
|
-
**What it does:**
|
|
158
|
+
**Manual Review:**
|
|
166
159
|
|
|
167
|
-
|
|
168
|
-
- Maps to `ListItem` + subcomponents (`ListItem.Button`, `ListItem.Checkbox`, etc.)
|
|
169
|
-
- Handles complex state requirements (modals, popovers)
|
|
170
|
-
- Preserves HTML attributes and removes legacy props
|
|
160
|
+
The transform generates a `codemod-report.txt` file for cases requiring manual attention:
|
|
171
161
|
|
|
172
|
-
|
|
162
|
+
- Spread props (`{...props}`)
|
|
163
|
+
- Dynamic expressions that cannot be statically analyzed
|
|
164
|
+
- Unsupported prop values
|
|
165
|
+
- Ambiguous icon children (conditional rendering, complex expressions)
|
|
173
166
|
|
|
174
167
|
---
|
|
175
168
|
|
|
176
169
|
## 🔧 Key Features
|
|
177
170
|
|
|
178
|
-
###
|
|
171
|
+
### Package Requirements Validation
|
|
179
172
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
- Supports npm, pnpm, and yarn
|
|
185
|
-
- Skips packages that don't meet prerequisites with clear reporting
|
|
173
|
+
- **Automatic Dependency Checking**: Validates required packages and versions before running transforms
|
|
174
|
+
- **Multi-Package Manager Support**: Works with npm, pnpm, and yarn
|
|
175
|
+
- **Smart Detection**: Checks package.json, lockfiles, and node_modules directories
|
|
176
|
+
- **Comprehensive Reporting**: Clear feedback when dependencies are missing or incompatible
|
|
186
177
|
|
|
187
178
|
### Monorepo Support
|
|
188
179
|
|
|
189
|
-
- Auto-
|
|
190
|
-
-
|
|
191
|
-
- Provides
|
|
192
|
-
- Manual monorepo mode for custom structures
|
|
193
|
-
|
|
194
|
-
### Manual Review Reporting
|
|
195
|
-
|
|
196
|
-
**🔘 Button transform only:**
|
|
197
|
-
|
|
198
|
-
- Generates `codemod-report.txt` for cases needing manual attention
|
|
199
|
-
- Includes file paths, line numbers, and specific issue descriptions
|
|
200
|
-
- Reports spread props, dynamic expressions, and unsupported values
|
|
201
|
-
- Auto-removes old reports and provides fresh summaries
|
|
180
|
+
- **Auto-Detection**: Automatically identifies monorepo structures (packages/, apps/, libs/, etc.)
|
|
181
|
+
- **Cross-Package Validation**: Checks dependencies across all workspace packages
|
|
182
|
+
- **Summary Reports**: Provides detailed breakdown of which packages have required dependencies
|
|
183
|
+
- **Flexible Configuration**: Manual monorepo mode for custom structures
|
|
202
184
|
|
|
203
|
-
|
|
185
|
+
### Manual Review Reports
|
|
204
186
|
|
|
205
|
-
-
|
|
206
|
-
-
|
|
207
|
-
-
|
|
187
|
+
- **Automated Report Generation**: Creates `codemod-report.txt` for issues requiring manual attention
|
|
188
|
+
- **Detailed Context**: Includes file paths, line numbers, and specific issue descriptions
|
|
189
|
+
- **Smart Cleanup**: Automatically removes old reports and provides fresh summaries
|
|
190
|
+
- **Issue Categories**: Organised reporting for spread props, dynamic expressions, and unsupported values
|
|
208
191
|
|
|
209
|
-
###
|
|
192
|
+
### Intelligent Processing
|
|
210
193
|
|
|
211
|
-
- Only runs on projects with compatible dependencies
|
|
212
|
-
-
|
|
213
|
-
- Graceful
|
|
214
|
-
- Performance-optimized for large codebases
|
|
194
|
+
- **Selective Execution**: Only runs transforms on projects with compatible dependencies
|
|
195
|
+
- **Performance Optimisation**: Caching and efficient directory traversal
|
|
196
|
+
- **Robust Error Handling**: Graceful handling of edge cases and invalid configurations
|
|
215
197
|
|
|
216
198
|
---
|
|
217
199
|
|