@wise/wds-codemods 0.0.1-experimental-868aa03 → 0.0.1-experimental-c483d40
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/dist/index.js +79 -226
- package/dist/index.js.map +1 -1
- package/dist/{reportManualReview-DQ00-OKx.js → reportManualReview-CDdJazd3.js} +4 -3
- package/dist/{reportManualReview-DQ00-OKx.js.map → reportManualReview-CDdJazd3.js.map} +1 -1
- package/dist/transforms/button.js +10 -7
- package/dist/transforms/button.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,162 +1,73 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_reportManualReview = require('./reportManualReview-
|
|
3
|
-
const node_child_process = require_reportManualReview.__toESM(require("node:child_process"));
|
|
2
|
+
const require_reportManualReview = require('./reportManualReview-CDdJazd3.js');
|
|
4
3
|
const node_fs_promises = require_reportManualReview.__toESM(require("node:fs/promises"));
|
|
4
|
+
const node_child_process = require_reportManualReview.__toESM(require("node:child_process"));
|
|
5
5
|
const node_path = require_reportManualReview.__toESM(require("node:path"));
|
|
6
6
|
const node_url = require_reportManualReview.__toESM(require("node:url"));
|
|
7
|
-
const node_fs = require_reportManualReview.__toESM(require("node:fs"));
|
|
8
7
|
const __inquirer_prompts = require_reportManualReview.__toESM(require("@inquirer/prompts"));
|
|
8
|
+
const node_fs = require_reportManualReview.__toESM(require("node:fs"));
|
|
9
9
|
|
|
10
10
|
//#region src/utils/getOptions.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
message: "Select a packages to transform:",
|
|
34
|
-
choices: nonRootPackages.map((file) => ({
|
|
35
|
-
name: file,
|
|
36
|
-
value: file,
|
|
37
|
-
checked: true
|
|
38
|
-
}))
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Determine user choice between CLI arg and Inquirer prompt: codemod
|
|
43
|
-
*/
|
|
44
|
-
const determineTransformer = async ({ candidate, transformFiles }) => {
|
|
45
|
-
const codemodMessage = "Select codemod to run:";
|
|
46
|
-
if (candidate && transformFiles.includes(candidate)) {
|
|
47
|
-
logToInquirer(codemodMessage, candidate);
|
|
48
|
-
return candidate;
|
|
11
|
+
async function getOptions(transformFiles) {
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
if (args.length > 0) {
|
|
14
|
+
const [transformFile$1, targetPath$1] = args;
|
|
15
|
+
const dry$1 = args.includes("--dry") || args.includes("--dry-run");
|
|
16
|
+
const print$1 = args.includes("--print");
|
|
17
|
+
const ignorePatternIndex = args.findIndex((arg) => arg === "--ignore-pattern");
|
|
18
|
+
let ignorePattern$1;
|
|
19
|
+
if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) ignorePattern$1 = args[ignorePatternIndex + 1];
|
|
20
|
+
const gitignore$1 = args.includes("--gitignore");
|
|
21
|
+
const noGitignore = args.includes("--no-gitignore");
|
|
22
|
+
if (!transformFile$1 || !transformFiles.includes(transformFile$1)) throw new Error("Invalid transform file specified.");
|
|
23
|
+
if (!targetPath$1) throw new Error("Target path cannot be empty.");
|
|
24
|
+
const useGitignore = !!(gitignore$1 || !gitignore$1 && !noGitignore);
|
|
25
|
+
return {
|
|
26
|
+
transformFile: transformFile$1,
|
|
27
|
+
targetPath: targetPath$1,
|
|
28
|
+
dry: dry$1,
|
|
29
|
+
print: print$1,
|
|
30
|
+
ignorePattern: ignorePattern$1,
|
|
31
|
+
gitignore: useGitignore
|
|
32
|
+
};
|
|
49
33
|
}
|
|
50
|
-
|
|
51
|
-
message:
|
|
34
|
+
const transformFile = await (0, __inquirer_prompts.select)({
|
|
35
|
+
message: "Select a codemod transform to run:",
|
|
52
36
|
choices: transformFiles.map((file) => ({
|
|
53
37
|
name: file,
|
|
54
38
|
value: file
|
|
55
39
|
}))
|
|
56
40
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
const determinePaths = async ({ candidate, root, packages }) => {
|
|
62
|
-
const targetPaths = [];
|
|
63
|
-
if (candidate && (0, node_fs.existsSync)((0, node_path.join)(root, candidate))) {
|
|
64
|
-
logToInquirer("Path to run codemod on", candidate);
|
|
65
|
-
targetPaths.push(candidate);
|
|
66
|
-
}
|
|
67
|
-
if (!targetPaths.length) {
|
|
68
|
-
const packagesToProcess = await queryPackages(packages);
|
|
69
|
-
targetPaths.push(...packagesToProcess ?? []);
|
|
70
|
-
}
|
|
71
|
-
return targetPaths;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Determine user choice between CLI arg and Inquirer prompt: dry mode
|
|
75
|
-
*/
|
|
76
|
-
const determineIsDryMode = async (args) => {
|
|
77
|
-
const message = "Run in dry mode (no changes written to files)?";
|
|
78
|
-
if (args.includes("--dry") || args.includes("--dry-run")) {
|
|
79
|
-
logToInquirer(message, "Yes");
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return (0, __inquirer_prompts.confirm)({
|
|
83
|
-
message,
|
|
84
|
-
default: false
|
|
41
|
+
const targetPath = await (0, __inquirer_prompts.input)({
|
|
42
|
+
message: "Enter the target directory or file path to run codemod on:",
|
|
43
|
+
validate: (value) => value.trim() !== "" || "Target path cannot be empty"
|
|
85
44
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
if (args.includes("--print")) {
|
|
93
|
-
logToInquirer(message, "Yes");
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
return (0, __inquirer_prompts.confirm)({
|
|
97
|
-
message,
|
|
45
|
+
const dry = await (0, __inquirer_prompts.confirm)({
|
|
46
|
+
message: "Run in dry mode (no changes written to files)?",
|
|
47
|
+
default: true
|
|
48
|
+
});
|
|
49
|
+
const print = await (0, __inquirer_prompts.confirm)({
|
|
50
|
+
message: "Print transformed source to console?",
|
|
98
51
|
default: false
|
|
99
52
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
const determineIgnorePatterns = async (args) => {
|
|
105
|
-
const message = "Enter ignore pattern(s) (comma separated) or leave empty:";
|
|
106
|
-
const ignorePatternIndex = args.findIndex((arg) => arg === "--ignore-pattern");
|
|
107
|
-
let ignorePattern;
|
|
108
|
-
if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) ignorePattern = args[ignorePatternIndex + 1];
|
|
109
|
-
if (ignorePattern) {
|
|
110
|
-
logToInquirer(message, ignorePattern);
|
|
111
|
-
return ignorePattern;
|
|
112
|
-
}
|
|
113
|
-
return (0, __inquirer_prompts.input)({
|
|
114
|
-
message,
|
|
115
|
-
validate: () => true
|
|
53
|
+
const ignorePattern = await (0, __inquirer_prompts.input)({
|
|
54
|
+
message: "Enter ignore pattern(s) (comma separated) or leave empty:",
|
|
55
|
+
validate: (value) => true
|
|
116
56
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* Determine user choice between CLI arg and Inquirer prompt: gitignore
|
|
120
|
-
*/
|
|
121
|
-
const determineGitIgnore = async (args) => {
|
|
122
|
-
const message = "Respect .gitignore files?";
|
|
123
|
-
if (args.includes("--gitignore")) {
|
|
124
|
-
logToInquirer(message, "Yes");
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
if (args.includes("--no-gitignore")) {
|
|
128
|
-
logToInquirer(message, "No");
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
return (0, __inquirer_prompts.confirm)({
|
|
132
|
-
message,
|
|
57
|
+
const gitignore = await (0, __inquirer_prompts.confirm)({
|
|
58
|
+
message: "Respect .gitignore files?",
|
|
133
59
|
default: true
|
|
134
60
|
});
|
|
135
|
-
};
|
|
136
|
-
async function getOptions({ transformFiles, packages, root }) {
|
|
137
|
-
const args = process.argv.slice(2);
|
|
138
|
-
const transformFile = await determineTransformer({
|
|
139
|
-
candidate: args[0],
|
|
140
|
-
transformFiles
|
|
141
|
-
});
|
|
142
|
-
const targetPaths = await determinePaths({
|
|
143
|
-
candidate: args[1],
|
|
144
|
-
packages,
|
|
145
|
-
root
|
|
146
|
-
});
|
|
147
|
-
const isDry = await determineIsDryMode(args);
|
|
148
|
-
const isPrint = await determineIsPrint(args);
|
|
149
|
-
const ignorePatterns = await determineIgnorePatterns(args);
|
|
150
|
-
const useGitIgnore = await determineGitIgnore(args);
|
|
151
61
|
return {
|
|
152
62
|
transformFile,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
63
|
+
targetPath,
|
|
64
|
+
dry,
|
|
65
|
+
print,
|
|
66
|
+
ignorePattern,
|
|
67
|
+
gitignore
|
|
158
68
|
};
|
|
159
69
|
}
|
|
70
|
+
var getOptions_default = getOptions;
|
|
160
71
|
|
|
161
72
|
//#endregion
|
|
162
73
|
//#region src/utils/loadTransformModules.ts
|
|
@@ -177,108 +88,50 @@ async function loadTransformModules(transformsDir) {
|
|
|
177
88
|
transformFiles
|
|
178
89
|
};
|
|
179
90
|
}
|
|
180
|
-
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/utils/repository.ts
|
|
183
|
-
/**
|
|
184
|
-
* Finds the root of the project by looking for the `.git` directory.
|
|
185
|
-
*/
|
|
186
|
-
function findProjectRoot() {
|
|
187
|
-
try {
|
|
188
|
-
const gitRoot = (0, node_child_process.execSync)("git rev-parse --show-toplevel", {
|
|
189
|
-
cwd: process.cwd(),
|
|
190
|
-
encoding: "utf8",
|
|
191
|
-
stdio: [
|
|
192
|
-
"ignore",
|
|
193
|
-
"pipe",
|
|
194
|
-
"ignore"
|
|
195
|
-
]
|
|
196
|
-
}).trim();
|
|
197
|
-
return gitRoot && (0, node_fs.existsSync)(gitRoot) ? gitRoot : "";
|
|
198
|
-
} catch {
|
|
199
|
-
return "";
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Quick and dirty way of determining package roots based on
|
|
204
|
-
* the presence of `package.json` files and them optimistically
|
|
205
|
-
* containing a `@transferwise/components` string.
|
|
206
|
-
* */
|
|
207
|
-
function findPackages() {
|
|
208
|
-
try {
|
|
209
|
-
const packages = (0, node_child_process.execSync)([
|
|
210
|
-
"find ./",
|
|
211
|
-
"-type f",
|
|
212
|
-
"-name \"package.json\"",
|
|
213
|
-
"-not -path \"*/node_modules/*\"",
|
|
214
|
-
"|",
|
|
215
|
-
"xargs grep -l \"@transferwise/components\""
|
|
216
|
-
].join(" "), {
|
|
217
|
-
cwd: findProjectRoot(),
|
|
218
|
-
encoding: "utf8"
|
|
219
|
-
}).trim().split("\n").map(node_path.default.dirname);
|
|
220
|
-
console.log(packages);
|
|
221
|
-
if (packages.length === 0) throw new Error();
|
|
222
|
-
return packages;
|
|
223
|
-
} catch {
|
|
224
|
-
throw new Error("No suitable package roots found in the repository.");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
91
|
+
var loadTransformModules_default = loadTransformModules;
|
|
227
92
|
|
|
228
93
|
//#endregion
|
|
229
94
|
//#region src/runCodemod.ts
|
|
230
95
|
const currentFilePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
231
96
|
const currentDirPath = node_path.default.dirname(currentFilePath);
|
|
232
|
-
const resetReportFile = async (reportPath) => {
|
|
233
|
-
try {
|
|
234
|
-
await node_fs_promises.default.access(reportPath);
|
|
235
|
-
await node_fs_promises.default.rm(reportPath);
|
|
236
|
-
console.debug(`Removed existing report file: ${reportPath}`);
|
|
237
|
-
} catch {
|
|
238
|
-
console.debug(`No existing report file to remove: ${reportPath}`);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const summariseReportFile = async (reportPath) => {
|
|
242
|
-
try {
|
|
243
|
-
const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
|
|
244
|
-
const lines = reportContent.split("\n").filter(Boolean);
|
|
245
|
-
if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
|
|
246
|
-
else console.debug(`Report file exists but is empty: ${reportPath}`);
|
|
247
|
-
} catch {
|
|
248
|
-
console.debug(`No report file generated - no manual reviews needed`);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
97
|
async function runCodemod(transformsDir) {
|
|
252
98
|
try {
|
|
253
|
-
const packages = findPackages();
|
|
254
|
-
const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
|
|
255
99
|
const resolvedTransformsDir = transformsDir ?? node_path.default.resolve(currentDirPath, "../dist/transforms");
|
|
256
100
|
console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);
|
|
257
|
-
await
|
|
258
|
-
const { transformFiles } = await loadTransformModules(resolvedTransformsDir);
|
|
101
|
+
const { transformFiles } = await loadTransformModules_default(resolvedTransformsDir);
|
|
259
102
|
if (transformFiles.length === 0) throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
root: findProjectRoot(),
|
|
263
|
-
transformFiles: await Promise.all(transformFiles)
|
|
264
|
-
});
|
|
103
|
+
const resolvedTransformFiles = await Promise.all(transformFiles);
|
|
104
|
+
const options = await getOptions_default(resolvedTransformFiles);
|
|
265
105
|
const codemodPath = node_path.default.resolve(resolvedTransformsDir, `${options.transformFile}.js`);
|
|
266
106
|
console.debug(`Resolved codemod path: ${codemodPath}`);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
107
|
+
const args = [
|
|
108
|
+
"-t",
|
|
109
|
+
codemodPath,
|
|
110
|
+
options.targetPath,
|
|
111
|
+
options.dry ? "--dry" : "",
|
|
112
|
+
options.print ? "--print" : "",
|
|
113
|
+
options.ignorePattern ? options.ignorePattern.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
|
|
114
|
+
options.gitignore ? "--gitignore" : ""
|
|
115
|
+
].filter(Boolean);
|
|
116
|
+
const command = `npx jscodeshift ${args.join(" ")}`;
|
|
117
|
+
console.debug(`Running: ${command}`);
|
|
118
|
+
const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
|
|
119
|
+
try {
|
|
120
|
+
await node_fs_promises.default.access(reportPath);
|
|
121
|
+
await node_fs_promises.default.rm(reportPath);
|
|
122
|
+
console.debug(`Removed existing report file: ${reportPath}`);
|
|
123
|
+
} catch {
|
|
124
|
+
console.debug(`No existing report file to remove: ${reportPath}`);
|
|
125
|
+
}
|
|
126
|
+
(0, node_child_process.execSync)(command, { stdio: "inherit" });
|
|
127
|
+
try {
|
|
128
|
+
const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
|
|
129
|
+
const lines = reportContent.split("\n").filter(Boolean);
|
|
130
|
+
if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
|
|
131
|
+
else console.debug(`Report file exists but is empty: ${reportPath}`);
|
|
132
|
+
} catch {
|
|
133
|
+
console.debug(`No report file generated - no manual reviews needed`);
|
|
134
|
+
}
|
|
282
135
|
} catch (error) {
|
|
283
136
|
if (error instanceof Error) console.error("Error running codemod:", error.message);
|
|
284
137
|
else console.error("Error running codemod:", error);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ignorePattern: string | undefined","transformModules: Record<string, unknown>","fs","path","path","path","fs","error: unknown"],"sources":["../src/utils/getOptions.ts","../src/utils/loadTransformModules.ts","../src/utils/repository.ts","../src/runCodemod.ts","../src/index.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport { checkbox, confirm, input, select as list } from '@inquirer/prompts';\n\n/**\n * if args are provided via CLI, log them to the console in\n * a formatted way matching Inquirer's style\n */\nconst logToInquirer = (label: string, value: string) => {\n const checkmark = '\\x1b[32m✔\\x1b[0m'; // Green checkmark\n const boldLabel = `\\x1b[1m${label}\\x1b[0m`; // Bold label\n const greenValue = `\\x1b[32m${value}\\x1b[0m`; // Green value\n\n console.info(`${checkmark} ${boldLabel} ${greenValue}`);\n};\n\n/**\n * Lets user pick from available packages to run the codemod on\n */\nconst queryPackages = async (packages: string[]) => {\n const message = 'Path to run codemod on:';\n const nonRootPackages = packages.filter((pkg) => pkg !== '.');\n\n // root package only\n if (packages.length === 1 && nonRootPackages.length === 0) {\n logToInquirer(message, packages[0]);\n return packages;\n }\n\n // multiple non-root packages\n if (nonRootPackages.length >= 1) {\n return checkbox({\n required: true,\n message: 'Select a packages to transform:',\n choices: nonRootPackages.map((file) => ({\n name: file,\n value: file,\n checked: true,\n })),\n });\n }\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: codemod\n */\nconst determineTransformer = async ({\n candidate,\n transformFiles,\n}: {\n candidate: string;\n transformFiles: string[];\n}): Promise<string> => {\n const codemodMessage = 'Select codemod to run:';\n\n if (candidate && transformFiles.includes(candidate)) {\n logToInquirer(codemodMessage, candidate);\n return candidate;\n }\n\n return list({\n message: codemodMessage,\n choices: transformFiles.map((file) => ({ name: file, value: file })),\n });\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: paths/packages to process\n */\nconst determinePaths = async ({\n candidate,\n root,\n packages,\n}: {\n candidate: string;\n root: string;\n packages: string[];\n}): Promise<string[]> => {\n const targetPaths = [];\n\n if (candidate && existsSync(join(root, candidate))) {\n logToInquirer('Path to run codemod on', candidate);\n targetPaths.push(candidate);\n }\n\n if (!targetPaths.length) {\n const packagesToProcess = await queryPackages(packages);\n targetPaths.push(...(packagesToProcess ?? []));\n }\n\n return targetPaths;\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: dry mode\n */\nconst determineIsDryMode = async (args: string[]) => {\n const message = 'Run in dry mode (no changes written to files)?';\n if (args.includes('--dry') || args.includes('--dry-run')) {\n logToInquirer(message, 'Yes');\n return true;\n }\n\n return confirm({ message, default: false });\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: print to CLI\n */\nconst determineIsPrint = async (args: string[]) => {\n const message = 'Print transformed source to console?';\n\n if (args.includes('--print')) {\n logToInquirer(message, 'Yes');\n return true;\n }\n\n return confirm({ message, default: false });\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: ignore patterns\n */\nconst determineIgnorePatterns = async (args: string[]) => {\n const message = 'Enter ignore pattern(s) (comma separated) or leave empty:';\n const ignorePatternIndex = args.findIndex((arg) => arg === '--ignore-pattern');\n\n let ignorePattern: string | undefined;\n\n if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) {\n ignorePattern = args[ignorePatternIndex + 1];\n }\n\n if (ignorePattern) {\n logToInquirer(message, ignorePattern);\n return ignorePattern;\n }\n\n return input({\n message,\n validate: () => true,\n });\n};\n\n/**\n * Determine user choice between CLI arg and Inquirer prompt: gitignore\n */\nconst determineGitIgnore = async (args: string[]) => {\n const message = 'Respect .gitignore files?';\n\n if (args.includes('--gitignore')) {\n logToInquirer(message, 'Yes');\n return true;\n }\n\n if (args.includes('--no-gitignore')) {\n logToInquirer(message, 'No');\n return false;\n }\n\n return confirm({ message, default: true });\n};\n\ninterface OptionsParams {\n transformFiles: string[];\n packages: string[];\n root: string;\n}\nasync function getOptions({ transformFiles, packages, root }: OptionsParams) {\n const args = process.argv.slice(2);\n\n const transformFile = await determineTransformer({ candidate: args[0], transformFiles });\n const targetPaths = await determinePaths({ candidate: args[1], packages, root });\n const isDry = await determineIsDryMode(args);\n const isPrint = await determineIsPrint(args);\n const ignorePatterns = await determineIgnorePatterns(args);\n const useGitIgnore = await determineGitIgnore(args);\n\n return {\n transformFile,\n targetPaths,\n isDry,\n isPrint,\n ignorePatterns,\n useGitIgnore,\n };\n}\n\nexport default getOptions;\n","import { promises as fs } from 'fs';\nimport path from 'path';\n\ninterface TransformModule {\n default: {\n default: unknown;\n };\n}\n\nasync function loadTransformModules(transformsDir: string) {\n let transformModules: Record<string, unknown> = {};\n\n const files = await fs.readdir(transformsDir);\n const transformFiles = await Promise.all(\n files\n .filter((file) => file.endsWith('.js'))\n .map(async (file) => {\n const transformPath = path.join(transformsDir, file);\n const transformModule = (await import(transformPath)) as TransformModule;\n transformModules = { ...transformModules, [file]: transformModule.default.default };\n return file.replace('.js', '');\n }),\n );\n\n return { transformModules, transformFiles };\n}\n\nexport default loadTransformModules;\n","import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Finds the root of the project by looking for the `.git` directory.\n */\nexport function findProjectRoot(): string {\n try {\n const gitRoot = execSync('git rev-parse --show-toplevel', {\n cwd: process.cwd(),\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim();\n\n return gitRoot && existsSync(gitRoot) ? gitRoot : '';\n } catch {\n return '';\n }\n}\n\n/**\n * Quick and dirty way of determining package roots based on\n * the presence of `package.json` files and them optimistically\n * containing a `@transferwise/components` string.\n * */\nexport function findPackages() {\n try {\n const packages = execSync(\n [\n 'find ./',\n '-type f',\n '-name \"package.json\"',\n '-not -path \"*/node_modules/*\"',\n '|',\n 'xargs grep -l \"@transferwise/components\"',\n ].join(' '),\n {\n cwd: findProjectRoot(),\n encoding: 'utf8',\n },\n )\n .trim()\n .split('\\n')\n .map(path.dirname);\n\n console.log(packages);\n\n if (packages.length === 0) {\n throw new Error();\n }\n\n return packages;\n } catch {\n throw new Error('No suitable package roots found in the repository.');\n }\n}\n","#!/usr/bin/env node\n\nimport { execSync } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { findPackages, findProjectRoot, getOptions, loadTransformModules } from './utils';\n\nconst currentFilePath = fileURLToPath(import.meta.url);\nconst currentDirPath = path.dirname(currentFilePath);\n\nconst resetReportFile = async (reportPath: string) => {\n try {\n await fs.access(reportPath);\n await fs.rm(reportPath);\n console.debug(`Removed existing report file: ${reportPath}`);\n } catch {\n console.debug(`No existing report file to remove: ${reportPath}`);\n }\n};\n\nconst summariseReportFile = async (reportPath: string) => {\n try {\n const reportContent = await fs.readFile(reportPath, 'utf8');\n const lines = reportContent.split('\\n').filter(Boolean);\n if (lines.length) {\n console.log(\n `\\n⚠️ ${lines.length} manual review${lines.length > 1 ? 's are' : ' is'} required. See ${reportPath} for details.`,\n );\n } else {\n console.debug(`Report file exists but is empty: ${reportPath}`);\n }\n } catch {\n console.debug(`No report file generated - no manual reviews needed`);\n }\n};\n\nasync function runCodemod(transformsDir?: string) {\n try {\n const packages = findPackages();\n const reportPath = path.resolve(process.cwd(), 'codemod-report.txt');\n const resolvedTransformsDir =\n transformsDir ?? path.resolve(currentDirPath, '../dist/transforms');\n console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);\n\n await resetReportFile(reportPath);\n\n const { transformFiles } = await loadTransformModules(resolvedTransformsDir);\n if (transformFiles.length === 0) {\n throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);\n }\n\n const options = await getOptions({\n packages,\n root: findProjectRoot(),\n transformFiles: await Promise.all(transformFiles),\n });\n\n const codemodPath = path.resolve(resolvedTransformsDir, `${options.transformFile}.js`);\n console.debug(`Resolved codemod path: ${codemodPath}`);\n\n options.targetPaths.map((targetPath) => {\n const args = [\n '-t',\n codemodPath,\n targetPath,\n options.isDry ? '--dry' : '',\n options.isPrint ? '--print' : '',\n options.ignorePatterns\n ? options.ignorePatterns\n .split(',')\n .map((pattern) => `--ignore-pattern=${pattern.trim()}`)\n .join(' ')\n : '',\n options.useGitIgnore ? '--gitignore' : '',\n ].filter(Boolean);\n\n const command = `npx jscodeshift ${args.join(' ')}`;\n console.debug(`Running: ${command}`);\n\n return execSync(command, { stdio: 'inherit' });\n });\n\n await summariseReportFile(reportPath);\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error('Error running codemod:', error.message);\n } else {\n console.error('Error running codemod:', error);\n }\n if (process.env.NODE_ENV !== 'test') {\n process.exit(1);\n }\n }\n}\n\nexport { runCodemod };\n","#!/usr/bin/env node\nimport { runCodemod } from './runCodemod';\n\nvoid runCodemod();\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAM,iBAAiB,OAAe,UAAkB;CACtD,MAAM,YAAY;CAClB,MAAM,YAAY,UAAU,MAAM;CAClC,MAAM,aAAa,WAAW,MAAM;AAEpC,SAAQ,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG;AAC3C;;;;AAKD,MAAM,gBAAgB,OAAO,aAAuB;CAClD,MAAM,UAAU;CAChB,MAAM,kBAAkB,SAAS,QAAQ,QAAQ,QAAQ;AAGzD,KAAI,SAAS,WAAW,KAAK,gBAAgB,WAAW,GAAG;AACzD,gBAAc,SAAS,SAAS;AAChC,SAAO;CACR;AAGD,KAAI,gBAAgB,UAAU,EAC5B,yCAAgB;EACd,UAAU;EACV,SAAS;EACT,SAAS,gBAAgB,KAAK,UAAU;GACtC,MAAM;GACN,OAAO;GACP,SAAS;GACV;EACF;AAEJ;;;;AAKD,MAAM,uBAAuB,OAAO,EAClC,WACA,gBAID,KAAsB;CACrB,MAAM,iBAAiB;AAEvB,KAAI,aAAa,eAAe,SAAS,YAAY;AACnD,gBAAc,gBAAgB;AAC9B,SAAO;CACR;AAED,uCAAY;EACV,SAAS;EACT,SAAS,eAAe,KAAK,UAAU;GAAE,MAAM;GAAM,OAAO;GAAM;EACnE;AACF;;;;AAKD,MAAM,iBAAiB,OAAO,EAC5B,WACA,MACA,UAKD,KAAwB;CACvB,MAAM,cAAc,EAAE;AA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B,KAAK,KAAK;AAC7C,WAAQ,MAAM,YAAY;AAE1B,2CAAgB,SAAS,EAAE,OAAO,WAAW;EAC9C;AAED,QAAM,oBAAoB;CAC3B,SAAQE,OAAgB;AACvB,MAAI,iBAAiB,MACnB,SAAQ,MAAM,0BAA0B,MAAM;MAE9C,SAAQ,MAAM,0BAA0B;AAE1C,MAAI,QAAQ,IAAI,aAAa,OAC3B,SAAQ,KAAK;CAEhB;AACF;;;;AC5FI"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["transformFile","targetPath","dry","print","ignorePattern: string | undefined","gitignore","transformModules: Record<string, unknown>","fs","path","path","loadTransformModules","getOptions","fs","error: unknown"],"sources":["../src/utils/getOptions.ts","../src/utils/loadTransformModules.ts","../src/runCodemod.ts","../src/index.ts"],"sourcesContent":["import { confirm, input, select as list } from '@inquirer/prompts';\n\nasync function getOptions(transformFiles: string[]) {\n const args = process.argv.slice(2);\n if (args.length > 0) {\n const [transformFile, targetPath] = args;\n const dry = args.includes('--dry') || args.includes('--dry-run');\n const print = args.includes('--print');\n const ignorePatternIndex = args.findIndex((arg) => arg === '--ignore-pattern');\n let ignorePattern: string | undefined;\n if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) {\n ignorePattern = args[ignorePatternIndex + 1];\n }\n const gitignore = args.includes('--gitignore');\n const noGitignore = args.includes('--no-gitignore');\n\n if (!transformFile || !transformFiles.includes(transformFile)) {\n throw new Error('Invalid transform file specified.');\n }\n if (!targetPath) {\n throw new Error('Target path cannot be empty.');\n }\n\n // If both --gitignore and --no-gitignore are specified, prioritize --gitignore\n const useGitignore = !!(gitignore || (!gitignore && !noGitignore));\n\n return { transformFile, targetPath, dry, print, ignorePattern, gitignore: useGitignore };\n }\n\n const transformFile = await list({\n message: 'Select a codemod transform to run:',\n choices: transformFiles.map((file) => ({ name: file, value: file })),\n });\n\n const targetPath = await input({\n message: 'Enter the target directory or file path to run codemod on:',\n validate: (value) => value.trim() !== '' || 'Target path cannot be empty',\n });\n\n const dry = await confirm({\n message: 'Run in dry mode (no changes written to files)?',\n default: true,\n });\n\n const print = await confirm({\n message: 'Print transformed source to console?',\n default: false,\n });\n\n const ignorePattern = await input({\n message: 'Enter ignore pattern(s) (comma separated) or leave empty:',\n validate: (value) => true,\n });\n\n const gitignore = await confirm({\n message: 'Respect .gitignore files?',\n default: true,\n });\n\n return { transformFile, targetPath, dry, print, ignorePattern, gitignore };\n}\n\nexport default getOptions;\n","import { promises as fs } from 'fs';\nimport path from 'path';\n\ninterface TransformModule {\n default: {\n default: unknown;\n };\n}\n\nasync function loadTransformModules(transformsDir: string) {\n let transformModules: Record<string, unknown> = {};\n\n const files = await fs.readdir(transformsDir);\n const transformFiles = await Promise.all(\n files\n .filter((file) => file.endsWith('.js'))\n .map(async (file) => {\n const transformPath = path.join(transformsDir, file);\n const transformModule = (await import(transformPath)) as TransformModule;\n transformModules = { ...transformModules, [file]: transformModule.default.default };\n return file.replace('.js', '');\n }),\n );\n\n return { transformModules, transformFiles };\n}\n\nexport default loadTransformModules;\n","#!/usr/bin/env node\n\nimport fs from 'node:fs/promises';\n\nimport { execSync } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nimport { getOptions, handleError, loadTransformModules } from './utils';\n\nconst currentFilePath = fileURLToPath(import.meta.url);\nconst currentDirPath = path.dirname(currentFilePath);\n\nasync function runCodemod(transformsDir?: string) {\n try {\n const resolvedTransformsDir =\n transformsDir ?? path.resolve(currentDirPath, '../dist/transforms');\n console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);\n\n const { transformFiles } = await loadTransformModules(resolvedTransformsDir);\n\n if (transformFiles.length === 0) {\n throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);\n }\n\n const resolvedTransformFiles = await Promise.all(transformFiles);\n const options = await getOptions(resolvedTransformFiles);\n\n const codemodPath = path.resolve(resolvedTransformsDir, `${options.transformFile}.js`);\n console.debug(`Resolved codemod path: ${codemodPath}`);\n\n const args = [\n '-t',\n codemodPath,\n options.targetPath,\n options.dry ? '--dry' : '',\n options.print ? '--print' : '',\n options.ignorePattern\n ? options.ignorePattern\n .split(',')\n .map((pattern) => `--ignore-pattern=${pattern.trim()}`)\n .join(' ')\n : '',\n options.gitignore ? '--gitignore' : '',\n ].filter(Boolean);\n\n const command = `npx jscodeshift ${args.join(' ')}`;\n\n console.debug(`Running: ${command}`);\n\n const reportPath = path.resolve(process.cwd(), 'codemod-report.txt');\n\n try {\n await fs.access(reportPath);\n await fs.rm(reportPath);\n console.debug(`Removed existing report file: ${reportPath}`);\n } catch {\n console.debug(`No existing report file to remove: ${reportPath}`);\n }\n\n execSync(command, { stdio: 'inherit' });\n\n try {\n const reportContent = await fs.readFile(reportPath, 'utf8');\n const lines = reportContent.split('\\n').filter(Boolean);\n if (lines.length) {\n console.log(\n `\\n⚠️ ${lines.length} manual review${lines.length > 1 ? 's are' : ' is'} required. See ${reportPath} for details.`,\n );\n } else {\n console.debug(`Report file exists but is empty: ${reportPath}`);\n }\n } catch {\n console.debug(`No report file generated - no manual reviews needed`);\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error('Error running codemod:', error.message);\n } else {\n console.error('Error running codemod:', error);\n }\n if (process.env.NODE_ENV !== 'test') {\n process.exit(1);\n }\n }\n}\n\nexport { runCodemod };\n","#!/usr/bin/env node\nimport { runCodemod } from './runCodemod';\n\nvoid runCodemod();\n"],"mappings":";;;;;;;;;;AAEA,eAAe,WAAW,gBAA0B;CAClD,MAAM,OAAO,QAAQ,KAAK,MAAM;AAChC,KAAI,KAAK,SAAS,GAAG;EACnB,MAAM,CAACA,iBAAeC,gBAAc;EACpC,MAAMC,QAAM,KAAK,SAAS,YAAY,KAAK,SAAS;EACpD,MAAMC,UAAQ,KAAK,SAAS;EAC5B,MAAM,qBAAqB,KAAK,WAAW,QAAQ,QAAQ;EAC3D,IAAIC;AACJ,MAAI,uBAAuB,MAAM,KAAK,SAAS,qBAAqB,EAClE,mBAAgB,KAAK,qBAAqB;EA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AQ,KAAK;;;;;;AC/Ed"}
|
|
@@ -33,6 +33,7 @@ const reportManualReview = async (filePath, message) => {
|
|
|
33
33
|
const lineInfo = lineNumber ? `:${lineNumber}` : "";
|
|
34
34
|
await node_fs_promises.default.appendFile(REPORT_PATH, `[${filePath}${lineInfo}] ${cleanMessage}\n`, "utf8");
|
|
35
35
|
};
|
|
36
|
+
var reportManualReview_default = reportManualReview;
|
|
36
37
|
|
|
37
38
|
//#endregion
|
|
38
39
|
Object.defineProperty(exports, '__toESM', {
|
|
@@ -41,10 +42,10 @@ Object.defineProperty(exports, '__toESM', {
|
|
|
41
42
|
return __toESM;
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
|
-
Object.defineProperty(exports, '
|
|
45
|
+
Object.defineProperty(exports, 'reportManualReview_default', {
|
|
45
46
|
enumerable: true,
|
|
46
47
|
get: function () {
|
|
47
|
-
return
|
|
48
|
+
return reportManualReview_default;
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
|
-
//# sourceMappingURL=reportManualReview-
|
|
51
|
+
//# sourceMappingURL=reportManualReview-CDdJazd3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reportManualReview-
|
|
1
|
+
{"version":3,"file":"reportManualReview-CDdJazd3.js","names":["path","fs"],"sources":["../src/utils/reportManualReview.ts"],"sourcesContent":["import fs from 'node:fs/promises';\n\nimport path from 'path';\n\nconst REPORT_PATH = path.resolve(process.cwd(), 'codemod-report.txt');\n\nconst reportManualReview = async (filePath: string, message: string): Promise<void> => {\n const lineMatch = /at line (\\d+)/u.exec(message);\n const lineNumber = lineMatch?.[1];\n\n const cleanMessage = message.replace(/ at line \\d+/u, '');\n const lineInfo = lineNumber ? `:${lineNumber}` : '';\n\n await fs.appendFile(REPORT_PATH, `[${filePath}${lineInfo}] ${cleanMessage}\\n`, 'utf8');\n};\n\nexport default reportManualReview;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,cAAcA,kBAAK,QAAQ,QAAQ,OAAO;AAEhD,MAAM,qBAAqB,OAAO,UAAkB,YAAmC;CACrF,MAAM,YAAY,iBAAiB,KAAK;CACxC,MAAM,aAAa,YAAY;CAE/B,MAAM,eAAe,QAAQ,QAAQ,iBAAiB;CACtD,MAAM,WAAW,aAAa,IAAI,eAAe;AAEjD,OAAMC,yBAAG,WAAW,aAAa,IAAI,WAAW,SAAS,IAAI,aAAa,KAAK;;AAGjF,iCAAe"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const require_reportManualReview = require('../reportManualReview-
|
|
2
|
+
const require_reportManualReview = require('../reportManualReview-CDdJazd3.js');
|
|
3
3
|
|
|
4
4
|
//#region src/transforms/helpers/hasImport.ts
|
|
5
5
|
/**
|
|
@@ -31,6 +31,7 @@ function hasImport(root, sourceValue, importName, j) {
|
|
|
31
31
|
remove
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
var hasImport_default = hasImport;
|
|
34
35
|
|
|
35
36
|
//#endregion
|
|
36
37
|
//#region src/transforms/helpers/iconUtils.ts
|
|
@@ -66,6 +67,7 @@ const processIconChildren = (j, children, iconImports, openingElement) => {
|
|
|
66
67
|
if (iconChildIndex - 1 >= 0 && isWhitespaceJsxText(children[iconChildIndex - 1])) children.splice(iconChildIndex - 1, 1);
|
|
67
68
|
else if (isWhitespaceJsxText(children[iconChildIndex])) children.splice(iconChildIndex, 1);
|
|
68
69
|
};
|
|
70
|
+
var iconUtils_default = processIconChildren;
|
|
69
71
|
|
|
70
72
|
//#endregion
|
|
71
73
|
//#region src/transforms/helpers/jsxElementUtils.ts
|
|
@@ -345,8 +347,8 @@ const transformer = (file, api, options) => {
|
|
|
345
347
|
const root = j(file.source);
|
|
346
348
|
const manualReviewIssues = [];
|
|
347
349
|
const reporter = createReporter(j, manualReviewIssues);
|
|
348
|
-
const { exists: hasButtonImport } =
|
|
349
|
-
const { exists: hasActionButtonImport, remove: removeActionButtonImport } =
|
|
350
|
+
const { exists: hasButtonImport } = hasImport_default(root, "@transferwise/components", "Button", j);
|
|
351
|
+
const { exists: hasActionButtonImport, remove: removeActionButtonImport } = hasImport_default(root, "@transferwise/components", "ActionButton", j);
|
|
350
352
|
const iconImports = /* @__PURE__ */ new Set();
|
|
351
353
|
root.find(j.ImportDeclaration, { source: { value: "@transferwise/icons" } }).forEach((path) => {
|
|
352
354
|
path.node.specifiers?.forEach((specifier) => {
|
|
@@ -368,7 +370,7 @@ const transformer = (file, api, options) => {
|
|
|
368
370
|
attribute: j.jsxAttribute(j.jsxIdentifier("size"), j.literal("sm")),
|
|
369
371
|
name: "size"
|
|
370
372
|
}]);
|
|
371
|
-
|
|
373
|
+
iconUtils_default(j, path.node.children, iconImports, openingElement);
|
|
372
374
|
if ((openingElement.attributes ?? []).some((attr) => attr.type === "JSXSpreadAttribute")) reporter.reportSpreadProps(path);
|
|
373
375
|
const legacyPropNames = ["priority", "text"];
|
|
374
376
|
const legacyProps = {};
|
|
@@ -402,7 +404,7 @@ const transformer = (file, api, options) => {
|
|
|
402
404
|
attribute: j.jsxAttribute(j.jsxIdentifier("v2")),
|
|
403
405
|
name: "v2"
|
|
404
406
|
}]);
|
|
405
|
-
|
|
407
|
+
iconUtils_default(j, path.node.children, iconImports, openingElement);
|
|
406
408
|
const legacyProps = {};
|
|
407
409
|
const legacyPropNames = [
|
|
408
410
|
"priority",
|
|
@@ -505,12 +507,13 @@ const transformer = (file, api, options) => {
|
|
|
505
507
|
if ((openingElement.attributes ?? []).some((attr) => attr.type === "JSXSpreadAttribute")) reporter.reportSpreadProps(path);
|
|
506
508
|
});
|
|
507
509
|
if (manualReviewIssues.length > 0) manualReviewIssues.forEach(async (issue) => {
|
|
508
|
-
await require_reportManualReview.
|
|
510
|
+
await require_reportManualReview.reportManualReview_default(file.path, issue);
|
|
509
511
|
});
|
|
510
512
|
return root.toSource();
|
|
511
513
|
};
|
|
514
|
+
var transformer_default = transformer;
|
|
512
515
|
|
|
513
516
|
//#endregion
|
|
514
|
-
exports.default =
|
|
517
|
+
exports.default = transformer_default;
|
|
515
518
|
exports.parser = parser;
|
|
516
519
|
//# sourceMappingURL=button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":["priorityMapping: Record<string, Record<string, string>>","sizeMap: Record<string, string>","enumMapping: Record<string, string>","j: JSCodeshift","manualReviewIssues: string[]","legacyProps: LegacyProps","asValue: string | null","reportManualReview"],"sources":["../../src/transforms/helpers/hasImport.ts","../../src/transforms/helpers/iconUtils.ts","../../src/transforms/helpers/jsxElementUtils.ts","../../src/transforms/helpers/jsxReportingUtils.ts","../../src/transforms/button/transformer.ts"],"sourcesContent":["import type { Collection, JSCodeshift } from 'jscodeshift';\n\n/**\n * Checks if a specific import exists in the given root collection and provides\n * a method to remove it if found.\n */\nfunction hasImport(\n root: Collection,\n sourceValue: string,\n importName: string,\n j: JSCodeshift,\n): { exists: boolean; remove: () => void } {\n const importDeclarations = root.find(j.ImportDeclaration, {\n source: { value: sourceValue },\n });\n\n if (importDeclarations.size() === 0) {\n return {\n exists: false,\n remove: () => {},\n };\n }\n\n const namedImport = importDeclarations.find(j.ImportSpecifier, {\n imported: { name: importName },\n });\n\n const defaultImport = importDeclarations.find(j.ImportDefaultSpecifier, {\n local: { name: importName },\n });\n\n const exists = namedImport.size() > 0 || defaultImport.size() > 0;\n\n const remove = () => {\n importDeclarations.forEach((path) => {\n const filteredSpecifiers =\n path.node.specifiers?.filter((specifier) => {\n if (specifier.type === 'ImportSpecifier' && specifier.imported.name === importName) {\n return false;\n }\n if (specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name === importName) {\n return false;\n }\n return true;\n }) ?? [];\n\n if (filteredSpecifiers.length === 0) {\n path.prune();\n } else {\n j(path).replaceWith(\n j.importDeclaration(filteredSpecifiers, path.node.source, path.node.importKind),\n );\n }\n });\n };\n\n return { exists, remove };\n}\n\nexport default hasImport;\n","import type { JSCodeshift, JSXElement, JSXExpressionContainer } from 'jscodeshift';\n\n/**\n * Process children of a JSX element to detect icon components and add iconStart or iconEnd attributes accordingly.\n * This is specific to icon handling but can be reused in codemods dealing with icon children.\n */\nconst processIconChildren = (\n j: JSCodeshift,\n children: (JSXElement | JSXExpressionContainer | unknown)[] | undefined,\n iconImports: Set<string>,\n openingElement: JSXElement['openingElement'],\n) => {\n if (!children || !openingElement.attributes) return;\n\n const unwrapJsxElement = (node: unknown): JSXElement | unknown => {\n if (\n typeof node === 'object' &&\n node !== null &&\n 'type' in node &&\n node.type === 'JSXExpressionContainer' &&\n j.JSXElement.check((node as JSXExpressionContainer).expression)\n ) {\n return (node as JSXExpressionContainer).expression;\n }\n return node;\n };\n\n const totalChildren = children.length;\n\n // Find index of icon child\n const iconChildIndex = children.findIndex((child) => {\n const unwrapped = unwrapJsxElement(child);\n return (\n j.JSXElement.check(unwrapped) &&\n unwrapped.openingElement.name.type === 'JSXIdentifier' &&\n iconImports.has(unwrapped.openingElement.name.name)\n );\n });\n\n if (iconChildIndex === -1) return;\n\n const iconChild = unwrapJsxElement(children[iconChildIndex]) as JSXElement;\n\n if (!iconChild || iconChild.openingElement.name.type !== 'JSXIdentifier') return;\n\n const iconName = iconChild.openingElement.name.name;\n\n // Determine if icon is closer to start or end\n const distanceToStart = iconChildIndex;\n const distanceToEnd = totalChildren - 1 - iconChildIndex;\n const iconPropName = distanceToStart <= distanceToEnd ? 'addonStart' : 'addonEnd';\n\n // Build: { type: 'icon', value: <IconName /> }\n const iconObject = j.objectExpression([\n j.property('init', j.identifier('type'), j.literal('icon')),\n j.property('init', j.identifier('value'), iconChild),\n ]);\n const iconProp = j.jsxAttribute(\n j.jsxIdentifier(iconPropName),\n j.jsxExpressionContainer(iconObject),\n );\n\n openingElement.attributes.push(iconProp);\n\n // Remove the icon child\n children.splice(iconChildIndex, 1);\n\n // Helper to check if a child is whitespace-only JSXText\n const isWhitespaceJsxText = (node: unknown): boolean => {\n return (\n typeof node === 'object' &&\n node !== null &&\n (node as { type?: unknown }).type === 'JSXText' &&\n typeof (node as { value?: string }).value === 'string' &&\n (node as { value?: string }).value!.trim() === ''\n );\n };\n\n // Remove adjacent whitespace-only JSXText node if any\n if (iconChildIndex - 1 >= 0 && isWhitespaceJsxText(children[iconChildIndex - 1])) {\n children.splice(iconChildIndex - 1, 1);\n } else if (isWhitespaceJsxText(children[iconChildIndex])) {\n children.splice(iconChildIndex, 1);\n }\n};\n\nexport default processIconChildren;\n","import type {\n JSCodeshift,\n JSXAttribute,\n JSXElement,\n JSXIdentifier,\n JSXMemberExpression,\n JSXNamespacedName,\n JSXSpreadAttribute,\n} from 'jscodeshift';\n\n/**\n * Rename a JSX element name if it is a JSXIdentifier.\n */\nexport const setNameIfJSXIdentifier = (\n elementName: JSXIdentifier | JSXNamespacedName | JSXMemberExpression | undefined,\n newName: string,\n): JSXIdentifier | JSXNamespacedName | JSXMemberExpression | undefined => {\n if (elementName && elementName.type === 'JSXIdentifier') {\n return { ...elementName, name: newName };\n }\n return elementName;\n};\n\n/**\n * Check if a list of attributes contains a specific attribute by name.\n */\nexport const hasAttribute = (\n attributes: (JSXAttribute | JSXSpreadAttribute)[] | undefined,\n attributeName: string,\n): boolean => {\n return (\n Array.isArray(attributes) &&\n attributes.some(\n (attr): attr is JSXAttribute =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === attributeName,\n )\n );\n};\n\n/**\n * Check if a JSX element's openingElement has a specific attribute.\n */\nexport const hasAttributeOnElement = (\n element: JSXElement['openingElement'],\n attributeName: string,\n): boolean => {\n return hasAttribute(element.attributes, attributeName);\n};\n\n/**\n * Add specified attributes to a JSX element's openingElement if they are not already present.\n */\nexport const addAttributesIfMissing = (\n j: JSCodeshift,\n openingElement: JSXElement['openingElement'],\n attributesToAdd: { attribute: JSXAttribute; name: string }[],\n) => {\n if (!Array.isArray(openingElement.attributes)) return;\n const attrs = openingElement.attributes;\n attributesToAdd.forEach(({ attribute, name }) => {\n if (!hasAttributeOnElement(openingElement, name)) {\n attrs.push(attribute);\n }\n });\n};\n","import type { ASTPath, JSCodeshift, JSXAttribute, JSXElement, Node } from 'jscodeshift';\n\nexport interface ReporterOptions {\n jscodeshift: JSCodeshift;\n issues: string[];\n}\n\n/**\n * CodemodReporter is a utility class for reporting issues found during codemod transformations.\n * It provides methods to report issues related to JSX elements, props, and attributes.\n *\n * @example\n * ```typescript\n * const issues: string[] = [];\n * const reporter = createReporter(j, issues);\n *\n * // Report a deprecated prop\n * reporter.reportDeprecatedProp(buttonElement, 'flat', 'variant=\"text\"');\n *\n * // Report complex expression that needs review\n * reporter.reportAmbiguousExpression(element, 'size');\n *\n * // Auto-detect common issues\n * reporter.reportAttributeIssues(element);\n * ```\n */\nexport class CodemodReporter {\n private readonly j: JSCodeshift;\n private readonly issues: string[];\n\n constructor(options: ReporterOptions) {\n this.j = options.jscodeshift;\n this.issues = options.issues;\n }\n\n /**\n * Reports an issue with a JSX element\n */\n reportElement(element: JSXElement | ASTPath<JSXElement>, reason: string): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const line = this.getLineNumber(node);\n\n this.addIssue(`Manual review required: <${componentName}> at line ${line} ${reason}.`);\n }\n\n /**\n * Reports an issue with a specific prop\n */\n reportProp(element: JSXElement | ASTPath<JSXElement>, propName: string, reason: string): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const line = this.getLineNumber(node);\n\n this.addIssue(\n `Manual review required: prop \"${propName}\" on <${componentName}> at line ${line} ${reason}.`,\n );\n }\n\n /**\n * Reports an issue with a JSX attribute directly\n */\n reportAttribute(\n attr: JSXAttribute,\n element: JSXElement | ASTPath<JSXElement>,\n reason?: string,\n ): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const propName = this.getAttributeName(attr);\n const line = this.getLineNumber(attr) || this.getLineNumber(node);\n\n const defaultReason = this.getAttributeReason(attr);\n const finalReason = reason || defaultReason;\n\n this.addIssue(\n `Manual review required: prop \"${propName}\" on <${componentName}> at line ${line} ${finalReason}.`,\n );\n }\n\n /**\n * Reports spread props on an element\n */\n reportSpreadProps(element: JSXElement | ASTPath<JSXElement>): void {\n this.reportElement(element, 'contains spread props that need manual review');\n }\n\n /**\n * Reports conflicting prop and children\n */\n reportPropWithChildren(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(\n element,\n propName,\n `conflicts with children - both \"${propName}\" prop and children are present`,\n );\n }\n\n /**\n * Reports unsupported prop value\n */\n reportUnsupportedValue(\n element: JSXElement | ASTPath<JSXElement>,\n propName: string,\n value: string,\n ): void {\n this.reportProp(element, propName, `has unsupported value \"${value}\"`);\n }\n\n /**\n * Reports ambiguous expression in prop\n */\n reportAmbiguousExpression(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(element, propName, 'contains a complex expression that needs manual review');\n }\n\n /**\n * Reports ambiguous children (like dynamic icons)\n */\n reportAmbiguousChildren(element: JSXElement | ASTPath<JSXElement>, childType = 'content'): void {\n this.reportElement(element, `contains ambiguous ${childType} that needs manual review`);\n }\n\n /**\n * Reports deprecated prop usage\n */\n reportDeprecatedProp(\n element: JSXElement | ASTPath<JSXElement>,\n propName: string,\n alternative?: string,\n ): void {\n const suggestion = alternative ? ` Use ${alternative} instead` : '';\n this.reportProp(element, propName, `is deprecated${suggestion}`);\n }\n\n /**\n * Reports missing required prop\n */\n reportMissingRequiredProp(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(element, propName, 'is required but missing');\n }\n\n /**\n * Reports conflicting props\n */\n reportConflictingProps(element: JSXElement | ASTPath<JSXElement>, propNames: string[]): void {\n const propList = propNames.map((name) => `\"${name}\"`).join(', ');\n this.reportElement(element, `has conflicting props: ${propList} cannot be used together`);\n }\n\n /**\n * Auto-detects and reports common attribute issues\n */\n reportAttributeIssues(element: JSXElement | ASTPath<JSXElement>): void {\n const node = this.getNode(element);\n const { attributes } = node.openingElement;\n\n if (!attributes) return;\n\n // Check for spread props\n if (attributes.some((attr) => attr.type === 'JSXSpreadAttribute')) {\n this.reportSpreadProps(element);\n }\n\n // Check for complex expressions in attributes\n attributes.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.value?.type === 'JSXExpressionContainer') {\n this.reportAttribute(attr, element);\n }\n });\n }\n\n // Private helper methods\n private getNode(element: JSXElement | ASTPath<JSXElement>): JSXElement {\n return 'node' in element ? element.node : element;\n }\n\n private getComponentName(node: JSXElement): string {\n const { name } = node.openingElement;\n if (name.type === 'JSXIdentifier') {\n return name.name;\n }\n // Handle JSXMemberExpression, JSXNamespacedName, etc.\n return this.j(name).toSource();\n }\n\n private getLineNumber(node: JSXElement | JSXAttribute | Node): string {\n return node.loc?.start.line?.toString() || 'unknown';\n }\n\n private getAttributeName(attr: JSXAttribute): string {\n if (attr.name.type === 'JSXIdentifier') {\n return attr.name.name;\n }\n return this.j(attr.name).toSource();\n }\n\n private getAttributeReason(attr: JSXAttribute): string {\n if (!attr.value) return 'has no value';\n\n if (attr.value.type === 'JSXExpressionContainer') {\n const expr = attr.value.expression;\n const expressionType = expr.type.replace('Expression', '').toLowerCase();\n\n // Show actual value for simple cases\n if (expr.type === 'Identifier' || expr.type === 'MemberExpression') {\n const valueText = this.j(expr).toSource();\n return `contains a ${expressionType} (${valueText})`;\n }\n\n return `contains a complex ${expressionType} expression`;\n }\n\n return 'needs manual review';\n }\n\n private addIssue(message: string): void {\n this.issues.push(message);\n }\n}\n\nexport const createReporter = (j: JSCodeshift, issues: string[]): CodemodReporter => {\n return new CodemodReporter({ jscodeshift: j, issues });\n};\n","import type { API, FileInfo, JSCodeshift, JSXIdentifier, Options } from 'jscodeshift';\n\nimport reportManualReview from '../../utils/reportManualReview';\nimport hasImport from '../helpers/hasImport';\nimport processIconChildren from '../helpers/iconUtils';\nimport {\n addAttributesIfMissing,\n hasAttributeOnElement,\n setNameIfJSXIdentifier,\n} from '../helpers/jsxElementUtils';\nimport { createReporter } from '../helpers/jsxReportingUtils';\n\nexport const parser = 'tsx';\n\ninterface LegacyProps {\n priority?: string;\n size?: string;\n type?: string;\n htmlType?: string;\n sentiment?: string;\n [key: string]: unknown;\n}\n\nconst priorityMapping: Record<string, Record<string, string>> = {\n accent: {\n primary: 'primary',\n secondary: 'secondary-neutral',\n tertiary: 'tertiary',\n },\n positive: {\n primary: 'primary',\n secondary: 'secondary-neutral',\n tertiary: 'secondary-neutral',\n },\n negative: {\n primary: 'primary',\n secondary: 'secondary',\n tertiary: 'secondary',\n },\n};\n\nconst sizeMap: Record<string, string> = {\n EXTRA_SMALL: 'xs',\n SMALL: 'sm',\n MEDIUM: 'md',\n LARGE: 'lg',\n EXTRA_LARGE: 'xl',\n xs: 'sm',\n sm: 'sm',\n md: 'md',\n lg: 'lg',\n xl: 'xl',\n};\n\nconst resolveSize = (size?: string): string | undefined => {\n if (!size) return size;\n const match = /^Size\\.(EXTRA_SMALL|SMALL|MEDIUM|LARGE|EXTRA_LARGE)$/u.exec(size);\n if (match) {\n return sizeMap[match[1]];\n }\n return sizeMap[size] || size;\n};\n\nconst resolvePriority = (type?: string, priority?: string): string | undefined => {\n if (type && priority) {\n return priorityMapping[type]?.[priority] || priority;\n }\n return priority;\n};\n\nconst resolveType = (type?: string, htmlType?: string): string | null => {\n if (htmlType) {\n return htmlType;\n }\n\n const legacyButtonTypes = [\n 'accent',\n 'negative',\n 'positive',\n 'primary',\n 'pay',\n 'secondary',\n 'danger',\n 'link',\n ];\n return type && legacyButtonTypes.includes(type) ? type : null;\n};\n\nconst convertEnumValue = (value?: string): string | undefined => {\n if (!value) return value;\n const strippedValue = value.replace(/^['\"]|['\"]$/gu, '');\n const enumMapping: Record<string, string> = {\n 'Priority.SECONDARY': 'secondary',\n 'Priority.PRIMARY': 'primary',\n 'Priority.TERTIARY': 'tertiary',\n 'ControlType.NEGATIVE': 'negative',\n 'ControlType.POSITIVE': 'positive',\n 'ControlType.ACCENT': 'accent',\n };\n return enumMapping[strippedValue] || strippedValue;\n};\n\n/**\n * This transform function modifies the Button and ActionButton components from the @transferwise/components library.\n * It updates the ActionButton component to use the Button component with specific attributes and mappings.\n * It also processes icon children and removes legacy props.\n *\n * @param {FileInfo} file - The file information object.\n * @param {API} api - The API object for jscodeshift.\n * @param {Options} options - The options object for jscodeshift.\n * @returns {string} - The transformed source code.\n */\nconst transformer = (file: FileInfo, api: API, options: Options) => {\n const j: JSCodeshift = api.jscodeshift;\n const root = j(file.source);\n const manualReviewIssues: string[] = [];\n\n // Create reporter instance\n const reporter = createReporter(j, manualReviewIssues);\n\n const { exists: hasButtonImport } = hasImport(root, '@transferwise/components', 'Button', j);\n const { exists: hasActionButtonImport, remove: removeActionButtonImport } = hasImport(\n root,\n '@transferwise/components',\n 'ActionButton',\n j,\n );\n\n const iconImports = new Set<string>();\n root.find(j.ImportDeclaration, { source: { value: '@transferwise/icons' } }).forEach((path) => {\n path.node.specifiers?.forEach((specifier) => {\n if (\n (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') &&\n specifier.local\n ) {\n const localName = (specifier.local as { name: string }).name;\n iconImports.add(localName);\n }\n });\n });\n\n if (hasActionButtonImport) {\n root.findJSXElements('ActionButton').forEach((path) => {\n const { openingElement, closingElement } = path.node;\n\n openingElement.name = setNameIfJSXIdentifier(openingElement.name, 'Button')!;\n if (closingElement) {\n closingElement.name = setNameIfJSXIdentifier(closingElement.name, 'Button')!;\n }\n\n addAttributesIfMissing(j, openingElement, [\n { attribute: j.jsxAttribute(j.jsxIdentifier('v2')), name: 'v2' },\n { attribute: j.jsxAttribute(j.jsxIdentifier('size'), j.literal('sm')), name: 'size' },\n ]);\n\n processIconChildren(j, path.node.children, iconImports, openingElement);\n\n if ((openingElement.attributes ?? []).some((attr) => attr.type === 'JSXSpreadAttribute')) {\n reporter.reportSpreadProps(path);\n }\n\n const legacyPropNames = ['priority', 'text'];\n const legacyProps: LegacyProps = {};\n\n openingElement.attributes?.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.name && attr.name.type === 'JSXIdentifier') {\n const { name } = attr.name;\n if (legacyPropNames.includes(name)) {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n legacyProps[name] = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n reporter.reportAttribute(attr, path);\n }\n }\n }\n }\n });\n\n const hasTextProp = openingElement.attributes?.some(\n (attr) =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === 'text',\n );\n const hasChildren = path.node.children?.some(\n (child) =>\n (child.type === 'JSXText' && child.value.trim() !== '') ||\n child.type === 'JSXElement' ||\n child.type === 'JSXExpressionContainer',\n );\n\n if (hasTextProp && hasChildren) {\n reporter.reportPropWithChildren(path, 'text');\n }\n\n (path.node.children || []).forEach((child) => {\n if (child.type === 'JSXExpressionContainer') {\n const expr = child.expression;\n if (\n expr.type === 'ConditionalExpression' ||\n expr.type === 'CallExpression' ||\n expr.type === 'Identifier' ||\n expr.type === 'MemberExpression'\n ) {\n reporter.reportAmbiguousChildren(path, 'icon');\n }\n }\n });\n });\n\n removeActionButtonImport();\n }\n\n if (hasButtonImport) {\n root.findJSXElements('Button').forEach((path) => {\n const { openingElement } = path.node;\n\n if (hasAttributeOnElement(openingElement, 'v2')) return;\n\n addAttributesIfMissing(j, openingElement, [\n { attribute: j.jsxAttribute(j.jsxIdentifier('v2')), name: 'v2' },\n ]);\n processIconChildren(j, path.node.children, iconImports, openingElement);\n\n const legacyProps: LegacyProps = {};\n const legacyPropNames = ['priority', 'size', 'type', 'htmlType', 'sentiment'];\n\n openingElement.attributes?.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.name && attr.name.type === 'JSXIdentifier') {\n const { name } = attr.name;\n if (legacyPropNames.includes(name)) {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n legacyProps[name] = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n legacyProps[name] = convertEnumValue(String(j(attr.value.expression).toSource()));\n }\n } else {\n legacyProps[name] = undefined;\n }\n }\n }\n });\n\n if (openingElement.attributes) {\n openingElement.attributes = openingElement.attributes.filter(\n (attr) =>\n !(\n attr.type === 'JSXAttribute' &&\n attr.name &&\n legacyPropNames.includes((attr.name as JSXIdentifier).name)\n ),\n );\n }\n\n if ('size' in legacyProps) {\n const rawValue = legacyProps.size;\n const resolved = resolveSize(rawValue);\n const supportedSizes = ['xs', 'sm', 'md', 'lg', 'xl'];\n\n if (\n typeof rawValue === 'string' &&\n typeof resolved === 'string' &&\n supportedSizes.includes(resolved)\n ) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('size'), j.literal(resolved)),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'size', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'size');\n }\n }\n\n if ('priority' in legacyProps) {\n const rawValue = legacyProps.priority;\n const converted = convertEnumValue(rawValue);\n const mapped = resolvePriority(legacyProps.type, converted);\n const supportedPriorities = ['primary', 'secondary', 'tertiary', 'secondary-neutral'];\n\n if (\n typeof rawValue === 'string' &&\n typeof mapped === 'string' &&\n supportedPriorities.includes(mapped)\n ) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('priority'), j.literal(mapped)),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'priority', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'priority');\n }\n }\n\n if ('type' in legacyProps || 'htmlType' in legacyProps) {\n const rawType = legacyProps.type;\n const rawHtmlType = legacyProps.htmlType;\n\n const resolvedType =\n typeof rawType === 'string'\n ? rawType\n : rawType && typeof rawType === 'object'\n ? convertEnumValue(j(rawType).toSource())\n : undefined;\n\n const resolved = resolveType(resolvedType, rawHtmlType);\n\n const supportedTypes = [\n 'accent',\n 'negative',\n 'positive',\n 'primary',\n 'pay',\n 'secondary',\n 'danger',\n 'link',\n 'submit',\n 'button',\n 'reset',\n ];\n\n if (typeof resolved === 'string' && supportedTypes.includes(resolved)) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('type'), j.literal(resolved)),\n );\n\n if (resolved === 'negative') {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('sentiment'), j.literal('negative')),\n );\n }\n } else if (typeof rawType === 'string' || typeof rawHtmlType === 'string') {\n reporter.reportUnsupportedValue(path, 'type', rawType ?? rawHtmlType ?? '');\n } else if (rawType !== undefined || rawHtmlType !== undefined) {\n reporter.reportAmbiguousExpression(path, 'type');\n }\n }\n\n if ('sentiment' in legacyProps) {\n const rawValue = legacyProps.sentiment;\n if (rawValue === 'negative') {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('sentiment'), j.literal('negative')),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'sentiment', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'sentiment');\n }\n }\n\n let asIndex = -1;\n let asValue: string | null = null;\n let hrefExists = false;\n let asAmbiguous = false;\n let hrefAmbiguous = false;\n\n openingElement.attributes?.forEach((attr, index) => {\n if (attr.type === 'JSXAttribute' && attr.name) {\n if (attr.name.name === 'as') {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n asValue = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n asAmbiguous = true;\n reporter.reportAttribute(attr, path);\n }\n }\n asIndex = index;\n }\n\n if (attr.name.name === 'href') {\n hrefExists = true;\n if (attr.value && attr.value.type !== 'StringLiteral') {\n hrefAmbiguous = true;\n reporter.reportAttribute(attr, path);\n }\n }\n }\n });\n\n if (asValue && asValue !== 'a') {\n reporter.reportUnsupportedValue(path, 'as', asValue);\n }\n\n if (asValue === 'a') {\n if (asIndex !== -1) {\n openingElement.attributes = openingElement.attributes?.filter(\n (_, idx) => idx !== asIndex,\n );\n }\n if (!hrefExists) {\n openingElement.attributes = [\n ...(openingElement.attributes ?? []),\n j.jsxAttribute(j.jsxIdentifier('href'), j.literal('#')),\n ];\n }\n }\n\n if ((openingElement.attributes ?? []).some((attr) => attr.type === 'JSXSpreadAttribute')) {\n reporter.reportSpreadProps(path);\n }\n });\n }\n\n if (manualReviewIssues.length > 0) {\n manualReviewIssues.forEach(async (issue) => {\n await reportManualReview(file.path, issue);\n });\n }\n\n return root.toSource();\n};\n\nexport default transformer;\n"],"mappings":";;;;;;;;AAMA,SAAS,UACP,MACA,aACA,YACA,GACyC;CACzC,MAAM,qBAAqB,KAAK,KAAK,EAAE,mBAAmB,EACxD,QAAQ,EAAE,OAAO,aAAa,EAC/B;AAED,KAAI,mBAAmB,WAAW,EAChC,QAAO;EACL,QAAQ;EACR,cAAc,CAAE;EACjB;CAGH,MAAM,cAAc,mBAAmB,KAAK,EAAE,iBAAiB,EAC7D,UAAU,EAAE,MAAM,YAAY,EAC/B;CAED,MAAM,gBAAgB,mBAAmB,KAAK,EAAE,wBAAwB,EACtE,OAAO,EAAE,MAAM,YAAY,EAC5B;CAED,MAAM,SAAS,YAAY,SAAS,KAAK,cAAc,SAAS;CAEhE,MAAM,eAAe;AACnB,qBAAmB,SAAS,SAAS;GACnC,MAAM,qBACJ,KAAK,KAAK,YAAY,QAAQ,cAAc;AAC1C,QAAI,UAAU,SAAS,qBAAqB,UAAU,SAAS,SAAS,WACtE,QAAO;AAET,QAAI,UAAU,SAAS,4BAA4B,UAAU,OAAO,SAAS,WAC3E,QAAO;AAET,WAAO;GACR,MAAK,EAAE;AAEV,OAAI,mBAAmB,WAAW,EAChC,MAAK;OAEL,GAAE,MAAM,YACN,EAAE,kBAAkB,oBAAoB,KAAK,KAAK,QAAQ,KAAK,KAAK;EAGzE;CACF;AAED,QAAO;EAAE;EAAQ;EAAQ;AAC1B;;;;;;;;ACnDD,MAAM,uBACJ,GACA,UACA,aACA,mBACG;AACH,KAAI,CAAC,YAAY,CAAC,eAAe,WAAY;CAE7C,MAAM,oBAAoB,SAAwC;AAChE,MACE,OAAO,SAAS,YA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;YAEhD,OAAO,aAAa,SAC7B,UAAS,uBAAuB,MAAM,aAAa;YAC1C,aAAa,OACtB,UAAS,0BAA0B,MAAM;EAE5C;EAED,IAAI,UAAU;EACd,IAAIC,UAAyB;EAC7B,IAAI,aAAa;AAIjB,iBAAe,YAAY,SAAS,MAAM,UAAU;AAClD,OAAI,KAAK,SAAS,kBAAkB,KAAK,MAAM;AAC7C,QAAI,KAAK,KAAK,SAAS,MAAM;AAC3B,SAAI,KAAK,OACP;UAAI,KAAK,MAAM,SAAS,gBACtB,WAAU,KAAK,MAAM;eACZ,KAAK,MAAM,SAAS,yBAE7B,UAAS,gBAAgB,MAAM;KAChC;AAEH,eAAU;IACX;AAED,QAAI,KAAK,KAAK,SAAS,QAAQ;AAC7B,kBAAa;AACb,SAAI,KAAK,SAAS,KAAK,MAAM,SAAS,gBAEpC,UAAS,gBAAgB,MAAM;IAElC;GACF;EACF;AAED,MAAI,WAAW,YAAY,IACzB,UAAS,uBAAuB,MAAM,MAAM;AAG9C,MAAI,YAAY,KAAK;AACnB,OAAI,YAAY,GACd,gBAAe,aAAa,eAAe,YAAY,QACpD,GAAG,QAAQ,QAAQ;AAGxB,OAAI,CAAC,WACH,gBAAe,aAAa,CAC1B,GAAI,eAAe,cAAc,EAAE,EACnC,EAAE,aAAa,EAAE,cAAc,SAAS,EAAE,QAAQ,MACnD;EAEJ;AAED,OAAK,eAAe,cAAc,EAAE,EAAE,MAAM,SAAS,KAAK,SAAS,sBACjE,UAAS,kBAAkB;CAE9B;AAGH,KAAI,mBAAmB,SAAS,EAC9B,oBAAmB,QAAQ,OAAO,UAAU;AAC1C,QAAMC,8CAAmB,KAAK,MAAM;CACrC;AAGH,QAAO,KAAK;AACb"}
|
|
1
|
+
{"version":3,"file":"button.js","names":["priorityMapping: Record<string, Record<string, string>>","sizeMap: Record<string, string>","enumMapping: Record<string, string>","j: JSCodeshift","manualReviewIssues: string[]","hasImport","legacyProps: LegacyProps","asValue: string | null","reportManualReview"],"sources":["../../src/transforms/helpers/hasImport.ts","../../src/transforms/helpers/iconUtils.ts","../../src/transforms/helpers/jsxElementUtils.ts","../../src/transforms/helpers/jsxReportingUtils.ts","../../src/transforms/button/transformer.ts"],"sourcesContent":["import type { Collection, JSCodeshift } from 'jscodeshift';\n\n/**\n * Checks if a specific import exists in the given root collection and provides\n * a method to remove it if found.\n */\nfunction hasImport(\n root: Collection,\n sourceValue: string,\n importName: string,\n j: JSCodeshift,\n): { exists: boolean; remove: () => void } {\n const importDeclarations = root.find(j.ImportDeclaration, {\n source: { value: sourceValue },\n });\n\n if (importDeclarations.size() === 0) {\n return {\n exists: false,\n remove: () => {},\n };\n }\n\n const namedImport = importDeclarations.find(j.ImportSpecifier, {\n imported: { name: importName },\n });\n\n const defaultImport = importDeclarations.find(j.ImportDefaultSpecifier, {\n local: { name: importName },\n });\n\n const exists = namedImport.size() > 0 || defaultImport.size() > 0;\n\n const remove = () => {\n importDeclarations.forEach((path) => {\n const filteredSpecifiers =\n path.node.specifiers?.filter((specifier) => {\n if (specifier.type === 'ImportSpecifier' && specifier.imported.name === importName) {\n return false;\n }\n if (specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name === importName) {\n return false;\n }\n return true;\n }) ?? [];\n\n if (filteredSpecifiers.length === 0) {\n path.prune();\n } else {\n j(path).replaceWith(\n j.importDeclaration(filteredSpecifiers, path.node.source, path.node.importKind),\n );\n }\n });\n };\n\n return { exists, remove };\n}\n\nexport default hasImport;\n","import type { JSCodeshift, JSXElement, JSXExpressionContainer } from 'jscodeshift';\n\n/**\n * Process children of a JSX element to detect icon components and add iconStart or iconEnd attributes accordingly.\n * This is specific to icon handling but can be reused in codemods dealing with icon children.\n */\nconst processIconChildren = (\n j: JSCodeshift,\n children: (JSXElement | JSXExpressionContainer | unknown)[] | undefined,\n iconImports: Set<string>,\n openingElement: JSXElement['openingElement'],\n) => {\n if (!children || !openingElement.attributes) return;\n\n const unwrapJsxElement = (node: unknown): JSXElement | unknown => {\n if (\n typeof node === 'object' &&\n node !== null &&\n 'type' in node &&\n node.type === 'JSXExpressionContainer' &&\n j.JSXElement.check((node as JSXExpressionContainer).expression)\n ) {\n return (node as JSXExpressionContainer).expression;\n }\n return node;\n };\n\n const totalChildren = children.length;\n\n // Find index of icon child\n const iconChildIndex = children.findIndex((child) => {\n const unwrapped = unwrapJsxElement(child);\n return (\n j.JSXElement.check(unwrapped) &&\n unwrapped.openingElement.name.type === 'JSXIdentifier' &&\n iconImports.has(unwrapped.openingElement.name.name)\n );\n });\n\n if (iconChildIndex === -1) return;\n\n const iconChild = unwrapJsxElement(children[iconChildIndex]) as JSXElement;\n\n if (!iconChild || iconChild.openingElement.name.type !== 'JSXIdentifier') return;\n\n const iconName = iconChild.openingElement.name.name;\n\n // Determine if icon is closer to start or end\n const distanceToStart = iconChildIndex;\n const distanceToEnd = totalChildren - 1 - iconChildIndex;\n const iconPropName = distanceToStart <= distanceToEnd ? 'addonStart' : 'addonEnd';\n\n // Build: { type: 'icon', value: <IconName /> }\n const iconObject = j.objectExpression([\n j.property('init', j.identifier('type'), j.literal('icon')),\n j.property('init', j.identifier('value'), iconChild),\n ]);\n const iconProp = j.jsxAttribute(\n j.jsxIdentifier(iconPropName),\n j.jsxExpressionContainer(iconObject),\n );\n\n openingElement.attributes.push(iconProp);\n\n // Remove the icon child\n children.splice(iconChildIndex, 1);\n\n // Helper to check if a child is whitespace-only JSXText\n const isWhitespaceJsxText = (node: unknown): boolean => {\n return (\n typeof node === 'object' &&\n node !== null &&\n (node as { type?: unknown }).type === 'JSXText' &&\n typeof (node as { value?: string }).value === 'string' &&\n (node as { value?: string }).value!.trim() === ''\n );\n };\n\n // Remove adjacent whitespace-only JSXText node if any\n if (iconChildIndex - 1 >= 0 && isWhitespaceJsxText(children[iconChildIndex - 1])) {\n children.splice(iconChildIndex - 1, 1);\n } else if (isWhitespaceJsxText(children[iconChildIndex])) {\n children.splice(iconChildIndex, 1);\n }\n};\n\nexport default processIconChildren;\n","import type {\n JSCodeshift,\n JSXAttribute,\n JSXElement,\n JSXIdentifier,\n JSXMemberExpression,\n JSXNamespacedName,\n JSXSpreadAttribute,\n} from 'jscodeshift';\n\n/**\n * Rename a JSX element name if it is a JSXIdentifier.\n */\nexport const setNameIfJSXIdentifier = (\n elementName: JSXIdentifier | JSXNamespacedName | JSXMemberExpression | undefined,\n newName: string,\n): JSXIdentifier | JSXNamespacedName | JSXMemberExpression | undefined => {\n if (elementName && elementName.type === 'JSXIdentifier') {\n return { ...elementName, name: newName };\n }\n return elementName;\n};\n\n/**\n * Check if a list of attributes contains a specific attribute by name.\n */\nexport const hasAttribute = (\n attributes: (JSXAttribute | JSXSpreadAttribute)[] | undefined,\n attributeName: string,\n): boolean => {\n return (\n Array.isArray(attributes) &&\n attributes.some(\n (attr): attr is JSXAttribute =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === attributeName,\n )\n );\n};\n\n/**\n * Check if a JSX element's openingElement has a specific attribute.\n */\nexport const hasAttributeOnElement = (\n element: JSXElement['openingElement'],\n attributeName: string,\n): boolean => {\n return hasAttribute(element.attributes, attributeName);\n};\n\n/**\n * Add specified attributes to a JSX element's openingElement if they are not already present.\n */\nexport const addAttributesIfMissing = (\n j: JSCodeshift,\n openingElement: JSXElement['openingElement'],\n attributesToAdd: { attribute: JSXAttribute; name: string }[],\n) => {\n if (!Array.isArray(openingElement.attributes)) return;\n const attrs = openingElement.attributes;\n attributesToAdd.forEach(({ attribute, name }) => {\n if (!hasAttributeOnElement(openingElement, name)) {\n attrs.push(attribute);\n }\n });\n};\n","import type { ASTPath, JSCodeshift, JSXAttribute, JSXElement, Node } from 'jscodeshift';\n\nexport interface ReporterOptions {\n jscodeshift: JSCodeshift;\n issues: string[];\n}\n\n/**\n * CodemodReporter is a utility class for reporting issues found during codemod transformations.\n * It provides methods to report issues related to JSX elements, props, and attributes.\n *\n * @example\n * ```typescript\n * const issues: string[] = [];\n * const reporter = createReporter(j, issues);\n *\n * // Report a deprecated prop\n * reporter.reportDeprecatedProp(buttonElement, 'flat', 'variant=\"text\"');\n *\n * // Report complex expression that needs review\n * reporter.reportAmbiguousExpression(element, 'size');\n *\n * // Auto-detect common issues\n * reporter.reportAttributeIssues(element);\n * ```\n */\nexport class CodemodReporter {\n private readonly j: JSCodeshift;\n private readonly issues: string[];\n\n constructor(options: ReporterOptions) {\n this.j = options.jscodeshift;\n this.issues = options.issues;\n }\n\n /**\n * Reports an issue with a JSX element\n */\n reportElement(element: JSXElement | ASTPath<JSXElement>, reason: string): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const line = this.getLineNumber(node);\n\n this.addIssue(`Manual review required: <${componentName}> at line ${line} ${reason}.`);\n }\n\n /**\n * Reports an issue with a specific prop\n */\n reportProp(element: JSXElement | ASTPath<JSXElement>, propName: string, reason: string): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const line = this.getLineNumber(node);\n\n this.addIssue(\n `Manual review required: prop \"${propName}\" on <${componentName}> at line ${line} ${reason}.`,\n );\n }\n\n /**\n * Reports an issue with a JSX attribute directly\n */\n reportAttribute(\n attr: JSXAttribute,\n element: JSXElement | ASTPath<JSXElement>,\n reason?: string,\n ): void {\n const node = this.getNode(element);\n const componentName = this.getComponentName(node);\n const propName = this.getAttributeName(attr);\n const line = this.getLineNumber(attr) || this.getLineNumber(node);\n\n const defaultReason = this.getAttributeReason(attr);\n const finalReason = reason || defaultReason;\n\n this.addIssue(\n `Manual review required: prop \"${propName}\" on <${componentName}> at line ${line} ${finalReason}.`,\n );\n }\n\n /**\n * Reports spread props on an element\n */\n reportSpreadProps(element: JSXElement | ASTPath<JSXElement>): void {\n this.reportElement(element, 'contains spread props that need manual review');\n }\n\n /**\n * Reports conflicting prop and children\n */\n reportPropWithChildren(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(\n element,\n propName,\n `conflicts with children - both \"${propName}\" prop and children are present`,\n );\n }\n\n /**\n * Reports unsupported prop value\n */\n reportUnsupportedValue(\n element: JSXElement | ASTPath<JSXElement>,\n propName: string,\n value: string,\n ): void {\n this.reportProp(element, propName, `has unsupported value \"${value}\"`);\n }\n\n /**\n * Reports ambiguous expression in prop\n */\n reportAmbiguousExpression(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(element, propName, 'contains a complex expression that needs manual review');\n }\n\n /**\n * Reports ambiguous children (like dynamic icons)\n */\n reportAmbiguousChildren(element: JSXElement | ASTPath<JSXElement>, childType = 'content'): void {\n this.reportElement(element, `contains ambiguous ${childType} that needs manual review`);\n }\n\n /**\n * Reports deprecated prop usage\n */\n reportDeprecatedProp(\n element: JSXElement | ASTPath<JSXElement>,\n propName: string,\n alternative?: string,\n ): void {\n const suggestion = alternative ? ` Use ${alternative} instead` : '';\n this.reportProp(element, propName, `is deprecated${suggestion}`);\n }\n\n /**\n * Reports missing required prop\n */\n reportMissingRequiredProp(element: JSXElement | ASTPath<JSXElement>, propName: string): void {\n this.reportProp(element, propName, 'is required but missing');\n }\n\n /**\n * Reports conflicting props\n */\n reportConflictingProps(element: JSXElement | ASTPath<JSXElement>, propNames: string[]): void {\n const propList = propNames.map((name) => `\"${name}\"`).join(', ');\n this.reportElement(element, `has conflicting props: ${propList} cannot be used together`);\n }\n\n /**\n * Auto-detects and reports common attribute issues\n */\n reportAttributeIssues(element: JSXElement | ASTPath<JSXElement>): void {\n const node = this.getNode(element);\n const { attributes } = node.openingElement;\n\n if (!attributes) return;\n\n // Check for spread props\n if (attributes.some((attr) => attr.type === 'JSXSpreadAttribute')) {\n this.reportSpreadProps(element);\n }\n\n // Check for complex expressions in attributes\n attributes.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.value?.type === 'JSXExpressionContainer') {\n this.reportAttribute(attr, element);\n }\n });\n }\n\n // Private helper methods\n private getNode(element: JSXElement | ASTPath<JSXElement>): JSXElement {\n return 'node' in element ? element.node : element;\n }\n\n private getComponentName(node: JSXElement): string {\n const { name } = node.openingElement;\n if (name.type === 'JSXIdentifier') {\n return name.name;\n }\n // Handle JSXMemberExpression, JSXNamespacedName, etc.\n return this.j(name).toSource();\n }\n\n private getLineNumber(node: JSXElement | JSXAttribute | Node): string {\n return node.loc?.start.line?.toString() || 'unknown';\n }\n\n private getAttributeName(attr: JSXAttribute): string {\n if (attr.name.type === 'JSXIdentifier') {\n return attr.name.name;\n }\n return this.j(attr.name).toSource();\n }\n\n private getAttributeReason(attr: JSXAttribute): string {\n if (!attr.value) return 'has no value';\n\n if (attr.value.type === 'JSXExpressionContainer') {\n const expr = attr.value.expression;\n const expressionType = expr.type.replace('Expression', '').toLowerCase();\n\n // Show actual value for simple cases\n if (expr.type === 'Identifier' || expr.type === 'MemberExpression') {\n const valueText = this.j(expr).toSource();\n return `contains a ${expressionType} (${valueText})`;\n }\n\n return `contains a complex ${expressionType} expression`;\n }\n\n return 'needs manual review';\n }\n\n private addIssue(message: string): void {\n this.issues.push(message);\n }\n}\n\nexport const createReporter = (j: JSCodeshift, issues: string[]): CodemodReporter => {\n return new CodemodReporter({ jscodeshift: j, issues });\n};\n","import type { API, FileInfo, JSCodeshift, JSXIdentifier, Options } from 'jscodeshift';\n\nimport reportManualReview from '../../utils/reportManualReview';\nimport hasImport from '../helpers/hasImport';\nimport processIconChildren from '../helpers/iconUtils';\nimport {\n addAttributesIfMissing,\n hasAttributeOnElement,\n setNameIfJSXIdentifier,\n} from '../helpers/jsxElementUtils';\nimport { createReporter } from '../helpers/jsxReportingUtils';\n\nexport const parser = 'tsx';\n\ninterface LegacyProps {\n priority?: string;\n size?: string;\n type?: string;\n htmlType?: string;\n sentiment?: string;\n [key: string]: unknown;\n}\n\nconst priorityMapping: Record<string, Record<string, string>> = {\n accent: {\n primary: 'primary',\n secondary: 'secondary-neutral',\n tertiary: 'tertiary',\n },\n positive: {\n primary: 'primary',\n secondary: 'secondary-neutral',\n tertiary: 'secondary-neutral',\n },\n negative: {\n primary: 'primary',\n secondary: 'secondary',\n tertiary: 'secondary',\n },\n};\n\nconst sizeMap: Record<string, string> = {\n EXTRA_SMALL: 'xs',\n SMALL: 'sm',\n MEDIUM: 'md',\n LARGE: 'lg',\n EXTRA_LARGE: 'xl',\n xs: 'sm',\n sm: 'sm',\n md: 'md',\n lg: 'lg',\n xl: 'xl',\n};\n\nconst resolveSize = (size?: string): string | undefined => {\n if (!size) return size;\n const match = /^Size\\.(EXTRA_SMALL|SMALL|MEDIUM|LARGE|EXTRA_LARGE)$/u.exec(size);\n if (match) {\n return sizeMap[match[1]];\n }\n return sizeMap[size] || size;\n};\n\nconst resolvePriority = (type?: string, priority?: string): string | undefined => {\n if (type && priority) {\n return priorityMapping[type]?.[priority] || priority;\n }\n return priority;\n};\n\nconst resolveType = (type?: string, htmlType?: string): string | null => {\n if (htmlType) {\n return htmlType;\n }\n\n const legacyButtonTypes = [\n 'accent',\n 'negative',\n 'positive',\n 'primary',\n 'pay',\n 'secondary',\n 'danger',\n 'link',\n ];\n return type && legacyButtonTypes.includes(type) ? type : null;\n};\n\nconst convertEnumValue = (value?: string): string | undefined => {\n if (!value) return value;\n const strippedValue = value.replace(/^['\"]|['\"]$/gu, '');\n const enumMapping: Record<string, string> = {\n 'Priority.SECONDARY': 'secondary',\n 'Priority.PRIMARY': 'primary',\n 'Priority.TERTIARY': 'tertiary',\n 'ControlType.NEGATIVE': 'negative',\n 'ControlType.POSITIVE': 'positive',\n 'ControlType.ACCENT': 'accent',\n };\n return enumMapping[strippedValue] || strippedValue;\n};\n\n/**\n * This transform function modifies the Button and ActionButton components from the @transferwise/components library.\n * It updates the ActionButton component to use the Button component with specific attributes and mappings.\n * It also processes icon children and removes legacy props.\n *\n * @param {FileInfo} file - The file information object.\n * @param {API} api - The API object for jscodeshift.\n * @param {Options} options - The options object for jscodeshift.\n * @returns {string} - The transformed source code.\n */\nconst transformer = (file: FileInfo, api: API, options: Options) => {\n const j: JSCodeshift = api.jscodeshift;\n const root = j(file.source);\n const manualReviewIssues: string[] = [];\n\n // Create reporter instance\n const reporter = createReporter(j, manualReviewIssues);\n\n const { exists: hasButtonImport } = hasImport(root, '@transferwise/components', 'Button', j);\n const { exists: hasActionButtonImport, remove: removeActionButtonImport } = hasImport(\n root,\n '@transferwise/components',\n 'ActionButton',\n j,\n );\n\n const iconImports = new Set<string>();\n root.find(j.ImportDeclaration, { source: { value: '@transferwise/icons' } }).forEach((path) => {\n path.node.specifiers?.forEach((specifier) => {\n if (\n (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') &&\n specifier.local\n ) {\n const localName = (specifier.local as { name: string }).name;\n iconImports.add(localName);\n }\n });\n });\n\n if (hasActionButtonImport) {\n root.findJSXElements('ActionButton').forEach((path) => {\n const { openingElement, closingElement } = path.node;\n\n openingElement.name = setNameIfJSXIdentifier(openingElement.name, 'Button')!;\n if (closingElement) {\n closingElement.name = setNameIfJSXIdentifier(closingElement.name, 'Button')!;\n }\n\n addAttributesIfMissing(j, openingElement, [\n { attribute: j.jsxAttribute(j.jsxIdentifier('v2')), name: 'v2' },\n { attribute: j.jsxAttribute(j.jsxIdentifier('size'), j.literal('sm')), name: 'size' },\n ]);\n\n processIconChildren(j, path.node.children, iconImports, openingElement);\n\n if ((openingElement.attributes ?? []).some((attr) => attr.type === 'JSXSpreadAttribute')) {\n reporter.reportSpreadProps(path);\n }\n\n const legacyPropNames = ['priority', 'text'];\n const legacyProps: LegacyProps = {};\n\n openingElement.attributes?.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.name && attr.name.type === 'JSXIdentifier') {\n const { name } = attr.name;\n if (legacyPropNames.includes(name)) {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n legacyProps[name] = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n reporter.reportAttribute(attr, path);\n }\n }\n }\n }\n });\n\n const hasTextProp = openingElement.attributes?.some(\n (attr) =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === 'text',\n );\n const hasChildren = path.node.children?.some(\n (child) =>\n (child.type === 'JSXText' && child.value.trim() !== '') ||\n child.type === 'JSXElement' ||\n child.type === 'JSXExpressionContainer',\n );\n\n if (hasTextProp && hasChildren) {\n reporter.reportPropWithChildren(path, 'text');\n }\n\n (path.node.children || []).forEach((child) => {\n if (child.type === 'JSXExpressionContainer') {\n const expr = child.expression;\n if (\n expr.type === 'ConditionalExpression' ||\n expr.type === 'CallExpression' ||\n expr.type === 'Identifier' ||\n expr.type === 'MemberExpression'\n ) {\n reporter.reportAmbiguousChildren(path, 'icon');\n }\n }\n });\n });\n\n removeActionButtonImport();\n }\n\n if (hasButtonImport) {\n root.findJSXElements('Button').forEach((path) => {\n const { openingElement } = path.node;\n\n if (hasAttributeOnElement(openingElement, 'v2')) return;\n\n addAttributesIfMissing(j, openingElement, [\n { attribute: j.jsxAttribute(j.jsxIdentifier('v2')), name: 'v2' },\n ]);\n processIconChildren(j, path.node.children, iconImports, openingElement);\n\n const legacyProps: LegacyProps = {};\n const legacyPropNames = ['priority', 'size', 'type', 'htmlType', 'sentiment'];\n\n openingElement.attributes?.forEach((attr) => {\n if (attr.type === 'JSXAttribute' && attr.name && attr.name.type === 'JSXIdentifier') {\n const { name } = attr.name;\n if (legacyPropNames.includes(name)) {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n legacyProps[name] = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n legacyProps[name] = convertEnumValue(String(j(attr.value.expression).toSource()));\n }\n } else {\n legacyProps[name] = undefined;\n }\n }\n }\n });\n\n if (openingElement.attributes) {\n openingElement.attributes = openingElement.attributes.filter(\n (attr) =>\n !(\n attr.type === 'JSXAttribute' &&\n attr.name &&\n legacyPropNames.includes((attr.name as JSXIdentifier).name)\n ),\n );\n }\n\n if ('size' in legacyProps) {\n const rawValue = legacyProps.size;\n const resolved = resolveSize(rawValue);\n const supportedSizes = ['xs', 'sm', 'md', 'lg', 'xl'];\n\n if (\n typeof rawValue === 'string' &&\n typeof resolved === 'string' &&\n supportedSizes.includes(resolved)\n ) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('size'), j.literal(resolved)),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'size', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'size');\n }\n }\n\n if ('priority' in legacyProps) {\n const rawValue = legacyProps.priority;\n const converted = convertEnumValue(rawValue);\n const mapped = resolvePriority(legacyProps.type, converted);\n const supportedPriorities = ['primary', 'secondary', 'tertiary', 'secondary-neutral'];\n\n if (\n typeof rawValue === 'string' &&\n typeof mapped === 'string' &&\n supportedPriorities.includes(mapped)\n ) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('priority'), j.literal(mapped)),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'priority', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'priority');\n }\n }\n\n if ('type' in legacyProps || 'htmlType' in legacyProps) {\n const rawType = legacyProps.type;\n const rawHtmlType = legacyProps.htmlType;\n\n const resolvedType =\n typeof rawType === 'string'\n ? rawType\n : rawType && typeof rawType === 'object'\n ? convertEnumValue(j(rawType).toSource())\n : undefined;\n\n const resolved = resolveType(resolvedType, rawHtmlType);\n\n const supportedTypes = [\n 'accent',\n 'negative',\n 'positive',\n 'primary',\n 'pay',\n 'secondary',\n 'danger',\n 'link',\n 'submit',\n 'button',\n 'reset',\n ];\n\n if (typeof resolved === 'string' && supportedTypes.includes(resolved)) {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('type'), j.literal(resolved)),\n );\n\n if (resolved === 'negative') {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('sentiment'), j.literal('negative')),\n );\n }\n } else if (typeof rawType === 'string' || typeof rawHtmlType === 'string') {\n reporter.reportUnsupportedValue(path, 'type', rawType ?? rawHtmlType ?? '');\n } else if (rawType !== undefined || rawHtmlType !== undefined) {\n reporter.reportAmbiguousExpression(path, 'type');\n }\n }\n\n if ('sentiment' in legacyProps) {\n const rawValue = legacyProps.sentiment;\n if (rawValue === 'negative') {\n openingElement.attributes?.push(\n j.jsxAttribute(j.jsxIdentifier('sentiment'), j.literal('negative')),\n );\n } else if (typeof rawValue === 'string') {\n reporter.reportUnsupportedValue(path, 'sentiment', rawValue);\n } else if (rawValue !== undefined) {\n reporter.reportAmbiguousExpression(path, 'sentiment');\n }\n }\n\n let asIndex = -1;\n let asValue: string | null = null;\n let hrefExists = false;\n let asAmbiguous = false;\n let hrefAmbiguous = false;\n\n openingElement.attributes?.forEach((attr, index) => {\n if (attr.type === 'JSXAttribute' && attr.name) {\n if (attr.name.name === 'as') {\n if (attr.value) {\n if (attr.value.type === 'StringLiteral') {\n asValue = attr.value.value;\n } else if (attr.value.type === 'JSXExpressionContainer') {\n asAmbiguous = true;\n reporter.reportAttribute(attr, path);\n }\n }\n asIndex = index;\n }\n\n if (attr.name.name === 'href') {\n hrefExists = true;\n if (attr.value && attr.value.type !== 'StringLiteral') {\n hrefAmbiguous = true;\n reporter.reportAttribute(attr, path);\n }\n }\n }\n });\n\n if (asValue && asValue !== 'a') {\n reporter.reportUnsupportedValue(path, 'as', asValue);\n }\n\n if (asValue === 'a') {\n if (asIndex !== -1) {\n openingElement.attributes = openingElement.attributes?.filter(\n (_, idx) => idx !== asIndex,\n );\n }\n if (!hrefExists) {\n openingElement.attributes = [\n ...(openingElement.attributes ?? []),\n j.jsxAttribute(j.jsxIdentifier('href'), j.literal('#')),\n ];\n }\n }\n\n if ((openingElement.attributes ?? []).some((attr) => attr.type === 'JSXSpreadAttribute')) {\n reporter.reportSpreadProps(path);\n }\n });\n }\n\n if (manualReviewIssues.length > 0) {\n manualReviewIssues.forEach(async (issue) => {\n await reportManualReview(file.path, issue);\n });\n }\n\n return root.toSource();\n};\n\nexport default transformer;\n"],"mappings":";;;;;;;;AAMA,SAAS,UACP,MACA,aACA,YACA,GACyC;CACzC,MAAM,q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AAe,aAAa,CAC1B,GAAI,eAAe,cAAc,IACjC,EAAE,aAAa,EAAE,cAAc,SAAS,EAAE,QAAQ;;AAKxD,OAAK,eAAe,cAAc,IAAI,MAAM,SAAS,KAAK,SAAS,sBACjE,UAAS,kBAAkB;;AAKjC,KAAI,mBAAmB,SAAS,EAC9B,oBAAmB,QAAQ,OAAO,UAAU;AAC1C,QAAMC,sDAAmB,KAAK,MAAM;;AAIxC,QAAO,KAAK;;AAGd,0BAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/wds-codemods",
|
|
3
|
-
"version": "0.0.1-experimental-
|
|
3
|
+
"version": "0.0.1-experimental-c483d40",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Wise Payments Ltd.",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test:watch": "jest --watch"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@inquirer/prompts": "^7.8.
|
|
37
|
+
"@inquirer/prompts": "^7.8.4",
|
|
38
38
|
"jscodeshift": "^17.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|