@wise/wds-codemods 1.0.0 → 1.1.0-experimental-71771a8
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 +128 -86
- package/dist/constants-CcE2TmzN.js +59 -0
- package/dist/constants-CcE2TmzN.js.map +1 -0
- package/dist/{helpers-auDAwIcO.js → helpers-LWyJOzUP.js} +625 -592
- package/dist/helpers-LWyJOzUP.js.map +1 -0
- package/dist/index.js +87 -46
- package/dist/index.js.map +1 -1
- package/dist/transforms/button/transformer.js +3 -8
- package/dist/transforms/button/transformer.js.map +1 -1
- package/dist/transforms/list-item/config.json/config.json +6 -0
- package/dist/transforms/list-item/transformer.js +426 -0
- package/dist/transforms/list-item/transformer.js.map +1 -0
- package/package.json +46 -38
- package/dist/helpers-auDAwIcO.js.map +0 -1
- /package/dist/transforms/button/{config.json → config.json/config.json} +0 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
const require_constants = require('../../constants-CcE2TmzN.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 _listr2_manager = require("@listr2/manager");
|
|
6
|
+
let listr2 = require("listr2");
|
|
7
|
+
let node_https = require("node:https");
|
|
8
|
+
node_https = require_constants.__toESM(node_https);
|
|
9
|
+
let _anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
10
|
+
|
|
11
|
+
//#region src/transforms/list-item/constants.ts
|
|
12
|
+
const CLAUDE_SETTINGS_FILE = ".claude/settings.json";
|
|
13
|
+
const VPN_COUNTDOWN_TIMEOUT = 5;
|
|
14
|
+
const DIRECTORY_CONCURRENCY_LIMIT = 3;
|
|
15
|
+
const FILE_CONCURRENCY_LIMIT = 10;
|
|
16
|
+
const DEPRECATED_COMPONENT_NAMES = [
|
|
17
|
+
"ActionOption",
|
|
18
|
+
"NavigationOption",
|
|
19
|
+
"NavigationOptionList",
|
|
20
|
+
"Summary",
|
|
21
|
+
"SwitchOption",
|
|
22
|
+
"CheckboxOption",
|
|
23
|
+
"RadioOption"
|
|
24
|
+
];
|
|
25
|
+
const GREP_PATTERN = new RegExp(`import\\s*\\{[\\s\\S]*?(${DEPRECATED_COMPONENT_NAMES.join("|")})[\\s\\S]*?\\}\\s*from\\s*['"]@transferwise/components['"]`, "u");
|
|
26
|
+
const MIGRATION_RULES = `Migration rules:
|
|
27
|
+
# Legacy Component → ListItem Migration Guide
|
|
28
|
+
|
|
29
|
+
## Import Management
|
|
30
|
+
1. Remove imports: \`{ ActionOption, NavigationOption, NavigationOptionList, Summary, SwitchOption, CheckboxOption, RadioOption }\` from \`'@transferwise/components'\`
|
|
31
|
+
2. Add import: \`{ ListItem }\` from \`'@transferwise/components'\`
|
|
32
|
+
3. For Summary with info: Add \`{ Modal }\` and/or \`{ Popover }\` from \`'@transferwise/components'\`
|
|
33
|
+
4. For Summary with info: Add \`{ QuestionMarkCircle }\` from \`'@transferwise/icons'\`
|
|
34
|
+
5. For Summary with info modal: Add \`{ useState }\` from \`'react'\`
|
|
35
|
+
|
|
36
|
+
## Universal Rules
|
|
37
|
+
1. \`title\` → \`title\` (direct)
|
|
38
|
+
2. \`content\` or \`description\` → \`subtitle\`
|
|
39
|
+
3. \`disabled\` stays on \`ListItem\` (not controls)
|
|
40
|
+
4. \`id\` stays on \`ListItem\` (not controls)
|
|
41
|
+
5. Remove deprecated props: \`as\`, \`complex\`, \`showMediaAtAllSizes\`, \`showMediaCircle\`, \`isContainerAligned\`
|
|
42
|
+
6. Preserve string quotes exactly as they are (don't convert \`\` to \`'\` or \`"\`)
|
|
43
|
+
7. When wrapping icons in \`ListItem.AvatarView\`: move \`size\` from icon to AvatarView (except Summary always uses 32)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## ActionOption → ListItem.Button
|
|
48
|
+
|
|
49
|
+
- \`action\` → Button children
|
|
50
|
+
- \`onClick\` → Button \`onClick\`
|
|
51
|
+
- Priority mapping:
|
|
52
|
+
- default or \`"primary"\` → \`"primary"\`
|
|
53
|
+
- \`"secondary"\` → \`"secondary-neutral"\`
|
|
54
|
+
- \`"secondary-send"\` → \`"secondary"\`
|
|
55
|
+
- \`"tertiary"\` → \`"tertiary"\`
|
|
56
|
+
|
|
57
|
+
\`\`\`tsx
|
|
58
|
+
<ActionOption title="Title" content="Text" action="Click" priority="secondary" onClick={fn} />
|
|
59
|
+
→
|
|
60
|
+
<ListItem title="Title" subtitle="Text" control={<ListItem.Button priority="secondary-neutral" onClick={fn}>Click</ListItem.Button>} />
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## CheckboxOption → ListItem.Checkbox
|
|
66
|
+
|
|
67
|
+
- \`name\` is moved to \`ListItem.Checkbox\`
|
|
68
|
+
- \`onChange\`: \`(checked: boolean) => void\` → \`(event: ChangeEvent<HTMLInputElement>) => void\`
|
|
69
|
+
- Update handler: \`(checked) => setX(checked)\` → \`(event) => setX(event.target.checked)\`
|
|
70
|
+
|
|
71
|
+
\`\`\`tsx
|
|
72
|
+
<CheckboxOption id="x" name="y" title="Title" content="Text" checked={v} onChange={(c) => set(c)} />
|
|
73
|
+
→
|
|
74
|
+
<ListItem id="x" title="Title" subtitle="Text" control={<ListItem.Checkbox name="y" checked={v} onChange={(e) => set(e.target.checked)} />} />
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## RadioOption → ListItem.Radio
|
|
80
|
+
|
|
81
|
+
- \`name\`, \`value\`, \`checked\`, \`onChange\` move to Radio
|
|
82
|
+
|
|
83
|
+
\`\`\`tsx
|
|
84
|
+
<RadioOption id="x" name="y" value="v" title="Title" content="Text" checked={v==='v'} onChange={set} />
|
|
85
|
+
→
|
|
86
|
+
<ListItem id="x" title="Title" subtitle="Text" control={<ListItem.Radio name="y" value="v" checked={v==='v'} onChange={set} />} />
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## SwitchOption → ListItem.Switch
|
|
92
|
+
|
|
93
|
+
- \`aria-label\` is moved to \`ListItem.Switch\`
|
|
94
|
+
- \`onChange\` → \`onClick\` with manual toggle: \`onChange={set}\` → \`onClick={() => set(!v)}\`
|
|
95
|
+
|
|
96
|
+
\`\`\`tsx
|
|
97
|
+
<SwitchOption id="x" title="Title" content="Text" checked={v} aria-label="Toggle" onChange={set} />
|
|
98
|
+
→
|
|
99
|
+
<ListItem id="x" title="Title" subtitle="Text" control={<ListItem.Switch checked={v} aria-label="Toggle" onClick={() => set(!v)} />} />
|
|
100
|
+
\`\`\`
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## NavigationOption → ListItem.Navigation
|
|
105
|
+
|
|
106
|
+
- \`onClick\` or \`href\` move to Navigation
|
|
107
|
+
|
|
108
|
+
\`\`\`tsx
|
|
109
|
+
<NavigationOption title="Title" content="Text" onClick={fn} />
|
|
110
|
+
→
|
|
111
|
+
<ListItem title="Title" subtitle="Text" control={<ListItem.Navigation onClick={fn} />} />
|
|
112
|
+
\`\`\`
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## NavigationOptionList → (remove wrapper)
|
|
117
|
+
|
|
118
|
+
- Convert \`NavigationOptionList\` wrapper to \`<List></List>\`
|
|
119
|
+
- Convert each child \`NavigationOption\` to \`ListItem\` with \`ListItem.Navigation\`
|
|
120
|
+
|
|
121
|
+
\`\`\`tsx
|
|
122
|
+
<NavigationOptionList>
|
|
123
|
+
<NavigationOption title="T1" content="C1" onClick={fn1} />
|
|
124
|
+
<NavigationOption title="T2" content="C2" href="/link" />
|
|
125
|
+
</NavigationOptionList>
|
|
126
|
+
→
|
|
127
|
+
<>
|
|
128
|
+
<ListItem title="T1" subtitle="C1" control={<ListItem.Navigation onClick={fn1} />} />
|
|
129
|
+
<ListItem title="T2" subtitle="C2" control={<ListItem.Navigation href="/link" />} />
|
|
130
|
+
</>
|
|
131
|
+
\`\`\`
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Option → ListItem
|
|
136
|
+
|
|
137
|
+
- Wrap \`media\` in \`ListItem.AvatarView\`
|
|
138
|
+
- Move \`size\` prop from icon to AvatarView (keeping same value)
|
|
139
|
+
|
|
140
|
+
\`\`\`tsx
|
|
141
|
+
<Option media={<Icon size={48} />} title="Title" />
|
|
142
|
+
→
|
|
143
|
+
<ListItem title="Title" media={<ListItem.AvatarView size={48}><Icon /></ListItem.AvatarView>} />
|
|
144
|
+
\`\`\`
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Summary → ListItem
|
|
149
|
+
|
|
150
|
+
### Basic
|
|
151
|
+
- \`icon\` prop → wrap in \`ListItem.AvatarView\` with \`size={32}\` as \`media\`
|
|
152
|
+
- ALWAYS use \`size={32}\` on AvatarView (regardless of original icon size)
|
|
153
|
+
- ALWAYS remove \`size\` prop from child icon
|
|
154
|
+
- Summary-specific: always uses 32, while other components move size value from icon to AvatarView
|
|
155
|
+
|
|
156
|
+
### Status mapping
|
|
157
|
+
- \`Status.DONE\` → \`badge={{ status: 'positive' }}\` on AvatarView
|
|
158
|
+
- \`Status.PENDING\` → \`badge={{ status: 'pending' }}\` on AvatarView
|
|
159
|
+
- \`Status.NOT_DONE\` → no badge
|
|
160
|
+
|
|
161
|
+
### Action
|
|
162
|
+
- \`action.text\` → \`action.label\` in \`ListItem.AdditionalInfo\`
|
|
163
|
+
- Pass entire action object including \`href\`, \`onClick\`, \`target\`
|
|
164
|
+
- Remove \`aria-label\` from action (not supported)
|
|
165
|
+
|
|
166
|
+
### Info with Modal (add state management)
|
|
167
|
+
- Add: \`const [open, setOpen] = useState(false)\`
|
|
168
|
+
- Create \`ListItem.IconButton\` with \`partiallyInteractive\` and \`onClick\`
|
|
169
|
+
- Render \`Modal\` separately with state
|
|
170
|
+
- Transfer \`aria-label\` to IconButton
|
|
171
|
+
|
|
172
|
+
### Info with Popover
|
|
173
|
+
- \`Popover\` wraps \`ListItem.IconButton\` with \`partiallyInteractive\`
|
|
174
|
+
- Transfer \`aria-label\` to IconButton
|
|
175
|
+
|
|
176
|
+
\`\`\`tsx
|
|
177
|
+
// Basic (icon with or without size prop always becomes size={32} on AvatarView)
|
|
178
|
+
<Summary title="T" description="D" icon={<Icon size={24} />} />
|
|
179
|
+
→
|
|
180
|
+
<ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} />
|
|
181
|
+
|
|
182
|
+
// Status
|
|
183
|
+
<Summary title="T" description="D" icon={<Icon />} status={Status.DONE} />
|
|
184
|
+
→
|
|
185
|
+
<ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32} badge={{status:'positive'}}><Icon /></ListItem.AvatarView>} />
|
|
186
|
+
|
|
187
|
+
// Action
|
|
188
|
+
<Summary title="T" description="D" icon={<Icon />} action={{text:'Go', href:'/go', target:'_blank'}} />
|
|
189
|
+
→
|
|
190
|
+
<ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} additionalInfo={<ListItem.AdditionalInfo action={{label:'Go', href:'/go', target:'_blank'}} />} />
|
|
191
|
+
|
|
192
|
+
// Modal (requires state: const [open, setOpen] = useState(false))
|
|
193
|
+
<Summary title="T" description="D" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'MODAL', 'aria-label':'Info'}} />
|
|
194
|
+
→
|
|
195
|
+
<>
|
|
196
|
+
<ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={
|
|
197
|
+
<ListItem.IconButton partiallyInteractive aria-label="Info" onClick={()=>setOpen(!open)}>
|
|
198
|
+
<QuestionMarkCircle />
|
|
199
|
+
</ListItem.IconButton>
|
|
200
|
+
} />
|
|
201
|
+
<Modal open={open} title="Help" body="Text" onClose={()=>setOpen(false)} />
|
|
202
|
+
</>
|
|
203
|
+
|
|
204
|
+
// Popover
|
|
205
|
+
<Summary title="T" description="D" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'POPOVER', 'aria-label':'Info'}} />
|
|
206
|
+
→
|
|
207
|
+
<ListItem title="T" subtitle="D" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={
|
|
208
|
+
<Popover title="Help" content="Text" onClose={()=>setOpen(false)}>
|
|
209
|
+
<ListItem.IconButton partiallyInteractive aria-label="Info">
|
|
210
|
+
<QuestionMarkCircle />
|
|
211
|
+
</ListItem.IconButton>
|
|
212
|
+
</Popover>
|
|
213
|
+
} />
|
|
214
|
+
\`\`\`
|
|
215
|
+
|
|
216
|
+
`;
|
|
217
|
+
const SYSTEM_PROMPT = `You are a code migration assistant that helps migrate TypeScript/JSX code from deprecated Wise Design System (WDS) components to the new ListItem component and ListItem subcomponents from '@transferwise/components'.
|
|
218
|
+
|
|
219
|
+
Rules:
|
|
220
|
+
1. Only ever modify files via the Edit tool - do not use the Write tool
|
|
221
|
+
2. When identifying what code to migrate within a file, explain how you identified it first.
|
|
222
|
+
3. Migrate components per provided migration rules
|
|
223
|
+
4. Maintain TypeScript type safety and update types to match new API
|
|
224
|
+
5. Map props: handle renamed, deprecated, new required, and changed types
|
|
225
|
+
6. Update imports to new WDS components and types
|
|
226
|
+
7. Preserve code style, formatting, and calculated logic
|
|
227
|
+
8. Handle conditional rendering, spread props, and complex expressions
|
|
228
|
+
9. Note: New components may lack feature parity with legacy versions
|
|
229
|
+
10. Only modify code requiring changes per migration rules, and any impacted surrounding code for context.
|
|
230
|
+
11. Final result response should just be whether the migration was successful overall, or if any errors were encountered
|
|
231
|
+
- Do not summarise or explain the changes made
|
|
232
|
+
12. Explain your reasoning and justification before making changes, as you edit each file.
|
|
233
|
+
- Keep it concise and succinct, as only bullet points
|
|
234
|
+
13. After modifying the file, do not summarise the changes made.
|
|
235
|
+
14. If you do not have permission to edit a file, still attempt to edit it and then move onto the next file.
|
|
236
|
+
|
|
237
|
+
You'll receive:
|
|
238
|
+
- File paths to migrate in individual queries
|
|
239
|
+
- Deprecated component names at the end of this prompt
|
|
240
|
+
- Migration context and rules for each deprecated component
|
|
241
|
+
|
|
242
|
+
Deprecated components: ${DEPRECATED_COMPONENT_NAMES.join(", ")}.
|
|
243
|
+
|
|
244
|
+
${MIGRATION_RULES}`;
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/transforms/list-item/helpers.ts
|
|
248
|
+
/** Split the path to get the relative path after the directory, and wrap with ANSI color codes */
|
|
249
|
+
function formatPathOutput(directory, path, asDim) {
|
|
250
|
+
const relativePath = path ? path.split(directory.replace(".", ""))[1] ?? path : directory;
|
|
251
|
+
return asDim ? `\x1b[2m${relativePath}\x1b[0m` : `\x1b[32m${relativePath}\x1b[0m`;
|
|
252
|
+
}
|
|
253
|
+
/** Generates a formatted string representing the total elapsed time since the given start time */
|
|
254
|
+
function generateElapsedTime(startTime) {
|
|
255
|
+
const endTime = Date.now();
|
|
256
|
+
const elapsedTime = Math.floor((endTime - startTime) / 1e3);
|
|
257
|
+
const hours = Math.floor(elapsedTime / 3600);
|
|
258
|
+
const minutes = Math.floor(elapsedTime % 3600 / 60);
|
|
259
|
+
const seconds = elapsedTime % 60;
|
|
260
|
+
return `${hours ? `${hours}h ` : ""}${minutes ? `${minutes}m ` : ""}${seconds ? `${seconds}s` : ""}`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/transforms/list-item/claude.ts
|
|
265
|
+
async function checkVPN(baseUrl, task) {
|
|
266
|
+
if (!baseUrl) return;
|
|
267
|
+
const checkOnce = async () => new Promise((resolveCheck) => {
|
|
268
|
+
const url = new URL("/health", baseUrl);
|
|
269
|
+
const req = node_https.default.get(url, {
|
|
270
|
+
timeout: 2e3,
|
|
271
|
+
rejectUnauthorized: false
|
|
272
|
+
}, (res) => {
|
|
273
|
+
const ok = !!(res.statusCode && res.statusCode >= 200 && res.statusCode < 400);
|
|
274
|
+
res.resume();
|
|
275
|
+
resolveCheck(ok);
|
|
276
|
+
});
|
|
277
|
+
req.on("timeout", () => {
|
|
278
|
+
req.destroy(/* @__PURE__ */ new Error("timeout"));
|
|
279
|
+
});
|
|
280
|
+
req.on("error", () => resolveCheck(false));
|
|
281
|
+
});
|
|
282
|
+
while (true) {
|
|
283
|
+
if (await checkOnce()) {
|
|
284
|
+
task.title = "Connected to VPN";
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
for (let countdown = VPN_COUNTDOWN_TIMEOUT; countdown > 0; countdown -= 1) {
|
|
288
|
+
task.output = `Please connect to VPN... retrying in ${countdown}s`;
|
|
289
|
+
await new Promise((response) => {
|
|
290
|
+
setTimeout(response, 1e3);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function getQueryOptions(sessionId) {
|
|
296
|
+
const claudeSettingsPath = (0, node_path.resolve)(process.env.HOME || "", CLAUDE_SETTINGS_FILE);
|
|
297
|
+
const settings = JSON.parse((0, node_fs.readFileSync)(claudeSettingsPath, "utf-8"));
|
|
298
|
+
let apiKey;
|
|
299
|
+
try {
|
|
300
|
+
apiKey = (0, node_child_process.execSync)(`bash ${settings.apiKeyHelper}`, { encoding: "utf-8" }).trim();
|
|
301
|
+
} catch {}
|
|
302
|
+
if (!apiKey || !settings.env?.ANTHROPIC_BASE_URL) throw new Error("Failed to retrieve Anthropic API key or Base URL. Please check your Claude Code x LLM Gateway configuration - https://transferwise.atlassian.net/wiki/x/_YUe3Q");
|
|
303
|
+
const { ANTHROPIC_CUSTOM_HEADERS, ...restEnvVars } = settings?.env ?? {};
|
|
304
|
+
return {
|
|
305
|
+
resume: sessionId,
|
|
306
|
+
env: {
|
|
307
|
+
ANTHROPIC_AUTH_TOKEN: apiKey,
|
|
308
|
+
ANTHROPIC_CUSTOM_HEADERS,
|
|
309
|
+
...restEnvVars,
|
|
310
|
+
PATH: process.env.PATH
|
|
311
|
+
},
|
|
312
|
+
permissionMode: "acceptEdits",
|
|
313
|
+
systemPrompt: {
|
|
314
|
+
type: "preset",
|
|
315
|
+
preset: "claude_code",
|
|
316
|
+
append: SYSTEM_PROMPT
|
|
317
|
+
},
|
|
318
|
+
allowedTools: ["Grep", "Read"],
|
|
319
|
+
settingSources: [
|
|
320
|
+
"local",
|
|
321
|
+
"project",
|
|
322
|
+
"user"
|
|
323
|
+
]
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/** Initiate a new Claude session/conversation and return reusable options */
|
|
327
|
+
async function initiateClaudeSessionOptions(manager) {
|
|
328
|
+
const options = getQueryOptions(void 0);
|
|
329
|
+
manager.add([{
|
|
330
|
+
title: "Checking VPN connection",
|
|
331
|
+
task: async (_, task) => checkVPN(options.env?.ANTHROPIC_BASE_URL, task)
|
|
332
|
+
}]);
|
|
333
|
+
await manager.runAll();
|
|
334
|
+
manager.add([{
|
|
335
|
+
title: "Starting Claude instance",
|
|
336
|
+
task: async (_, task) => {
|
|
337
|
+
task.output = "Your browser may open for Okta authentication if required";
|
|
338
|
+
const result = (0, _anthropic_ai_claude_agent_sdk.query)({
|
|
339
|
+
options,
|
|
340
|
+
prompt: `You'll be given file paths in additional individual queries to search in for files using deprecated Wise Design System (WDS) components. Migrate the code per the provided migration rules.`
|
|
341
|
+
});
|
|
342
|
+
for await (const message of result) switch (message.type) {
|
|
343
|
+
case "system":
|
|
344
|
+
if (message.subtype === "init" && !options.resume) {
|
|
345
|
+
task.title = "Successfully initialised Claude instance\n";
|
|
346
|
+
options.resume = message.session_id;
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
default: if (message.type === "result" && message.subtype !== "success") throw new Error(`Claude encountered an error when initialising: ${message.errors.join("\n")}`);
|
|
350
|
+
}
|
|
351
|
+
task.task.complete();
|
|
352
|
+
}
|
|
353
|
+
}]);
|
|
354
|
+
await manager.runAll().finally(() => {
|
|
355
|
+
manager.options = { concurrent: DIRECTORY_CONCURRENCY_LIMIT };
|
|
356
|
+
});
|
|
357
|
+
return options;
|
|
358
|
+
}
|
|
359
|
+
async function queryClaude(directory, filePath, options, task, isDebug = false) {
|
|
360
|
+
const startTime = Date.now();
|
|
361
|
+
const result = (0, _anthropic_ai_claude_agent_sdk.query)({
|
|
362
|
+
options,
|
|
363
|
+
prompt: filePath
|
|
364
|
+
});
|
|
365
|
+
for await (const message of result) switch (message.type) {
|
|
366
|
+
case "result":
|
|
367
|
+
if (message.subtype === "success" && isDebug) {
|
|
368
|
+
task.title = `\x1b[2m${formatPathOutput(directory, filePath)}\x1b[0m]`;
|
|
369
|
+
task.output = `\x1b[2mMigrated in ${generateElapsedTime(startTime)}\x1b[0m`;
|
|
370
|
+
} else if (message.is_error) {
|
|
371
|
+
task.title = `\x1b[2m${formatPathOutput(directory, filePath)}\x1b[0m]`;
|
|
372
|
+
task.output = `${require_constants.CONSOLE_ICONS.error} Claude encountered an error: ${JSON.stringify(message)}`;
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
default:
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/transforms/list-item/transformer.ts
|
|
381
|
+
const transformer = async (targetPaths, isDebug = false) => {
|
|
382
|
+
process.setMaxListeners(20);
|
|
383
|
+
const startTime = Date.now();
|
|
384
|
+
const manager = new _listr2_manager.Manager({ concurrent: true });
|
|
385
|
+
const queryOptions = await initiateClaudeSessionOptions(manager);
|
|
386
|
+
for (const directory of targetPaths) {
|
|
387
|
+
const matchingFilePaths = (0, node_child_process.execSync)(`find "${directory}" -name "*.tsx" -type f`, { encoding: "utf-8" }).trim().split("\n").filter(Boolean).filter((filePath) => {
|
|
388
|
+
const content = (0, node_fs.readFileSync)(filePath, "utf-8");
|
|
389
|
+
return GREP_PATTERN.test(content);
|
|
390
|
+
});
|
|
391
|
+
if (matchingFilePaths.length === 0) manager.add([{
|
|
392
|
+
title: `\x1b[2m${formatPathOutput(directory)} - No files need migration\x1b[0m`,
|
|
393
|
+
task: (ctx) => {
|
|
394
|
+
ctx.skip = true;
|
|
395
|
+
}
|
|
396
|
+
}]);
|
|
397
|
+
else manager.add([{
|
|
398
|
+
title: `${formatPathOutput(directory)} - Found \x1b[32m${matchingFilePaths.length}\x1b[0m file(s) needing migration`,
|
|
399
|
+
task: async (ctx, parentTask) => {
|
|
400
|
+
parentTask.title = `${formatPathOutput(directory)} - Migrating \x1b[32m${matchingFilePaths.length}\x1b[0m file(s)...`;
|
|
401
|
+
const completedFilesInDirectory = { count: 0 };
|
|
402
|
+
return parentTask.newListr(matchingFilePaths.map((filePath) => ({
|
|
403
|
+
title: "",
|
|
404
|
+
task: async (fileCtx, fileTask) => {
|
|
405
|
+
await queryClaude(directory, filePath, queryOptions, fileTask, isDebug).finally(() => {
|
|
406
|
+
completedFilesInDirectory.count += 1;
|
|
407
|
+
const isDim = completedFilesInDirectory.count === matchingFilePaths.length;
|
|
408
|
+
parentTask.title = `${isDim ? "\x1B[2m" : ""}${formatPathOutput(directory)} - Migrated \x1b[32m${completedFilesInDirectory.count}\x1b[0m/\x1b[32m${matchingFilePaths.length}\x1b[0m files${isDim ? "\x1B[0m" : ""}`;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
})), { concurrent: FILE_CONCURRENCY_LIMIT }).run();
|
|
412
|
+
}
|
|
413
|
+
}]);
|
|
414
|
+
}
|
|
415
|
+
await manager.runAll().finally(async () => {
|
|
416
|
+
await new listr2.Listr([{
|
|
417
|
+
title: `Finished migrating - elapsed time: \x1b[32m${generateElapsedTime(startTime)}\x1b[0m `,
|
|
418
|
+
task: async () => {}
|
|
419
|
+
}]).run();
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
var transformer_default = transformer;
|
|
423
|
+
|
|
424
|
+
//#endregion
|
|
425
|
+
module.exports = transformer_default;
|
|
426
|
+
//# sourceMappingURL=transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer.js","names":["https","CONSOLE_ICONS","Manager","Listr"],"sources":["../../../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 CLAUDE_SETTINGS_FILE = '.claude/settings.json';\nexport const VPN_COUNTDOWN_TIMEOUT = 5;\nexport const DIRECTORY_CONCURRENCY_LIMIT = 3;\nexport const FILE_CONCURRENCY_LIMIT = 10;\nconst DEPRECATED_COMPONENT_NAMES = [\n 'ActionOption',\n 'NavigationOption',\n 'NavigationOptionList',\n 'Summary',\n 'SwitchOption',\n 'CheckboxOption',\n 'RadioOption',\n];\nexport const GREP_PATTERN = new RegExp(\n `import\\\\s*\\\\{[\\\\s\\\\S]*?(${DEPRECATED_COMPONENT_NAMES.join('|')})[\\\\s\\\\S]*?\\\\}\\\\s*from\\\\s*['\"]@transferwise/components['\"]`,\n 'u',\n);\n\nconst MIGRATION_RULES = `Migration rules:\n# Legacy Component → ListItem Migration Guide\n\n## Import Management\n1. Remove imports: \\`{ ActionOption, NavigationOption, NavigationOptionList, Summary, SwitchOption, CheckboxOption, RadioOption }\\` from \\`'@transferwise/components'\\`\n2. Add import: \\`{ ListItem }\\` from \\`'@transferwise/components'\\`\n3. For Summary with info: Add \\`{ Modal }\\` and/or \\`{ Popover }\\` from \\`'@transferwise/components'\\`\n4. For Summary with info: Add \\`{ QuestionMarkCircle }\\` from \\`'@transferwise/icons'\\`\n5. For Summary with info modal: Add \\`{ useState }\\` from \\`'react'\\`\n\n## Universal Rules\n1. \\`title\\` → \\`title\\` (direct)\n2. \\`content\\` or \\`description\\` → \\`subtitle\\`\n3. \\`disabled\\` stays on \\`ListItem\\` (not controls)\n4. \\`id\\` stays on \\`ListItem\\` (not controls)\n5. Remove deprecated props: \\`as\\`, \\`complex\\`, \\`showMediaAtAllSizes\\`, \\`showMediaCircle\\`, \\`isContainerAligned\\`\n6. Preserve string quotes exactly as they are (don't convert \\`\\` to \\`'\\` or \\`\"\\`)\n7. When wrapping icons in \\`ListItem.AvatarView\\`: move \\`size\\` from icon to AvatarView (except Summary always uses 32)\n\n---\n\n## ActionOption → ListItem.Button\n\n- \\`action\\` → Button children\n- \\`onClick\\` → Button \\`onClick\\`\n- Priority mapping:\n - default or \\`\"primary\"\\` → \\`\"primary\"\\`\n - \\`\"secondary\"\\` → \\`\"secondary-neutral\"\\`\n - \\`\"secondary-send\"\\` → \\`\"secondary\"\\`\n - \\`\"tertiary\"\\` → \\`\"tertiary\"\\`\n\n\\`\\`\\`tsx\n<ActionOption title=\"Title\" content=\"Text\" action=\"Click\" priority=\"secondary\" onClick={fn} />\n→\n<ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Button priority=\"secondary-neutral\" onClick={fn}>Click</ListItem.Button>} />\n\\`\\`\\`\n\n---\n\n## CheckboxOption → ListItem.Checkbox\n\n- \\`name\\` is moved to \\`ListItem.Checkbox\\`\n- \\`onChange\\`: \\`(checked: boolean) => void\\` → \\`(event: ChangeEvent<HTMLInputElement>) => void\\`\n - Update handler: \\`(checked) => setX(checked)\\` → \\`(event) => setX(event.target.checked)\\`\n\n\\`\\`\\`tsx\n<CheckboxOption id=\"x\" name=\"y\" title=\"Title\" content=\"Text\" checked={v} onChange={(c) => set(c)} />\n→\n<ListItem id=\"x\" title=\"Title\" subtitle=\"Text\" control={<ListItem.Checkbox name=\"y\" checked={v} onChange={(e) => set(e.target.checked)} />} />\n\\`\\`\\`\n\n---\n\n## RadioOption → ListItem.Radio\n\n- \\`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<ListItem id=\"x\" title=\"Title\" subtitle=\"Text\" control={<ListItem.Radio name=\"y\" value=\"v\" checked={v==='v'} onChange={set} />} />\n\\`\\`\\`\n\n---\n\n## SwitchOption → ListItem.Switch\n\n- \\`aria-label\\` is moved to \\`ListItem.Switch\\`\n- \\`onChange\\` → \\`onClick\\` with manual toggle: \\`onChange={set}\\` → \\`onClick={() => set(!v)}\\`\n\n\\`\\`\\`tsx\n<SwitchOption id=\"x\" title=\"Title\" content=\"Text\" checked={v} aria-label=\"Toggle\" onChange={set} />\n→\n<ListItem id=\"x\" title=\"Title\" subtitle=\"Text\" control={<ListItem.Switch checked={v} aria-label=\"Toggle\" onClick={() => set(!v)} />} />\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<ListItem title=\"Title\" subtitle=\"Text\" control={<ListItem.Navigation onClick={fn} />} />\n\\`\\`\\`\n\n---\n\n## NavigationOptionList → (remove wrapper)\n\n- Convert \\`NavigationOptionList\\` wrapper to \\`<List></List>\\`\n- Convert each child \\`NavigationOption\\` to \\`ListItem\\` with \\`ListItem.Navigation\\`\n\n\\`\\`\\`tsx\n<NavigationOptionList>\n <NavigationOption title=\"T1\" content=\"C1\" onClick={fn1} />\n <NavigationOption title=\"T2\" content=\"C2\" href=\"/link\" />\n</NavigationOptionList>\n→\n<>\n <ListItem title=\"T1\" subtitle=\"C1\" control={<ListItem.Navigation onClick={fn1} />} />\n <ListItem title=\"T2\" subtitle=\"C2\" control={<ListItem.Navigation href=\"/link\" />} />\n</>\n\\`\\`\\`\n\n---\n\n## Option → ListItem\n\n- Wrap \\`media\\` in \\`ListItem.AvatarView\\`\n- Move \\`size\\` prop from icon to AvatarView (keeping same value)\n\n\\`\\`\\`tsx\n<Option media={<Icon size={48} />} title=\"Title\" />\n→\n<ListItem title=\"Title\" media={<ListItem.AvatarView size={48}><Icon /></ListItem.AvatarView>} />\n\\`\\`\\`\n\n---\n\n## Summary → ListItem\n\n### Basic\n- \\`icon\\` prop → wrap in \\`ListItem.AvatarView\\` with \\`size={32}\\` as \\`media\\`\n- ALWAYS use \\`size={32}\\` on AvatarView (regardless of original icon size)\n- ALWAYS remove \\`size\\` prop from child icon\n- Summary-specific: always uses 32, while other components move size value from icon to AvatarView\n\n### Status mapping\n- \\`Status.DONE\\` → \\`badge={{ status: 'positive' }}\\` on AvatarView\n- \\`Status.PENDING\\` → \\`badge={{ status: 'pending' }}\\` on AvatarView\n- \\`Status.NOT_DONE\\` → no badge\n\n### Action\n- \\`action.text\\` → \\`action.label\\` in \\`ListItem.AdditionalInfo\\`\n- Pass entire action object including \\`href\\`, \\`onClick\\`, \\`target\\`\n- Remove \\`aria-label\\` from action (not supported)\n\n### Info with Modal (add state management)\n- Add: \\`const [open, setOpen] = useState(false)\\`\n- Create \\`ListItem.IconButton\\` with \\`partiallyInteractive\\` and \\`onClick\\`\n- Render \\`Modal\\` separately with state\n- Transfer \\`aria-label\\` to IconButton\n\n### Info with Popover\n- \\`Popover\\` wraps \\`ListItem.IconButton\\` with \\`partiallyInteractive\\`\n- Transfer \\`aria-label\\` to IconButton\n\n\\`\\`\\`tsx\n// Basic (icon with or without size prop always becomes size={32} on AvatarView)\n<Summary title=\"T\" description=\"D\" icon={<Icon size={24} />} />\n→\n<ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} />\n\n// Status\n<Summary title=\"T\" description=\"D\" icon={<Icon />} status={Status.DONE} />\n→\n<ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32} badge={{status:'positive'}}><Icon /></ListItem.AvatarView>} />\n\n// Action\n<Summary title=\"T\" description=\"D\" icon={<Icon />} action={{text:'Go', href:'/go', target:'_blank'}} />\n→\n<ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} additionalInfo={<ListItem.AdditionalInfo action={{label:'Go', href:'/go', target:'_blank'}} />} />\n\n// Modal (requires state: 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<>\n <ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={\n <ListItem.IconButton partiallyInteractive aria-label=\"Info\" onClick={()=>setOpen(!open)}>\n <QuestionMarkCircle />\n </ListItem.IconButton>\n } />\n <Modal open={open} title=\"Help\" body=\"Text\" onClose={()=>setOpen(false)} />\n</>\n\n// Popover\n<Summary title=\"T\" description=\"D\" icon={<Icon />} info={{title:'Help', content:'Text', presentation:'POPOVER', 'aria-label':'Info'}} />\n→\n<ListItem title=\"T\" subtitle=\"D\" media={<ListItem.AvatarView size={32}><Icon /></ListItem.AvatarView>} control={\n <Popover title=\"Help\" content=\"Text\" onClose={()=>setOpen(false)}>\n <ListItem.IconButton partiallyInteractive aria-label=\"Info\">\n <QuestionMarkCircle />\n </ListItem.IconButton>\n </Popover>\n} />\n\\`\\`\\`\n\n`;\n\nexport const SYSTEM_PROMPT = `You are a code migration assistant that helps migrate TypeScript/JSX code from deprecated Wise Design System (WDS) components to the new ListItem component and ListItem subcomponents from '@transferwise/components'.\n\nRules:\n1. Only ever modify files via the Edit tool - do not use the Write tool\n2. When identifying what code to migrate within a file, explain how you identified it first.\n3. Migrate components per provided migration rules\n4. Maintain TypeScript type safety and update types to match new API\n5. Map props: handle renamed, deprecated, new required, and changed types\n6. Update imports to new WDS components and types\n7. Preserve code style, formatting, and calculated logic\n8. Handle conditional rendering, spread props, and complex expressions\n9. Note: New components may lack feature parity with legacy versions\n10. Only modify code requiring changes per migration rules, and any impacted surrounding code for context.\n11. Final result response should just be whether the migration was successful overall, or if any errors were encountered\n - Do not summarise or explain the changes made\n12. Explain your reasoning and justification before making changes, as you edit each file.\n - Keep it concise and succinct, as only bullet points\n13. After modifying the file, do not summarise the changes made.\n14. If you do not have permission to edit a file, still attempt to edit it and then move onto the next file.\n\nYou'll receive:\n- File paths to migrate 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, asDim?: boolean): string {\n const relativePath = path ? (path.split(directory.replace('.', ''))[1] ?? path) : directory;\n return asDim ? `\\x1b[2m${relativePath}\\x1b[0m` : `\\x1b[32m${relativePath}\\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 { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport https from 'node:https';\nimport { resolve } from 'node:path';\n\nimport { type Options, query } from '@anthropic-ai/claude-agent-sdk';\nimport type { Manager } from '@listr2/manager';\nimport type { DefaultRenderer, ListrTaskWrapper, SimpleRenderer } from 'listr2';\n\nimport { CONSOLE_ICONS } from '../../constants';\nimport {\n CLAUDE_SETTINGS_FILE,\n DIRECTORY_CONCURRENCY_LIMIT,\n SYSTEM_PROMPT,\n VPN_COUNTDOWN_TIMEOUT,\n} from './constants';\nimport { formatPathOutput, generateElapsedTime } from './helpers';\nimport type { ClaudeSettings } from './types';\n\nasync function checkVPN(\n baseUrl: string | undefined,\n task: ListrTaskWrapper<never, typeof DefaultRenderer, typeof SimpleRenderer>,\n): Promise<void> {\n if (!baseUrl) return;\n\n const checkOnce = async (): Promise<boolean> =>\n new Promise<boolean>((resolveCheck) => {\n const url = new URL('/health', baseUrl);\n const req = https.get(url, { timeout: 2000, rejectUnauthorized: false }, (res) => {\n const ok = !!(res.statusCode && res.statusCode >= 200 && res.statusCode < 400);\n res.resume();\n resolveCheck(ok);\n });\n req.on('timeout', () => {\n req.destroy(new Error('timeout'));\n });\n req.on('error', () => resolveCheck(false));\n });\n\n while (true) {\n const ok = await checkOnce();\n if (ok) {\n // eslint-disable-next-line no-param-reassign\n task.title = 'Connected to VPN';\n break;\n }\n\n // Countdown from 5s\n for (let countdown = VPN_COUNTDOWN_TIMEOUT; countdown > 0; countdown -= 1) {\n // eslint-disable-next-line no-param-reassign\n task.output = `Please connect to VPN... retrying in ${countdown}s`;\n await new Promise<void>((response) => {\n setTimeout(response, 1000);\n });\n }\n }\n}\n\nexport function getQueryOptions(sessionId?: string): 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 || !settings.env?.ANTHROPIC_BASE_URL) {\n throw new Error(\n 'Failed to retrieve Anthropic API key or Base URL. Please check your Claude Code x LLM Gateway configuration - https://transferwise.atlassian.net/wiki/x/_YUe3Q',\n );\n }\n\n const { ANTHROPIC_CUSTOM_HEADERS, ...restEnvVars } = settings?.env ?? {};\n\n const envVars = {\n ANTHROPIC_AUTH_TOKEN: apiKey,\n ANTHROPIC_CUSTOM_HEADERS,\n ...restEnvVars,\n PATH: process.env.PATH, // Specifying PATH, as Claude Agent SDK seems to struggle consuming the actual environment PATH\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 allowedTools: ['Grep', 'Read'],\n settingSources: ['local', 'project', 'user'],\n };\n}\n\n/** Initiate a new Claude session/conversation and return reusable options */\nexport async function initiateClaudeSessionOptions(manager: Manager): Promise<Options> {\n const options = getQueryOptions(undefined);\n\n manager.add([\n {\n title: 'Checking VPN connection',\n task: async (\n _,\n task: ListrTaskWrapper<never, typeof DefaultRenderer, typeof SimpleRenderer>,\n ) => checkVPN(options.env?.ANTHROPIC_BASE_URL, task),\n },\n ]);\n\n await manager.runAll();\n\n manager.add([\n {\n title: 'Starting Claude instance',\n task: async (_, task) => {\n // eslint-disable-next-line no-param-reassign\n task.output = 'Your browser may open for Okta authentication if required';\n\n const result = query({\n options,\n prompt: `You'll be given file paths 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 // eslint-disable-next-line no-param-reassign\n task.title = '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 throw new Error(\n `Claude encountered an error when initialising: ${message.errors.join('\\n')}`,\n );\n }\n }\n }\n\n task.task.complete();\n },\n },\n ]);\n\n await manager.runAll().finally(() => {\n // Set manager to run tasks concurrently, once initialisation steps are done\n // eslint-disable-next-line no-param-reassign\n manager.options = {\n concurrent: DIRECTORY_CONCURRENCY_LIMIT,\n };\n });\n\n return options;\n}\n\n// Queries Claude with the given path and handles logging of tool uses and results\nexport async function queryClaude(\n directory: string,\n filePath: string,\n options: Options,\n task: ListrTaskWrapper<never, typeof DefaultRenderer, typeof SimpleRenderer>,\n isDebug = false,\n) {\n const startTime = Date.now();\n const result = query({\n options,\n prompt: filePath,\n });\n\n for await (const message of result) {\n switch (message.type) {\n case 'result':\n if (message.subtype === 'success' && isDebug) {\n // eslint-disable-next-line no-param-reassign\n task.title = `\\x1b[2m${formatPathOutput(directory, filePath)}\\x1b[0m]`;\n // eslint-disable-next-line no-param-reassign\n task.output = `\\x1b[2mMigrated in ${generateElapsedTime(startTime)}\\x1b[0m`;\n } else if (message.is_error) {\n // eslint-disable-next-line no-param-reassign\n task.title = `\\x1b[2m${formatPathOutput(directory, filePath)}\\x1b[0m]`;\n // eslint-disable-next-line no-param-reassign\n task.output = `${CONSOLE_ICONS.error} Claude encountered an error: ${JSON.stringify(message)}`;\n }\n break;\n default:\n }\n }\n}\n","import { Manager } from '@listr2/manager';\nimport { execSync } from 'child_process';\nimport { readFileSync } from 'fs';\nimport {\n type DefaultRenderer,\n Listr,\n type ListrTask,\n type ListrTaskWrapper,\n type SimpleRenderer,\n} from 'listr2';\n\nimport { initiateClaudeSessionOptions, queryClaude } from './claude';\nimport { FILE_CONCURRENCY_LIMIT, GREP_PATTERN } from './constants';\nimport { formatPathOutput, generateElapsedTime } from './helpers';\n\nconst transformer = async (targetPaths: string[], isDebug = false) => {\n process.setMaxListeners(20); // Resolves potential memory issues with how Claude handles it's own event listeners\n const startTime = Date.now();\n // Create manager for handling multiple listr instances\n const manager = new Manager({\n concurrent: true,\n });\n const queryOptions = await initiateClaudeSessionOptions(manager);\n\n // Process each directory\n for (const directory of targetPaths) {\n // Find all .tsx files in the directory\n const allTsxFiles = execSync(`find \"${directory}\" -name \"*.tsx\" -type f`, {\n encoding: 'utf-8',\n })\n .trim()\n .split('\\n')\n .filter(Boolean);\n\n // Filter files that match the pattern by reading and testing each file\n const matchingFilePaths = allTsxFiles.filter((filePath) => {\n const content = readFileSync(filePath, 'utf-8');\n return GREP_PATTERN.test(content);\n });\n\n // No files to process in this directory, so we add a task that's immediately skipped\n if (matchingFilePaths.length === 0) {\n manager.add([\n {\n title: `\\x1b[2m${formatPathOutput(directory)} - No files need migration\\x1b[0m`,\n task: (ctx: ListrTask): void => {\n // eslint-disable-next-line no-param-reassign\n ctx.skip = true;\n },\n },\n ]);\n } else {\n manager.add([\n {\n title: `${formatPathOutput(directory)} - Found \\x1b[32m${matchingFilePaths.length}\\x1b[0m file(s) needing migration`,\n task: async (ctx, parentTask) => {\n // eslint-disable-next-line no-param-reassign\n parentTask.title = `${formatPathOutput(directory)} - Migrating \\x1b[32m${matchingFilePaths.length}\\x1b[0m file(s)...`;\n const completedFilesInDirectory = { count: 0 };\n return parentTask\n .newListr(\n matchingFilePaths.map((filePath) => ({\n title: '', // No title so it runs in the background without any console output\n task: async (\n fileCtx,\n fileTask: ListrTaskWrapper<\n never,\n typeof DefaultRenderer,\n typeof SimpleRenderer\n >,\n ) => {\n await queryClaude(directory, filePath, queryOptions, fileTask, isDebug).finally(\n () => {\n // Update parent task title with progress for each completed file migration\n completedFilesInDirectory.count += 1;\n const isDim = completedFilesInDirectory.count === matchingFilePaths.length;\n // eslint-disable-next-line no-param-reassign\n parentTask.title = `${isDim ? '\\x1b[2m' : ''}${formatPathOutput(directory)} - Migrated \\x1b[32m${completedFilesInDirectory.count}\\x1b[0m/\\x1b[32m${matchingFilePaths.length}\\x1b[0m files${isDim ? '\\x1b[0m' : ''}`;\n },\n );\n },\n })),\n { concurrent: FILE_CONCURRENCY_LIMIT },\n )\n .run();\n },\n },\n ]);\n }\n }\n\n // Run all directory tasks, with final follow up/summary task\n await manager.runAll().finally(async () => {\n await new Listr([\n {\n title: `Finished migrating - elapsed time: \\x1b[32m${generateElapsedTime(startTime)}\\x1b[0m `,\n task: async () => {\n // Task completes immediately\n },\n },\n ]).run();\n });\n};\n\nexport default transformer;\n"],"mappings":";;;;;;;;;;;AAAA,MAAa,uBAAuB;AACpC,MAAa,wBAAwB;AACrC,MAAa,8BAA8B;AAC3C,MAAa,yBAAyB;AACtC,MAAM,6BAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAa,eAAe,IAAI,OAC9B,2BAA2B,2BAA2B,KAAK,IAAI,CAAC,6DAChE,IACD;AAED,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAGF,MAAI,kBAAkB,WAAW,EAC/B,SAAQ,IAAI,CACV;GACE,OAAO,UAAU,iBAAiB,UAAU,CAAC;GAC7C,OAAO,QAAyB;AAE9B,QAAI,OAAO;;GAEd,CACF,CAAC;MAEF,SAAQ,IAAI,CACV;GACE,OAAO,GAAG,iBAAiB,UAAU,CAAC,mBAAmB,kBAAkB,OAAO;GAClF,MAAM,OAAO,KAAK,eAAe;AAE/B,eAAW,QAAQ,GAAG,iBAAiB,UAAU,CAAC,uBAAuB,kBAAkB,OAAO;IAClG,MAAM,4BAA4B,EAAE,OAAO,GAAG;AAC9C,WAAO,WACJ,SACC,kBAAkB,KAAK,cAAc;KACnC,OAAO;KACP,MAAM,OACJ,SACA,aAKG;AACH,YAAM,YAAY,WAAW,UAAU,cAAc,UAAU,QAAQ,CAAC,cAChE;AAEJ,iCAA0B,SAAS;OACnC,MAAM,QAAQ,0BAA0B,UAAU,kBAAkB;AAEpE,kBAAW,QAAQ,GAAG,QAAQ,YAAY,KAAK,iBAAiB,UAAU,CAAC,sBAAsB,0BAA0B,MAAM,kBAAkB,kBAAkB,OAAO,eAAe,QAAQ,YAAY;QAElN;;KAEJ,EAAE,EACH,EAAE,YAAY,wBAAwB,CACvC,CACA,KAAK;;GAEX,CACF,CAAC;;AAKN,OAAM,QAAQ,QAAQ,CAAC,QAAQ,YAAY;AACzC,QAAM,IAAIC,aAAM,CACd;GACE,OAAO,8CAA8C,oBAAoB,UAAU,CAAC;GACpF,MAAM,YAAY;GAGnB,CACF,CAAC,CAAC,KAAK;GACR;;AAGJ,0BAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/wds-codemods",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0-experimental-71771a8",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Wise Payments Ltd.",
|
|
6
6
|
"repository": {
|
|
@@ -18,55 +18,63 @@
|
|
|
18
18
|
"README.md",
|
|
19
19
|
"package.json"
|
|
20
20
|
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsdown",
|
|
23
|
+
"changeset": "changeset",
|
|
24
|
+
"lint": "pnpm run lint:js+ts && pnpm run lint:format",
|
|
25
|
+
"lint:js+ts": "eslint '**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}' --concurrency=auto",
|
|
26
|
+
"lint:format": "prettier \"**/*\" --check --ignore-unknown",
|
|
27
|
+
"lint:types": "tsc --noEmit",
|
|
28
|
+
"lint:fix": "pnpm run lint:fix:js+ts && pnpm run lint:fix:format",
|
|
29
|
+
"lint:fix:js+ts": "pnpm run lint:js+ts --fix",
|
|
30
|
+
"lint:fix:format": "prettier \"**/*\" --write --ignore-unknown",
|
|
31
|
+
"prepare": "husky",
|
|
32
|
+
"release": "changeset publish",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "jest --watch"
|
|
35
|
+
},
|
|
21
36
|
"dependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
37
|
+
"@anthropic-ai/claude-agent-sdk": "^0.1.73",
|
|
38
|
+
"@inquirer/prompts": "^7.10.1",
|
|
39
|
+
"@listr2/manager": "^3.0.5",
|
|
40
|
+
"@types/spinnies": "^0.5.3",
|
|
41
|
+
"jscodeshift": "^17.3",
|
|
42
|
+
"listr2": "^9.0.5",
|
|
43
|
+
"spinnies": "^0.5.1"
|
|
24
44
|
},
|
|
25
45
|
"devDependencies": {
|
|
26
|
-
"@
|
|
46
|
+
"@anthropic-ai/sdk": "^0.71.2",
|
|
47
|
+
"@babel/core": "^7.28.5",
|
|
27
48
|
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
28
|
-
"@babel/preset-env": "^7.28.
|
|
29
|
-
"@babel/preset-typescript": "^7.
|
|
30
|
-
"@changesets/changelog-github": "^0.5.
|
|
31
|
-
"@changesets/cli": "^2.29.
|
|
32
|
-
"@commitlint/cli": "^20.
|
|
33
|
-
"@commitlint/config-conventional": "^20.
|
|
34
|
-
"@inquirer/testing": "^2.1.
|
|
35
|
-
"@jest/globals": "^30.
|
|
36
|
-
"@transferwise/components": "^46.
|
|
49
|
+
"@babel/preset-env": "^7.28.5",
|
|
50
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
51
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
52
|
+
"@changesets/cli": "^2.29.8",
|
|
53
|
+
"@commitlint/cli": "^20.2.0",
|
|
54
|
+
"@commitlint/config-conventional": "^20.2.0",
|
|
55
|
+
"@inquirer/testing": "^2.1.53",
|
|
56
|
+
"@jest/globals": "^30.2.0",
|
|
57
|
+
"@transferwise/components": "^46.116.1",
|
|
37
58
|
"@types/jest": "^30.0.0",
|
|
38
59
|
"@types/jscodeshift": "^17.3.0",
|
|
39
|
-
"@types/node": "^24.4
|
|
60
|
+
"@types/node": "^24.10.4",
|
|
40
61
|
"@types/semver": "^7.7.1",
|
|
41
|
-
"@wise/eslint-config": "^13.
|
|
42
|
-
"babel-jest": "^30.
|
|
62
|
+
"@wise/eslint-config": "^13.3.0",
|
|
63
|
+
"babel-jest": "^30.2.0",
|
|
43
64
|
"babel-plugin-transform-import-meta": "^2.3.3",
|
|
44
|
-
"eslint": "^9.
|
|
65
|
+
"eslint": "^9.39.2",
|
|
45
66
|
"husky": "^9.1.7",
|
|
46
|
-
"jest": "^30.
|
|
67
|
+
"jest": "^30.2.0",
|
|
47
68
|
"jest-file-snapshot": "^0.7.0",
|
|
48
|
-
"prettier": "^3.
|
|
49
|
-
"semver": "^7.7.
|
|
50
|
-
"ts-jest": "^29.4.
|
|
69
|
+
"prettier": "^3.7.4",
|
|
70
|
+
"semver": "^7.7.3",
|
|
71
|
+
"ts-jest": "^29.4.6",
|
|
51
72
|
"ts-node": "^10.9.2",
|
|
52
|
-
"tsdown": "^0.
|
|
53
|
-
"typescript": "^5.9.
|
|
73
|
+
"tsdown": "^0.18.1",
|
|
74
|
+
"typescript": "^5.9.3"
|
|
54
75
|
},
|
|
55
76
|
"publishConfig": {
|
|
56
77
|
"access": "public"
|
|
57
78
|
},
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
"changeset": "changeset",
|
|
61
|
-
"lint": "pnpm run lint:js+ts && pnpm run lint:format",
|
|
62
|
-
"lint:js+ts": "eslint '**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}' --concurrency=auto",
|
|
63
|
-
"lint:format": "prettier \"**/*\" --check --ignore-unknown",
|
|
64
|
-
"lint:types": "tsc --noEmit",
|
|
65
|
-
"lint:fix": "pnpm run lint:fix:js+ts && pnpm run lint:fix:format",
|
|
66
|
-
"lint:fix:js+ts": "pnpm run lint:js+ts --fix",
|
|
67
|
-
"lint:fix:format": "prettier \"**/*\" --write --ignore-unknown",
|
|
68
|
-
"release": "changeset publish",
|
|
69
|
-
"test": "jest",
|
|
70
|
-
"test:watch": "jest --watch"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
79
|
+
"packageManager": "pnpm@10.26.1+sha512.664074abc367d2c9324fdc18037097ce0a8f126034160f709928e9e9f95d98714347044e5c3164d65bd5da6c59c6be362b107546292a8eecb7999196e5ce58fa"
|
|
80
|
+
}
|