@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 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 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.
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 Started](#-getting-started)
14
- - [CLI Options](#cli-options)
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 Started
29
+ ## 🚀 Getting started
32
30
 
33
- ### Installation
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
- Install globally for convenience:
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
- ### Running Codemods
60
+ ### Using Interactive Prompts
62
61
 
63
- You can run codemods in two ways:
62
+ Simply run the codemod runner without any arguments:
64
63
 
65
- #### Interactive Mode
64
+ ```bash
65
+ wds-codemods
66
+ ```
66
67
 
67
- Run without arguments to get interactive prompts:
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'll be prompted to:
74
+ You will be prompted to:
74
75
 
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)
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
- #### Direct CLI Mode
82
+ ### Using CLI Arguments
83
83
 
84
- Run with arguments for automation:
84
+ You can also run codemods directly by providing arguments:
85
85
 
86
86
  ```bash
87
- wds-codemods <transform> <targetPath> [options]
87
+ wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
88
88
  ```
89
89
 
90
- Example:
90
+ Or using package runners:
91
91
 
92
92
  ```bash
93
- wds-codemods button ./src --dry --print
93
+ npx @wise/wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
94
94
  ```
95
95
 
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:
96
+ ## Commands
107
97
 
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 |
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
- ### Common Examples
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
- We currently provide two codemods for migrating Wise Design System components:
130
+ ### Button Transform (`button`)
139
131
 
140
- ### 🔘 [Button Transform (`button`)](./README-BUTTON.md)
132
+ Migrates `Button` and `ActionButton` components from `@transferwise/components` (v46.5.0+) to the new v2 API.
141
133
 
142
- Migrates `Button` and `ActionButton` components from `@transferwise/components` to the new v2 API.
134
+ **Key Features:**
143
135
 
144
- - **Engine**: jscodeshift (AST-based transformations)
145
- - **Prerequisites**: `@transferwise/components >=46.5.0`
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
- **What it does:**
151
+ **Configuration Options:**
148
152
 
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
153
+ During transform execution, you'll be prompted to choose:
153
154
 
154
- **[→ Full Button Transform Documentation](./README-BUTTON.md)**
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
- - 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
160
+ The transform generates a `codemod-report.txt` file for cases requiring manual attention:
171
161
 
172
- **[→ Full ListItem Transform Documentation](./README-LIST-ITEM.md)**
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
- ### Automatic Package Validation
171
+ ### Package Requirements Validation
179
172
 
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
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-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
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
- **📋 ListItem transform:**
185
+ ### Manual Review Reports
204
186
 
205
- - No report file generated
206
- - Claude handles complex cases inline
207
- - Use `--print` to review diffs before applying
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
- ### Smart Processing
192
+ ### Intelligent Processing
210
193
 
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
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