@wise/wds-codemods 1.0.0-experimental-969b484 → 1.0.0-experimental-541a93b

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.
@@ -0,0 +1,344 @@
1
+ const require_helpers = require('./helpers-RWhTD5Is.js');
2
+ let node_child_process = require("node:child_process");
3
+ let node_path = require("node:path");
4
+ let node_fs = require("node:fs");
5
+ let __anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
6
+
7
+ //#region src/constants.ts
8
+ const CONSOLE_ICONS = {
9
+ info: "\x1B[34mℹ\x1B[0m",
10
+ focus: "\x1B[34m➙\x1B[0m",
11
+ success: "\x1B[32m✔\x1B[0m",
12
+ warning: "\x1B[33m⚠\x1B[0m",
13
+ error: "\x1B[31m✖\x1B[0m"
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/transforms/list-item/constants.ts
18
+ const DEPRECATED_COMPONENT_NAMES = [
19
+ "ActionOption",
20
+ "NavigationOption",
21
+ "NavigationOptionsList",
22
+ "Summary",
23
+ "SwitchOption",
24
+ "CheckboxOption",
25
+ "RadioOption"
26
+ ];
27
+ const MIGRATION_RULES = `Migration rules:
28
+ # Legacy Component → ListItem Migration Guide
29
+
30
+ ## Universal Rules
31
+
32
+ 1. Wrap all \`ListItem\` in \`<List>\`
33
+ 2. \`title\` → \`title\` (direct)
34
+ 3. \`content\` or \`description\` → \`subtitle\`
35
+ 4. \`disabled\` stays on \`ListItem\` (not controls)
36
+ 5. Keep HTML attributes (\`id\`, \`name\`, \`aria-label\`), remove: \`as\`, \`complex\`, \`showMediaAtAllSizes\`, \`showMediaCircle\`, \`isContainerAligned\`
37
+
38
+ ---
39
+
40
+ ## ActionOption → ListItem.Button
41
+
42
+ - \`action\` → Button children
43
+ - \`onClick\` → Button \`onClick\`
44
+ - Priority: default/\`"primary"\` → \`"primary"\`, \`"secondary"\` → \`"secondary-neutral"\`, \`"secondary-send"\` → \`"secondary"\`, \`"tertiary"\` → \`"tertiary"\`
45
+
46
+ \`\`\`tsx
47
+ <ActionOption title="Title" content="Text" action="Click" priority="secondary" onClick={fn} />
48
+
49
+ <List><ListItem title="Title" subtitle="Text" control={<ListItem.Button priority="secondary-neutral" onClick={fn}>Click</ListItem.Button>} /></List>
50
+ \`\`\`
51
+
52
+ ---
53
+
54
+ ## CheckboxOption → ListItem.Checkbox
55
+
56
+ - \`onChange\`: \`(checked: boolean)\` → \`(event: ChangeEvent)\` use \`event.target.checked\`
57
+ - \`id\`, \`name\` move to Checkbox
58
+
59
+ \`\`\`tsx
60
+ <CheckboxOption id="x" name="y" title="Title" content="Text" checked={v} onChange={(c) => set(c)} />
61
+
62
+ <List><ListItem title="Title" subtitle="Text" control={<ListItem.Checkbox id="x" name="y" checked={v} onChange={(e) => set(e.target.checked)} />} /></List>
63
+ \`\`\`
64
+
65
+ ---
66
+
67
+ ## RadioOption → ListItem.Radio
68
+
69
+ - \`id\`, \`name\`, \`value\`, \`checked\`, \`onChange\` move to Radio
70
+
71
+ \`\`\`tsx
72
+ <RadioOption id="x" name="y" value="v" title="Title" content="Text" checked={v==='v'} onChange={set} />
73
+
74
+ <List><ListItem title="Title" subtitle="Text" control={<ListItem.Radio id="x" name="y" value="v" checked={v==='v'} onChange={set} />} /></List>
75
+ \`\`\`
76
+
77
+ ---
78
+
79
+ ## SwitchOption → ListItem.Switch
80
+
81
+ - \`onChange\` → \`onClick\`, toggle manually
82
+ - \`aria-label\` moves to Switch
83
+
84
+ \`\`\`tsx
85
+ <SwitchOption title="Title" content="Text" checked={v} aria-label="Toggle" onChange={set} />
86
+
87
+ <List><ListItem title="Title" subtitle="Text" control={<ListItem.Switch checked={v} aria-label="Toggle" onClick={() => set(!v)} />} /></List>
88
+ \`\`\`
89
+
90
+ ---
91
+
92
+ ## NavigationOption → ListItem.Navigation
93
+
94
+ - \`onClick\` or \`href\` move to Navigation
95
+
96
+ \`\`\`tsx
97
+ <NavigationOption title="Title" content="Text" onClick={fn} />
98
+
99
+ <List><ListItem title="Title" subtitle="Text" control={<ListItem.Navigation onClick={fn} />} /></List>
100
+ \`\`\`
101
+
102
+ ---
103
+
104
+ ## Option → ListItem
105
+
106
+ - Wrap \`media\` in \`ListItem.AvatarView\`
107
+
108
+ \`\`\`tsx
109
+ <Option media={<Icon />} title="Title" />
110
+
111
+ <List><ListItem title="Title" media={<ListItem.AvatarView><Icon /></ListItem.AvatarView>} /></List>
112
+ \`\`\`
113
+
114
+ ---
115
+
116
+ ## Summary → ListItem
117
+
118
+ **Basic:**
119
+
120
+ - \`icon\` → wrap in \`ListItem.AvatarView\` with \`size={32}\` as \`media\`
121
+
122
+ **Status:**
123
+
124
+ - \`Status.DONE\` → \`badge={{ status: 'positive' }}\`
125
+ - \`Status.PENDING\` → \`badge={{ status: 'pending' }}\`
126
+ - \`Status.NOT_DONE\` → no badge
127
+
128
+ **Action:**
129
+
130
+ - \`action.text\` → \`action.label\` in \`ListItem.AdditionalInfo\` as \`additionalInfo\`
131
+
132
+ **Info (requires state):**
133
+
134
+ - \`MODAL\` → \`ListItem.IconButton partiallyInteractive\` + \`<Modal>\` in \`control\`
135
+ - \`POPOVER\` → \`<Popover>\` wrapping \`ListItem.IconButton partiallyInteractive\` in \`control\`
136
+ - Use \`QuestionMarkCircle\` icon
137
+
138
+ \`\`\`tsx
139
+ // Basic
140
+ <Summary title="T" description="D" icon={<Icon />} />
141
+
142
+ <List><ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} /></List>
143
+
144
+ // Status
145
+ <Summary title="T" description="D" icon={<Icon />} status={Status.DONE} />
146
+
147
+ <List><ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32} badge={{status:'positive'}}><Icon /></ListItem.AvatarView>} /></List>
148
+
149
+ // Action
150
+ <Summary title="T" description="D" icon={<Icon />} action={{text:'Go', href:'/go'}} />
151
+
152
+ <List><ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} additionalInfo={<ListItem.AdditionalInfo action={{label:'Go', href:'/go'}} />} /></List>
153
+
154
+ // Modal (add: const [open, setOpen] = useState(false))
155
+ <Summary title="T" description="D" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'MODAL', 'aria-label':'Info'}} />
156
+
157
+ <List><ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={<ListItem.IconButton partiallyInteractive aria-label="Info" onClick={()=>setOpen(!open)}><QuestionMarkCircle /><Modal open={open} title="Help" body="Text" onClose={()=>setOpen(false)} /></ListItem.IconButton>} /></List>
158
+
159
+ // Popover
160
+ <Summary title="T" description="D" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'POPOVER', 'aria-label':'Info'}} />
161
+
162
+ <List><ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={<Popover title="Help" content="Text" onClose={()=>setOpen(false)}><ListItem.IconButton partiallyInteractive aria-label="Info"><QuestionMarkCircle /></ListItem.IconButton></Popover>} /></List>
163
+ \`\`\`
164
+
165
+ ---
166
+
167
+ ## DefinitionList → Multiple ListItem
168
+
169
+ - Array → individual \`ListItem\`s
170
+ - \`value\` → \`subtitle\`
171
+ - \`key\` → React \`key\` prop
172
+ - Action type: "Edit"/"Update"/"View" → \`ListItem.Button priority="secondary-neutral"\`, "Change"/"Password" → \`ListItem.Navigation\`, "Copy" → \`ListItem.IconButton\`
173
+
174
+ \`\`\`tsx
175
+ <DefinitionList definitions={[
176
+ {title:'T1', value:'V1', key:'k1'},
177
+ {title:'T2', value:'V2', key:'k2', action:{label:'Edit', onClick:fn}}
178
+ ]} />
179
+
180
+ <List>
181
+ <ListItem key="k1" title="T1" subtitle="V1" />
182
+ <ListItem key="k2" title="T2" subtitle="V2" control={<ListItem.Button priority="secondary-neutral" onClick={fn}>Edit</ListItem.Button>} />
183
+ </List>
184
+ \`\`\`
185
+ `;
186
+ const SYSTEM_PROMPT = `Transform TypeScript/JSX code from legacy Wise Design System (WDS) components to the new ListItem component and ListItem subcomponents from '@transferwise/components'.
187
+
188
+ Read and transform each file individually, instead of reading them all at the start. Only make a single edit or write per file, once you've fully processed it.
189
+
190
+ Rules:
191
+ 1. Ignore any files that do not contain deprecated WDS components, unless they are necessary for context.
192
+ 2. Migrate components per provided migration rules
193
+ 3. Maintain TypeScript type safety and update types to match new API
194
+ 4. Map props: handle renamed, deprecated, new required, and changed types
195
+ 5. Update imports to new WDS components and types
196
+ 6. Preserve code style, formatting, and calculated logic
197
+ 7. Handle conditional rendering, spread props, and complex expressions
198
+ 8. Note: New components may lack feature parity with legacy versions
199
+ 9. Only modify code requiring changes per migration rules, and any impacted surrounding code for context.
200
+ 10. Provide only the transformed code as output, without explanations or additional text
201
+ 11. Do not summarise the initial user request in a response.
202
+ 12. Use glob or grep tool usage to find the files with deprecated components.
203
+ 13. Final result response should just be whether the migration was successful overall, or if any errors were encountered
204
+
205
+ Make the necessary updates to the files and do not respond with any explanations or reasoning.
206
+
207
+ You'll receive:
208
+ - File paths/directories to search in individual queries
209
+ - Deprecated component names at the end of this prompt
210
+ - Migration context and rules for each deprecated component
211
+
212
+ Deprecated components: ${DEPRECATED_COMPONENT_NAMES.join(", ")}.
213
+
214
+ ${MIGRATION_RULES}`;
215
+
216
+ //#endregion
217
+ //#region src/transforms/list-item/helpers.ts
218
+ /** Split the path to get the relative path after the directory, and wrap with ANSI color codes */
219
+ function formatPathOutput(directory, path) {
220
+ return `\x1b[32m${path ? path.split(directory)[1] ?? path : directory}\x1b[0m`;
221
+ }
222
+ /** Generates a formatted string representing the total elapsed time since the given start time */
223
+ function generateElapsedTime(startTime) {
224
+ const endTime = Date.now();
225
+ const elapsedTime = Math.floor((endTime - startTime) / 1e3);
226
+ const hours = Math.floor(elapsedTime / 3600);
227
+ const minutes = Math.floor(elapsedTime % 3600 / 60);
228
+ const seconds = elapsedTime % 60;
229
+ return `${hours ? `${hours}h ` : ""}${minutes ? `${minutes}m ` : ""}${seconds ? `${seconds}s` : ""}`;
230
+ }
231
+
232
+ //#endregion
233
+ //#region src/transforms/list-item/claude.ts
234
+ const CLAUDE_SETTINGS_FILE = ".claude/settings.json";
235
+ function getQueryOptions(sessionId, isDebug) {
236
+ const claudeSettingsPath = (0, node_path.resolve)(process.env.HOME || "", CLAUDE_SETTINGS_FILE);
237
+ const settings = JSON.parse((0, node_fs.readFileSync)(claudeSettingsPath, "utf-8"));
238
+ let apiKey;
239
+ try {
240
+ apiKey = (0, node_child_process.execSync)(`bash ${settings.apiKeyHelper}`, { encoding: "utf-8" }).trim();
241
+ } catch {}
242
+ if (!apiKey) throw new Error("Failed to retrieve Anthropic API key. Please check your Claude Code x LLM Gateway configuration - https://transferwise.atlassian.net/wiki/x/_YUe3Q");
243
+ const envVars = {
244
+ ANTHROPIC_AUTH_TOKEN: apiKey,
245
+ ANTHROPIC_BASE_URL: settings?.env?.ANTHROPIC_BASE_URL,
246
+ ANTHROPIC_CUSTOM_HEADERS: settings?.env?.ANTHROPIC_CUSTOM_HEADERS,
247
+ ANTHROPIC_DEFAULT_SONNET_MODEL: settings.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,
248
+ ANTHROPIC_DEFAULT_HAIKU_MODEL: settings.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,
249
+ ANTHROPIC_DEFAULT_OPUS_MODEL: settings.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,
250
+ API_TIMEOUT_MS: settings.env?.API_TIMEOUT_MS,
251
+ PATH: process.env.PATH
252
+ };
253
+ if (isDebug) {
254
+ const { ANTHROPIC_AUTH_TOKEN, ...restVars } = envVars;
255
+ console.log(`${CONSOLE_ICONS.info} Claude configuration environment variables:`, JSON.stringify(restVars));
256
+ }
257
+ return {
258
+ resume: sessionId,
259
+ env: envVars,
260
+ permissionMode: "acceptEdits",
261
+ systemPrompt: {
262
+ type: "preset",
263
+ preset: "claude_code",
264
+ append: SYSTEM_PROMPT
265
+ },
266
+ settingSources: [
267
+ "local",
268
+ "project",
269
+ "user"
270
+ ]
271
+ };
272
+ }
273
+ /** Initiate a new Claude session/conversation and return reusable options */
274
+ async function initiateClaudeSessionOptions(isDebug = false) {
275
+ console.log(`${CONSOLE_ICONS.info} Starting Claude instance - your browser may open for Okta authentication if required.`);
276
+ const options = getQueryOptions(void 0, isDebug);
277
+ const result = (0, __anthropic_ai_claude_agent_sdk.query)({
278
+ options,
279
+ prompt: `You'll be given directories in additional individual queries to search in for files using deprecated Wise Design System (WDS) components. Migrate the code per the provided migration rules.`
280
+ });
281
+ for await (const message of result) switch (message.type) {
282
+ case "system":
283
+ if (message.subtype === "init" && !options.resume) {
284
+ console.log(`${CONSOLE_ICONS.success} Successfully initialised Claude instance`);
285
+ options.resume = message.session_id;
286
+ }
287
+ break;
288
+ default: if (message.type === "result" && message.subtype !== "success") console.log(`${CONSOLE_ICONS.error} Claude encountered an error: ${message.errors.join("\n")}`);
289
+ }
290
+ return options;
291
+ }
292
+ async function queryClaude(path, options, isDebug = false) {
293
+ const result = (0, __anthropic_ai_claude_agent_sdk.query)({
294
+ options,
295
+ prompt: path
296
+ });
297
+ const modifiedFiles = [];
298
+ for await (const message of result) switch (message.type) {
299
+ case "assistant":
300
+ for (const msg of message.message.content) switch (msg.type) {
301
+ case "tool_use":
302
+ if (msg.name === "Glob" || msg.name === "Grep") console.log(`${CONSOLE_ICONS.focus} Processing directory: ${formatPathOutput(path)}...`);
303
+ else if (msg.name === "Read") console.log(`${CONSOLE_ICONS.info} Reading ${formatPathOutput(path, msg.input.file_path)}`);
304
+ else if ((msg.name === "Write" || msg.name === "Edit") && !modifiedFiles.includes(msg.input.file_path)) {
305
+ modifiedFiles.push(msg.input.file_path);
306
+ console.log(`${CONSOLE_ICONS.info} Migrated ${formatPathOutput(path, msg.input.file_path)}`);
307
+ }
308
+ break;
309
+ default:
310
+ }
311
+ break;
312
+ case "result":
313
+ if (message.subtype === "success") console.log(`${CONSOLE_ICONS.success} Migrated all applicable files in ${formatPathOutput(path)}`);
314
+ else console.log(`${CONSOLE_ICONS.error} Claude encountered an error: ${message.errors.join("\n").trim()}`);
315
+ break;
316
+ default:
317
+ }
318
+ }
319
+
320
+ //#endregion
321
+ //#region src/transforms/list-item/transformer.ts
322
+ const transformer = async (targetPaths, codemodPath, isDebug = false) => {
323
+ const startTime = Date.now();
324
+ const queryOptions = await initiateClaudeSessionOptions(isDebug);
325
+ console.log(`${CONSOLE_ICONS.info} Analysing targetted paths - this may take a while...`);
326
+ for (const directory of targetPaths) if (require_helpers.assessPrerequisites(directory, codemodPath)) await queryClaude(directory, queryOptions, isDebug);
327
+ console.log(`${CONSOLE_ICONS.success} Finished migrating - elapsed time: \x1b[1m${generateElapsedTime(startTime)}\x1b[0m`);
328
+ };
329
+ var transformer_default = transformer;
330
+
331
+ //#endregion
332
+ Object.defineProperty(exports, 'CONSOLE_ICONS', {
333
+ enumerable: true,
334
+ get: function () {
335
+ return CONSOLE_ICONS;
336
+ }
337
+ });
338
+ Object.defineProperty(exports, 'transformer_default', {
339
+ enumerable: true,
340
+ get: function () {
341
+ return transformer_default;
342
+ }
343
+ });
344
+ //# sourceMappingURL=transformer-BxHkGbvJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer-BxHkGbvJ.js","names":["modifiedFiles: string[]","assessPrerequisites"],"sources":["../src/constants.ts","../src/transforms/list-item/constants.ts","../src/transforms/list-item/helpers.ts","../src/transforms/list-item/claude.ts","../src/transforms/list-item/transformer.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};\n","const DEPRECATED_COMPONENT_NAMES = [\n 'ActionOption',\n 'NavigationOption',\n 'NavigationOptionsList',\n 'Summary',\n 'SwitchOption',\n 'CheckboxOption',\n 'RadioOption',\n];\n\nconst MIGRATION_RULES = `Migration rules:\n# Legacy Component → ListItem Migration Guide\n\n## Universal Rules\n\n1. Wrap all \\`ListItem\\` in \\`<List>\\`\n2. \\`title\\` → \\`title\\` (direct)\n3. \\`content\\` or \\`description\\` → \\`subtitle\\`\n4. \\`disabled\\` stays on \\`ListItem\\` (not controls)\n5. Keep HTML attributes (\\`id\\`, \\`name\\`, \\`aria-label\\`), remove: \\`as\\`, \\`complex\\`, \\`showMediaAtAllSizes\\`, \\`showMediaCircle\\`, \\`isContainerAligned\\`\n\n---\n\n## ActionOption → ListItem.Button\n\n- \\`action\\` → Button children\n- \\`onClick\\` → Button \\`onClick\\`\n- Priority: default/\\`\"primary\"\\` → \\`\"primary\"\\`, \\`\"secondary\"\\` → \\`\"secondary-neutral\"\\`, \\`\"secondary-send\"\\` → \\`\"secondary\"\\`, \\`\"tertiary\"\\` → \\`\"tertiary\"\\`\n\n\\`\\`\\`tsx\n<ActionOption title=\"Title\" content=\"Text\" action=\"Click\" priority=\"secondary\" onClick={fn} />\n→\n<List><ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Button priority=\"secondary-neutral\" onClick={fn}>Click</ListItem.Button>} /></List>\n\\`\\`\\`\n\n---\n\n## CheckboxOption → ListItem.Checkbox\n\n- \\`onChange\\`: \\`(checked: boolean)\\` → \\`(event: ChangeEvent)\\` use \\`event.target.checked\\`\n- \\`id\\`, \\`name\\` move to Checkbox\n\n\\`\\`\\`tsx\n<CheckboxOption id=\"x\" name=\"y\" title=\"Title\" content=\"Text\" checked={v} onChange={(c) => set(c)} />\n→\n<List><ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Checkbox id=\"x\" name=\"y\" checked={v} onChange={(e) => set(e.target.checked)} />} /></List>\n\\`\\`\\`\n\n---\n\n## RadioOption → ListItem.Radio\n\n- \\`id\\`, \\`name\\`, \\`value\\`, \\`checked\\`, \\`onChange\\` move to Radio\n\n\\`\\`\\`tsx\n<RadioOption id=\"x\" name=\"y\" value=\"v\" title=\"Title\" content=\"Text\" checked={v==='v'} onChange={set} />\n→\n<List><ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Radio id=\"x\" name=\"y\" value=\"v\" checked={v==='v'} onChange={set} />} /></List>\n\\`\\`\\`\n\n---\n\n## SwitchOption → ListItem.Switch\n\n- \\`onChange\\` → \\`onClick\\`, toggle manually\n- \\`aria-label\\` moves to Switch\n\n\\`\\`\\`tsx\n<SwitchOption title=\"Title\" content=\"Text\" checked={v} aria-label=\"Toggle\" onChange={set} />\n→\n<List><ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Switch checked={v} aria-label=\"Toggle\" onClick={() => set(!v)} />} /></List>\n\\`\\`\\`\n\n---\n\n## NavigationOption → ListItem.Navigation\n\n- \\`onClick\\` or \\`href\\` move to Navigation\n\n\\`\\`\\`tsx\n<NavigationOption title=\"Title\" content=\"Text\" onClick={fn} />\n→\n<List><ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Navigation onClick={fn} />} /></List>\n\\`\\`\\`\n\n---\n\n## Option → ListItem\n\n- Wrap \\`media\\` in \\`ListItem.AvatarView\\`\n\n\\`\\`\\`tsx\n<Option media={<Icon />} title=\"Title\" />\n→\n<List><ListItem title=\"Title\" media={<ListItem.AvatarView><Icon /></ListItem.AvatarView>} /></List>\n\\`\\`\\`\n\n---\n\n## Summary → ListItem\n\n**Basic:**\n\n- \\`icon\\` → wrap in \\`ListItem.AvatarView\\` with \\`size={32}\\` as \\`media\\`\n\n**Status:**\n\n- \\`Status.DONE\\` → \\`badge={{ status: 'positive' }}\\`\n- \\`Status.PENDING\\` → \\`badge={{ status: 'pending' }}\\`\n- \\`Status.NOT_DONE\\` → no badge\n\n**Action:**\n\n- \\`action.text\\` → \\`action.label\\` in \\`ListItem.AdditionalInfo\\` as \\`additionalInfo\\`\n\n**Info (requires state):**\n\n- \\`MODAL\\` → \\`ListItem.IconButton partiallyInteractive\\` + \\`<Modal>\\` in \\`control\\`\n- \\`POPOVER\\` → \\`<Popover>\\` wrapping \\`ListItem.IconButton partiallyInteractive\\` in \\`control\\`\n- Use \\`QuestionMarkCircle\\` icon\n\n\\`\\`\\`tsx\n// Basic\n<Summary title=\"T\" description=\"D\" icon={<Icon />} />\n→\n<List><ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} /></List>\n\n// Status\n<Summary title=\"T\" description=\"D\" icon={<Icon />} status={Status.DONE} />\n→\n<List><ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32} badge={{status:'positive'}}><Icon /></ListItem.AvatarView>} /></List>\n\n// Action\n<Summary title=\"T\" description=\"D\" icon={<Icon />} action={{text:'Go', href:'/go'}} />\n→\n<List><ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} additionalInfo={<ListItem.AdditionalInfo action={{label:'Go', href:'/go'}} />} /></List>\n\n// Modal (add: const [open, setOpen] = useState(false))\n<Summary title=\"T\" description=\"D\" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'MODAL', 'aria-label':'Info'}} />\n→\n<List><ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={<ListItem.IconButton partiallyInteractive aria-label=\"Info\" onClick={()=>setOpen(!open)}><QuestionMarkCircle /><Modal open={open} title=\"Help\" body=\"Text\" onClose={()=>setOpen(false)} /></ListItem.IconButton>} /></List>\n\n// Popover\n<Summary title=\"T\" description=\"D\" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'POPOVER', 'aria-label':'Info'}} />\n→\n<List><ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={<Popover title=\"Help\" content=\"Text\" onClose={()=>setOpen(false)}><ListItem.IconButton partiallyInteractive aria-label=\"Info\"><QuestionMarkCircle /></ListItem.IconButton></Popover>} /></List>\n\\`\\`\\`\n\n---\n\n## DefinitionList → Multiple ListItem\n\n- Array → individual \\`ListItem\\`s\n- \\`value\\` → \\`subtitle\\`\n- \\`key\\` → React \\`key\\` prop\n- Action type: \"Edit\"/\"Update\"/\"View\" → \\`ListItem.Button priority=\"secondary-neutral\"\\`, \"Change\"/\"Password\" → \\`ListItem.Navigation\\`, \"Copy\" → \\`ListItem.IconButton\\`\n\n\\`\\`\\`tsx\n<DefinitionList definitions={[\n {title:'T1', value:'V1', key:'k1'},\n {title:'T2', value:'V2', key:'k2', action:{label:'Edit', onClick:fn}}\n]} />\n→\n<List>\n <ListItem key=\"k1\" title=\"T1\" subtitle=\"V1\" />\n <ListItem key=\"k2\" title=\"T2\" subtitle=\"V2\" control={<ListItem.Button priority=\"secondary-neutral\" onClick={fn}>Edit</ListItem.Button>} />\n</List>\n\\`\\`\\`\n`;\n\nexport const SYSTEM_PROMPT = `Transform TypeScript/JSX code from legacy Wise Design System (WDS) components to the new ListItem component and ListItem subcomponents from '@transferwise/components'.\n\nRead and transform each file individually, instead of reading them all at the start. Only make a single edit or write per file, once you've fully processed it.\n\nRules:\n1. Ignore any files that do not contain deprecated WDS components, unless they are necessary for context.\n2. Migrate components per provided migration rules\n3. Maintain TypeScript type safety and update types to match new API\n4. Map props: handle renamed, deprecated, new required, and changed types\n5. Update imports to new WDS components and types\n6. Preserve code style, formatting, and calculated logic\n7. Handle conditional rendering, spread props, and complex expressions\n8. Note: New components may lack feature parity with legacy versions\n9. Only modify code requiring changes per migration rules, and any impacted surrounding code for context.\n10. Provide only the transformed code as output, without explanations or additional text\n11. Do not summarise the initial user request in a response.\n12. Use glob or grep tool usage to find the files with deprecated components.\n13. Final result response should just be whether the migration was successful overall, or if any errors were encountered\n\nMake the necessary updates to the files and do not respond with any explanations or reasoning. \n\nYou'll receive:\n- File paths/directories to search in individual queries\n- Deprecated component names at the end of this prompt\n- Migration context and rules for each deprecated component\n\nDeprecated components: ${DEPRECATED_COMPONENT_NAMES.join(', ')}.\n\n${MIGRATION_RULES}`;\n","/** Split the path to get the relative path after the directory, and wrap with ANSI color codes */\nexport function formatPathOutput(directory: string, path?: string): string {\n return `\\x1b[32m${path ? (path.split(directory)[1] ?? path) : directory}\\x1b[0m`;\n}\n\n/** Generates a formatted string representing the total elapsed time since the given start time */\nexport function generateElapsedTime(startTime: number): string {\n const endTime = Date.now();\n const elapsedTime = Math.floor((endTime - startTime) / 1000);\n const hours = Math.floor(elapsedTime / 3600);\n const minutes = Math.floor((elapsedTime % 3600) / 60);\n const seconds = elapsedTime % 60;\n\n return `${hours ? `${hours}h ` : ''}${minutes ? `${minutes}m ` : ''}${seconds ? `${seconds}s` : ''}`;\n}\n","import { type Options, query } from '@anthropic-ai/claude-agent-sdk';\nimport { execSync } from 'child_process';\nimport { readFileSync } from 'fs';\nimport { resolve } from 'path';\n\nimport { CONSOLE_ICONS } from '../../constants';\nimport { SYSTEM_PROMPT } from './constants';\nimport { formatPathOutput } from './helpers';\nimport type { ClaudeResponseToolUse, ClaudeSettings } from './types';\n\nconst CLAUDE_SETTINGS_FILE = '.claude/settings.json';\n\nexport function getQueryOptions(sessionId?: string, isDebug?: boolean): Options {\n // Read settings from ~/.claude/settings.json to get headers and apiKeyHelper\n const claudeSettingsPath = resolve(process.env.HOME || '', CLAUDE_SETTINGS_FILE);\n const settings = JSON.parse(readFileSync(claudeSettingsPath, 'utf-8')) as ClaudeSettings;\n\n // Get API key by executing the apiKeyHelper script, for authenticating with Okta via LLM Gateway\n let apiKey;\n try {\n apiKey = execSync(`bash ${settings.apiKeyHelper}`, {\n encoding: 'utf-8',\n }).trim();\n } catch {}\n\n if (!apiKey) {\n throw new Error(\n 'Failed to retrieve Anthropic API key. Please check your Claude Code x LLM Gateway configuration - https://transferwise.atlassian.net/wiki/x/_YUe3Q',\n );\n }\n\n const envVars = {\n ANTHROPIC_AUTH_TOKEN: apiKey,\n ANTHROPIC_BASE_URL: settings?.env?.ANTHROPIC_BASE_URL,\n ANTHROPIC_CUSTOM_HEADERS: settings?.env?.ANTHROPIC_CUSTOM_HEADERS,\n ANTHROPIC_DEFAULT_SONNET_MODEL: settings.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,\n ANTHROPIC_DEFAULT_HAIKU_MODEL: settings.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,\n ANTHROPIC_DEFAULT_OPUS_MODEL: settings.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,\n API_TIMEOUT_MS: settings.env?.API_TIMEOUT_MS,\n PATH: process.env.PATH, // Specifying PATH, as Claude Agent SDK seems to struggle consuming the actual environment PATH\n };\n\n if (isDebug) {\n // Not logging the auth token for security reasons\n const { ANTHROPIC_AUTH_TOKEN, ...restVars } = envVars;\n console.log(\n `${CONSOLE_ICONS.info} Claude configuration environment variables:`,\n JSON.stringify(restVars),\n );\n }\n\n return {\n resume: sessionId,\n env: envVars,\n permissionMode: 'acceptEdits',\n systemPrompt: {\n type: 'preset',\n preset: 'claude_code',\n append: SYSTEM_PROMPT,\n },\n settingSources: ['local', 'project', 'user'],\n };\n}\n\n/** Initiate a new Claude session/conversation and return reusable options */\nexport async function initiateClaudeSessionOptions(isDebug = false): Promise<Options> {\n console.log(\n `${CONSOLE_ICONS.info} Starting Claude instance - your browser may open for Okta authentication if required.`,\n );\n\n const options = getQueryOptions(undefined, isDebug);\n const result = query({\n options,\n prompt: `You'll be given directories in additional individual queries to search in for files using deprecated Wise Design System (WDS) components. Migrate the code per the provided migration rules.`,\n });\n\n for await (const message of result) {\n switch (message.type) {\n case 'system':\n if (message.subtype === 'init' && !options.resume) {\n console.log(`${CONSOLE_ICONS.success} Successfully initialised Claude instance`);\n\n // Set the session ID to resume the conversation in future queries\n options.resume = message.session_id;\n }\n break;\n default:\n if (message.type === 'result' && message.subtype !== 'success') {\n console.log(\n `${CONSOLE_ICONS.error} Claude encountered an error: ${message.errors.join('\\n')}`,\n );\n }\n }\n }\n\n return options;\n}\n\nexport async function queryClaude(path: string, options: Options, isDebug = false) {\n const result = query({\n options,\n prompt: path,\n });\n const modifiedFiles: string[] = [];\n\n for await (const message of result) {\n switch (message.type) {\n case 'assistant':\n for (const msg of message.message.content) {\n switch (msg.type) {\n // Handles logging of tool uses to determine key stages of the migration ()\n case 'tool_use':\n if (msg.name === 'Glob' || msg.name === 'Grep') {\n console.log(\n `${CONSOLE_ICONS.focus} Processing directory: ${formatPathOutput(path)}...`,\n );\n // NOTE: Possibly want to only log reading files when in debug mode, to reduce noise\n } else if (msg.name === 'Read') {\n console.log(\n `${CONSOLE_ICONS.info} Reading ${formatPathOutput(path, (msg as ClaudeResponseToolUse).input.file_path)}`,\n );\n } else if (\n (msg.name === 'Write' || msg.name === 'Edit') &&\n !modifiedFiles.includes((msg as ClaudeResponseToolUse).input.file_path) // Safeguard against duplicate logs, where Claude may write multiple times to the same file\n ) {\n modifiedFiles.push((msg as ClaudeResponseToolUse).input.file_path);\n console.log(\n `${CONSOLE_ICONS.info} Migrated ${formatPathOutput(path, (msg as ClaudeResponseToolUse).input.file_path)}`,\n );\n }\n break;\n default:\n }\n }\n break;\n case 'result':\n if (message.subtype === 'success') {\n // TODO: Handle case where migration failed for some files?\n console.log(\n `${CONSOLE_ICONS.success} Migrated all applicable files in ${formatPathOutput(path)}`,\n );\n } else {\n console.log(\n `${CONSOLE_ICONS.error} Claude encountered an error: ${message.errors.join('\\n').trim()}`,\n );\n }\n break;\n default:\n }\n }\n}\n","import { CONSOLE_ICONS } from '../../constants';\nimport { assessPrerequisites } from '../../controller/helpers';\nimport { initiateClaudeSessionOptions, queryClaude } from './claude';\nimport { generateElapsedTime } from './helpers';\n\nconst transformer = async (targetPaths: string[], codemodPath: string, isDebug = false) => {\n const startTime = Date.now();\n\n // TODO: We need to check whether the user is connected to the VPN\n\n const queryOptions = await initiateClaudeSessionOptions(isDebug);\n\n console.log(`${CONSOLE_ICONS.info} Analysing targetted paths - this may take a while...`);\n\n for (const directory of targetPaths) {\n const isCompliant = assessPrerequisites(directory, codemodPath);\n\n if (isCompliant) {\n // TODO: Potential improvement could be getting all of the file paths first -\n // Make sure claude can still handle related files (imported components/wrapping parents)\n // Get all files within directory, and call queryClaude for each file\n await queryClaude(directory, queryOptions, isDebug);\n }\n\n // await queryClaude(directory, queryOptions, isDebug);\n }\n\n console.log(\n `${CONSOLE_ICONS.success} Finished migrating - elapsed time: \\x1b[1m${generateElapsedTime(startTime)}\\x1b[0m`,\n );\n};\n\nexport default transformer;\n"],"mappings":";;;;;;;AAAA,MAAa,gBAAgB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS;CACT,SAAS;CACT,OAAO;CACR;;;;ACND,MAAM,6BAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgKxB,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;yBA0BJ,2BAA2B,KAAK,KAAK,CAAC;;EAE7D;;;;;ACrMF,SAAgB,iBAAiB,WAAmB,MAAuB;AACzE,QAAO,WAAW,OAAQ,KAAK,MAAM,UAAU,CAAC,MAAM,OAAQ,UAAU;;;AAI1E,SAAgB,oBAAoB,WAA2B;CAC7D,MAAM,UAAU,KAAK,KAAK;CAC1B,MAAM,cAAc,KAAK,OAAO,UAAU,aAAa,IAAK;CAC5D,MAAM,QAAQ,KAAK,MAAM,cAAc,KAAK;CAC5C,MAAM,UAAU,KAAK,MAAO,cAAc,OAAQ,GAAG;CACrD,MAAM,UAAU,cAAc;AAE9B,QAAO,GAAG,QAAQ,GAAG,MAAM,MAAM,KAAK,UAAU,GAAG,QAAQ,MAAM,KAAK,UAAU,GAAG,QAAQ,KAAK;;;;;ACHlG,MAAM,uBAAuB;AAE7B,SAAgB,gBAAgB,WAAoB,SAA4B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,6CAA6C,oBAAoB,UAAU,CAAC,SACtG;;AAGH,0BAAe"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_helpers = require('../../helpers-BneL7s1f.js');
2
+ const require_helpers = require('../../helpers-RWhTD5Is.js');
3
3
 
4
4
  //#region src/helpers/addImport.ts
5
5
  /**
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "claude",
3
+ "prerequisites": {
4
+ "@transferwise/components": ">=46.107.0"
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ require('../../helpers-RWhTD5Is.js');
2
+ const require_transformer = require('../../transformer-BxHkGbvJ.js');
3
+
4
+ module.exports = require_transformer.transformer_default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/wds-codemods",
3
- "version": "1.0.0-experimental-969b484",
3
+ "version": "1.0.0-experimental-541a93b",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Wise Payments Ltd.",
6
6
  "repository": {
@@ -34,10 +34,12 @@
34
34
  "test:watch": "jest --watch"
35
35
  },
36
36
  "dependencies": {
37
+ "@anthropic-ai/claude-agent-sdk": "^0.1.37",
37
38
  "@inquirer/prompts": "^7.8.6",
38
39
  "jscodeshift": "^17.3"
39
40
  },
40
41
  "devDependencies": {
42
+ "@anthropic-ai/sdk": "^0.68.0",
41
43
  "@babel/core": "^7.28.4",
42
44
  "@babel/plugin-syntax-import-meta": "^7.10.4",
43
45
  "@babel/preset-env": "^7.28.3",
@@ -64,7 +66,7 @@
64
66
  "semver": "^7.7.2",
65
67
  "ts-jest": "^29.4.1",
66
68
  "ts-node": "^10.9.2",
67
- "tsdown": "^0.16.4",
69
+ "tsdown": "^0.14.2",
68
70
  "typescript": "^5.9.2"
69
71
  },
70
72
  "publishConfig": {