@wise/wds-codemods 1.0.0-experimental-37647bf → 1.0.0-experimental-31a00f9
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 +101 -83
- package/dist/constants-CcE2TmzN.js +59 -0
- package/dist/constants-CcE2TmzN.js.map +1 -0
- package/dist/{helpers-BNLAPdMR.js → helpers-IFtIGywc.js} +187 -160
- package/dist/helpers-IFtIGywc.js.map +1 -0
- package/dist/index.js +71 -40
- package/dist/index.js.map +1 -1
- package/dist/transformer-DoAMzZmy.js +468 -0
- package/dist/transformer-DoAMzZmy.js.map +1 -0
- package/dist/transforms/button/transformer.js +2 -1
- package/dist/transforms/button/transformer.js.map +1 -1
- package/dist/transforms/list-item/config.json +6 -0
- package/dist/transforms/list-item/transformer.js +4 -0
- package/package.json +9 -4
- package/dist/helpers-BNLAPdMR.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
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
|
-
> with minimal manual effort.
|
|
6
|
+
> specifically for the Wise Design System. This package provides two types of transforms:
|
|
7
|
+
> **[jscodeshift](https://github.com/facebook/jscodeshift)** and **[Claude AI](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk)**,
|
|
8
|
+
> enabling large-scale refactoring and updates with minimal manual effort.
|
|
9
9
|
|
|
10
10
|
## Table of Contents
|
|
11
11
|
|
|
12
12
|
- [The Repository](#-the-repository)
|
|
13
|
-
- [Getting
|
|
14
|
-
- [
|
|
15
|
-
- [Key Features](#-key-features)
|
|
13
|
+
- [Getting Started](#-getting-started)
|
|
14
|
+
- [CLI Options](#cli-options)
|
|
16
15
|
- [Available Transforms](#-available-transforms)
|
|
16
|
+
- [Button Transform](./button.md)
|
|
17
|
+
- [ListItem Transform](./list-item.md)
|
|
18
|
+
- [Key Features](#-key-features)
|
|
17
19
|
- [Working with the Project Locally](#-working-with-the-project-locally)
|
|
18
20
|
- [Writing Codemod Transforms](#-writing-codemod-transforms)
|
|
19
21
|
- [Developer Documentation](#-developer-documentation)
|
|
@@ -26,12 +28,11 @@ The project provides a flexible CLI interface that allows you to run codemods ei
|
|
|
26
28
|
via prompts or directly through command-line arguments. It includes intelligent package validation,
|
|
27
29
|
monorepo support, and comprehensive reporting for manual review cases.
|
|
28
30
|
|
|
29
|
-
## 🚀 Getting
|
|
31
|
+
## 🚀 Getting Started
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
arguments. Here's how to do both:
|
|
33
|
+
### Installation
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
Install globally for convenience:
|
|
35
36
|
|
|
36
37
|
```bash
|
|
37
38
|
# Using npm
|
|
@@ -44,7 +45,7 @@ pnpm add -g @wise/wds-codemods
|
|
|
44
45
|
yarn global add @wise/wds-codemods
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
Or
|
|
48
|
+
Or run directly without installing:
|
|
48
49
|
|
|
49
50
|
```bash
|
|
50
51
|
# Using npx
|
|
@@ -57,53 +58,60 @@ pnpm dlx @wise/wds-codemods
|
|
|
57
58
|
yarn dlx @wise/wds-codemods
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
###
|
|
61
|
+
### Running Codemods
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
You can run codemods in two ways:
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
wds-codemods
|
|
66
|
-
```
|
|
65
|
+
#### Interactive Mode
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
Run without arguments to get interactive prompts:
|
|
69
68
|
|
|
70
69
|
```bash
|
|
71
|
-
|
|
70
|
+
wds-codemods
|
|
72
71
|
```
|
|
73
72
|
|
|
74
|
-
You
|
|
73
|
+
You'll be prompted to:
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
1. Select a transform (`button` or `list-item`)
|
|
76
|
+
2. Enter target directory or file path
|
|
77
|
+
3. Choose dry-run mode (preview without writing) (🔘 `button` only)
|
|
78
|
+
4. Choose whether to print transformed output
|
|
79
|
+
5. Configure monorepo detection (auto-detected in most cases)
|
|
80
|
+
6. Answer transform-specific configuration questions (🔘 `button` only)
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
#### Direct CLI Mode
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Run with arguments for automation:
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
wds-codemods <transform> <targetPath> [
|
|
87
|
+
wds-codemods <transform> <targetPath> [options]
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
Example:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
|
|
93
|
+
wds-codemods button ./src --dry --print
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## CLI Options
|
|
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:
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
- `--no-gitignore`: Do not respect `.gitignore` files.
|
|
104
|
-
- `--monorepo`: Enable monorepo package checking across multiple workspace folders.
|
|
108
|
+
| Option | Description |
|
|
109
|
+
| --------------------- | ---------------------------------------- |
|
|
110
|
+
| `--dry` / `--dry-run` | Preview changes without writing to files |
|
|
111
|
+
| `--gitignore` | Respect `.gitignore` files |
|
|
112
|
+
| `--no-gitignore` | Ignore `.gitignore` files |
|
|
105
113
|
|
|
106
|
-
Examples
|
|
114
|
+
### Common Examples
|
|
107
115
|
|
|
108
116
|
```bash
|
|
109
117
|
# Basic transform with dry run
|
|
@@ -127,73 +135,83 @@ wds-codemods button ./src --print --dry
|
|
|
127
135
|
|
|
128
136
|
## 💻 Available Transforms
|
|
129
137
|
|
|
130
|
-
|
|
138
|
+
We currently provide two codemods for migrating Wise Design System components:
|
|
131
139
|
|
|
132
|
-
|
|
140
|
+
### 🔘 [Button Transform (`button`)](./README-BUTTON.md)
|
|
133
141
|
|
|
134
|
-
|
|
142
|
+
Migrates `Button` and `ActionButton` components from `@transferwise/components` to the new v2 API.
|
|
135
143
|
|
|
136
|
-
- **
|
|
137
|
-
- **
|
|
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
|
|
144
|
+
- **Engine**: jscodeshift (AST-based transformations)
|
|
145
|
+
- **Prerequisites**: `@transferwise/components >=46.5.0`
|
|
150
146
|
|
|
151
|
-
**
|
|
147
|
+
**What it does:**
|
|
152
148
|
|
|
153
|
-
|
|
149
|
+
- Converts `ActionButton` + `Button` → `Button` with v2 prop
|
|
150
|
+
- Migrates legacy props (`priority`, `size`, `type`, `sentiment`)
|
|
151
|
+
- Processes icon children into addon props
|
|
152
|
+
- Handles link buttons and enum conversions
|
|
154
153
|
|
|
155
|
-
|
|
156
|
-
- `positiveSecondaryMapping`: How positive + secondary buttons are mapped (`secondary-neutral` recommended or `secondary`)
|
|
154
|
+
**[→ Full Button Transform Documentation](./README-BUTTON.md)**
|
|
157
155
|
|
|
158
|
-
|
|
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:**
|
|
159
166
|
|
|
160
|
-
|
|
167
|
+
- Converts `ActionOption`, `NavigationOption`, `Summary`, `SwitchOption`, `CheckboxOption`, `RadioOption`, `DefinitionList`
|
|
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
|
|
161
171
|
|
|
162
|
-
|
|
163
|
-
- Dynamic expressions that cannot be statically analyzed
|
|
164
|
-
- Unsupported prop values
|
|
165
|
-
- Ambiguous icon children (conditional rendering, complex expressions)
|
|
172
|
+
**[→ Full ListItem Transform Documentation](./README-LIST-ITEM.md)**
|
|
166
173
|
|
|
167
174
|
---
|
|
168
175
|
|
|
169
176
|
## 🔧 Key Features
|
|
170
177
|
|
|
171
|
-
### Package
|
|
178
|
+
### Automatic Package Validation
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
180
|
+
Before running any transform, the codemod automatically:
|
|
181
|
+
|
|
182
|
+
- Validates required package versions (e.g., `@transferwise/components >=46.5.0`)
|
|
183
|
+
- Checks `package.json`, lockfiles, and `node_modules`
|
|
184
|
+
- Supports npm, pnpm, and yarn
|
|
185
|
+
- Skips packages that don't meet prerequisites with clear reporting
|
|
177
186
|
|
|
178
187
|
### Monorepo Support
|
|
179
188
|
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
189
|
+
- Auto-detects monorepo structures (`packages/`, `apps/`, `libs/`, etc.)
|
|
190
|
+
- Validates dependencies across all workspace packages
|
|
191
|
+
- Provides summary reports showing which packages are ready
|
|
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
|
|
184
202
|
|
|
185
|
-
|
|
203
|
+
**📋 ListItem transform:**
|
|
186
204
|
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
- **Issue Categories**: Organised reporting for spread props, dynamic expressions, and unsupported values
|
|
205
|
+
- No report file generated
|
|
206
|
+
- Claude handles complex cases inline
|
|
207
|
+
- Use `--print` to review diffs before applying
|
|
191
208
|
|
|
192
|
-
###
|
|
209
|
+
### Smart Processing
|
|
193
210
|
|
|
194
|
-
-
|
|
195
|
-
-
|
|
196
|
-
-
|
|
211
|
+
- Only runs on projects with compatible dependencies
|
|
212
|
+
- Efficient directory traversal and file filtering
|
|
213
|
+
- Graceful error handling for edge cases
|
|
214
|
+
- Performance-optimized for large codebases
|
|
197
215
|
|
|
198
216
|
---
|
|
199
217
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
|
|
30
|
+
//#region src/constants.ts
|
|
31
|
+
const CONSOLE_ICONS = {
|
|
32
|
+
info: "\x1B[34mℹ\x1B[0m",
|
|
33
|
+
focus: "\x1B[34mâž™\x1B[0m",
|
|
34
|
+
success: "\x1B[32m✔\x1B[0m",
|
|
35
|
+
warning: "\x1B[33mâš \x1B[0m",
|
|
36
|
+
error: "\x1B[31m✖\x1B[0m",
|
|
37
|
+
claude: "\x1B[35m💬\x1B[0m"
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
Object.defineProperty(exports, 'CONSOLE_ICONS', {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return CONSOLE_ICONS;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, '__commonJSMin', {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return __commonJSMin;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, '__toESM', {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () {
|
|
56
|
+
return __toESM;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=constants-CcE2TmzN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-CcE2TmzN.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const CONSOLE_ICONS = {\n info: '\\x1b[34mℹ\\x1b[0m', // Blue info icon\n focus: '\\x1b[34m➙\\x1b[0m', // Blue arrow icon\n success: '\\x1b[32m✔\\x1b[0m', // Green checkmark\n warning: '\\x1b[33m⚠\\x1b[0m', // Yellow warning icon\n error: '\\x1b[31m✖\\x1b[0m', // Red cross icon\n claude: '\\x1b[35m💬\\x1b[0m', // Speech bubble\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,gBAAgB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACT"}
|