@wise/wds-codemods 1.0.0 → 1.1.0

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 CHANGED
@@ -3,17 +3,22 @@
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 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.
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 started](#-getting-started)
14
- - [Commands](#commands)
15
- - [Key Features](#-key-features)
13
+ - [Getting Started](#-getting-started)
14
+ - [CLI Options](#cli-options)
15
+ - [Transform Engines](#-transform-engines)
16
+ - [jscodeshift Transforms](#jscodeshift-transforms)
17
+ - [AI Transforms](#ai-transforms)
16
18
  - [Available Transforms](#-available-transforms)
19
+ - [Button Transform](./src/transforms/button/README.md)
20
+ - [ListItem Transform](./src/transforms/list-item/README.md)
21
+ - [Key Features](#-key-features)
17
22
  - [Working with the Project Locally](#-working-with-the-project-locally)
18
23
  - [Writing Codemod Transforms](#-writing-codemod-transforms)
19
24
  - [Developer Documentation](#-developer-documentation)
@@ -26,12 +31,11 @@ The project provides a flexible CLI interface that allows you to run codemods ei
26
31
  via prompts or directly through command-line arguments. It includes intelligent package validation,
27
32
  monorepo support, and comprehensive reporting for manual review cases.
28
33
 
29
- ## 🚀 Getting started
34
+ ## 🚀 Getting Started
30
35
 
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:
36
+ ### Installation
33
37
 
34
- ### To get started, install the package
38
+ Install globally for convenience:
35
39
 
36
40
  ```bash
37
41
  # Using npm
@@ -44,7 +48,7 @@ pnpm add -g @wise/wds-codemods
44
48
  yarn global add @wise/wds-codemods
45
49
  ```
46
50
 
47
- Or, if you prefer, you can run it directly without installing globally:
51
+ Or run directly without installing:
48
52
 
49
53
  ```bash
50
54
  # Using npx
@@ -57,53 +61,60 @@ pnpm dlx @wise/wds-codemods
57
61
  yarn dlx @wise/wds-codemods
58
62
  ```
59
63
 
60
- ### Using Interactive Prompts
64
+ ### Running Codemods
61
65
 
62
- Simply run the codemod runner without any arguments:
66
+ You can run codemods in two ways:
63
67
 
64
- ```bash
65
- wds-codemods
66
- ```
68
+ #### Interactive Mode
67
69
 
68
- Or, if you prefer, you can run it directly using `npx` without installing globally:
70
+ Run without arguments to get interactive prompts:
69
71
 
70
72
  ```bash
71
- npx wds-codemods
73
+ wds-codemods
72
74
  ```
73
75
 
74
- You will be prompted to:
76
+ You'll be prompted to:
75
77
 
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).
78
+ 1. Select a transform (`button` or `list-item`)
79
+ 2. Enter target directory or file path
80
+ 3. Choose dry-run mode (preview without writing) (jscodeshift engine only)
81
+ 4. Choose whether to print transformed output
82
+ 5. Configure monorepo detection (auto-detected in most cases)
83
+ 6. Answer transform-specific configuration questions (jscodeshift engine only)
81
84
 
82
- ### Using CLI Arguments
85
+ #### Direct CLI Mode
83
86
 
84
- You can also run codemods directly by providing arguments:
87
+ Run with arguments for automation:
85
88
 
86
89
  ```bash
87
- wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
90
+ wds-codemods <transform> <targetPath> [options]
88
91
  ```
89
92
 
90
- Or using package runners:
93
+ Example:
91
94
 
92
95
  ```bash
93
- npx @wise/wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
96
+ wds-codemods button ./src --dry --print
94
97
  ```
95
98
 
96
- ## Commands
99
+ ## CLI Options
100
+
101
+ All codemods support these command-line options:
102
+
103
+ | Option | Description |
104
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------ |
105
+ | `--print` | Print transformed source to console |
106
+ | `--ignore-pattern=GLOB` | Ignore files matching [glob pattern(s)](https://code.visualstudio.com/docs/editor/glob-patterns) (comma-separated) |
107
+ | `--monorepo` | Enable monorepo package checking across workspace folders |
97
108
 
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.
109
+ Only jscodeshift engine supports the following options (.gitignore is always respected with AI Engine):
105
110
 
106
- Examples:
111
+ | Option | Description |
112
+ | --------------------- | ---------------------------------------- |
113
+ | `--dry` / `--dry-run` | Preview changes without writing to files |
114
+ | `--gitignore` | Respect `.gitignore` files |
115
+ | `--no-gitignore` | Ignore `.gitignore` files |
116
+
117
+ ### Common Examples
107
118
 
108
119
  ```bash
109
120
  # Basic transform with dry run
@@ -125,75 +136,100 @@ wds-codemods button ./packages --monorepo
125
136
  wds-codemods button ./src --print --dry
126
137
  ```
127
138
 
128
- ## 💻 Available Transforms
139
+ ## 🔧 Transform Engines
140
+
141
+ This project supports two types of transform engines, each suited for different transformation needs:
142
+
143
+ ### jscodeshift Engine
144
+
145
+ **Best for:** Predictable, rule-based transformations with clear input/output mappings.
146
+
147
+ **How it works:**
148
+
149
+ - Parses code into an Abstract Syntax Tree (AST)
150
+ - Applies deterministic transformations based on pattern matching
151
+ - Guarantees consistent results across runs
152
+
153
+ **Features:**
129
154
 
130
- ### Button Transform (`button`)
155
+ - Dry-run mode to preview changes without writing files
156
+ - Manual review reports for edge cases
157
+ - Fast execution on large codebases
131
158
 
132
- Migrates `Button` and `ActionButton` components from `@transferwise/components` (v46.5.0+) to the new v2 API.
159
+ **Prerequisites:**
133
160
 
134
- **Key Features:**
161
+ - Package version requirements (validated automatically)
135
162
 
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
163
+ **Example transforms:** Button migration
150
164
 
151
- **Configuration Options:**
165
+ ### AI Engine
152
166
 
153
- During transform execution, you'll be prompted to choose:
167
+ **Best for:** Complex, context-aware transformations that require understanding intent.
154
168
 
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`)
169
+ **How it works:**
157
170
 
158
- **Manual Review:**
171
+ - Uses Claude AI to migrate code based on pregenrated instructions
159
172
 
160
- The transform generates a `codemod-report.txt` file for cases requiring manual attention:
173
+ **Features:**
161
174
 
162
- - Spread props (`{...props}`)
163
- - Dynamic expressions that cannot be statically analyzed
164
- - Unsupported prop values
165
- - Ambiguous icon children (conditional rendering, complex expressions)
175
+ - Handles ambiguous cases that would require manual review in jscodeshift
176
+
177
+ **Prerequisites:**
178
+
179
+ - Access to Wise LLM Gateway
180
+ - Claude configured locally
181
+ - VPN connection
182
+ - Package version requirements (validated automatically)
183
+
184
+ **Example transforms:** ListItem migration
185
+
186
+ ---
187
+
188
+ ## 💻 Available Transforms
189
+
190
+ - **[Button](./src/transforms/button/README.md)** - Migrates `Button` and `ActionButton` to the new v2 API using jscodeshift
191
+ - **[ListItem](./src/transforms/list-item/README.md)** - Migrates legacy `Option` and `Summary` components to `ListItem` using Claude AI
166
192
 
167
193
  ---
168
194
 
169
195
  ## 🔧 Key Features
170
196
 
171
- ### Package Requirements Validation
197
+ ### Automatic Package Validation
172
198
 
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
199
+ Before running any transform, the codemod automatically:
200
+
201
+ - Validates required package versions (e.g., `@transferwise/components >=46.5.0`)
202
+ - Checks `package.json`, lockfiles, and `node_modules`
203
+ - Supports npm, pnpm, and yarn
204
+ - Skips packages that don't meet prerequisites with clear reporting
177
205
 
178
206
  ### Monorepo Support
179
207
 
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
208
+ - Auto-detects monorepo structures (`packages/`, `apps/`, `libs/`, etc.)
209
+ - Validates dependencies across all workspace packages
210
+ - Provides summary reports showing which packages are ready
211
+ - Manual monorepo mode for custom structures
212
+
213
+ ### Manual Review Reporting
214
+
215
+ **jscodeshift engine:**
216
+
217
+ - Generates `codemod-report.txt` for cases needing manual attention
218
+ - Includes file paths, line numbers, and specific issue descriptions
219
+ - Reports spread props, dynamic expressions, and unsupported values
220
+ - Auto-removes old reports and provides fresh summaries
184
221
 
185
- ### Manual Review Reports
222
+ **AI engine:**
186
223
 
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
224
+ - No report file generated
225
+ - Handles complex cases inline during transformation
191
226
 
192
- ### Intelligent Processing
227
+ ### Smart Processing
193
228
 
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
229
+ - Only runs on projects with compatible dependencies
230
+ - Efficient directory traversal and file filtering
231
+ - Graceful error handling for edge cases
232
+ - Performance-optimized for large codebases
197
233
 
198
234
  ---
199
235
 
@@ -353,7 +389,13 @@ For comprehensive development details, including transform architecture, helper
353
389
 
354
390
  [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.
355
391
 
356
- This project uses jscodeshift as the core engine to perform code transformations.
392
+ jscodeshift is one of two engines to perform code transformations.
393
+
394
+ ### @anthropic-ai/claude-agent-sdk
395
+
396
+ [@anthropic-ai/claude-agent-sdk](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk) is Anthropic's SDK for building AI-powered agents with Claude. It provides tools for creating context-aware transformations that can understand code semantics and intent.
397
+
398
+ Claude Agent SDK is one of two engines to perform code transformations
357
399
 
358
400
  ### @inquirer/prompts
359
401
 
@@ -369,4 +411,4 @@ This project uses @inquirer/prompts to provide a user-friendly interactive exper
369
411
 
370
412
  ## ✍️ Feedback
371
413
 
372
- 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).
414
+ Please ask any questions on this project, you can do so by reaching out on [Slack](https://wise.enterprise.slack.com/archives/CJNBX9CP6) or contributing to any [active issues](https://transferwise.atlassian.net/jira/software/projects/DS/boards/277/backlog).
@@ -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"}