@wise/wds-codemods 0.0.1-experimental-70cf678 → 0.0.1-experimental-cd881b3

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 CHANGED
@@ -1,71 +1,161 @@
1
1
  #!/usr/bin/env node
2
2
  const require_reportManualReview = require('./reportManualReview-CQm-npxR.js');
3
- const node_fs_promises = require_reportManualReview.__toESM(require("node:fs/promises"));
4
3
  const node_child_process = require_reportManualReview.__toESM(require("node:child_process"));
4
+ const node_fs_promises = require_reportManualReview.__toESM(require("node:fs/promises"));
5
5
  const node_path = require_reportManualReview.__toESM(require("node:path"));
6
6
  const node_url = require_reportManualReview.__toESM(require("node:url"));
7
- const __inquirer_prompts = require_reportManualReview.__toESM(require("@inquirer/prompts"));
8
7
  const node_fs = require_reportManualReview.__toESM(require("node:fs"));
8
+ const __inquirer_prompts = require_reportManualReview.__toESM(require("@inquirer/prompts"));
9
9
  require("jscodeshift/src/testUtils");
10
10
 
11
11
  //#region src/utils/getOptions.ts
12
- async function getOptions(transformFiles) {
13
- const args = process.argv.slice(2);
14
- if (args.length > 0) {
15
- const [transformFile$1, targetPath$1] = args;
16
- const dry$1 = args.includes("--dry") || args.includes("--dry-run");
17
- const print$1 = args.includes("--print");
18
- const ignorePatternIndex = args.findIndex((arg) => arg === "--ignore-pattern");
19
- let ignorePattern$1;
20
- if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) ignorePattern$1 = args[ignorePatternIndex + 1];
21
- const gitignore$1 = args.includes("--gitignore");
22
- const noGitignore = args.includes("--no-gitignore");
23
- if (!transformFile$1 || !transformFiles.includes(transformFile$1)) throw new Error("Invalid transform file specified.");
24
- if (!targetPath$1) throw new Error("Target path cannot be empty.");
25
- const useGitignore = !!(gitignore$1 || !gitignore$1 && !noGitignore);
26
- return {
27
- transformFile: transformFile$1,
28
- targetPath: targetPath$1,
29
- dry: dry$1,
30
- print: print$1,
31
- ignorePattern: ignorePattern$1,
32
- gitignore: useGitignore
33
- };
12
+ /**
13
+ * if args are provided via CLI, log them to the console in
14
+ * a formatted way matching Inquirer's style
15
+ */
16
+ const logToInquirer = (label, value) => {
17
+ const checkmark = "\x1B[32m✔\x1B[0m";
18
+ const boldLabel = `\x1b[1m${label}\x1b[0m`;
19
+ const greenValue = `\x1b[32m${value}\x1b[0m`;
20
+ console.info(`${checkmark} ${boldLabel} ${greenValue}`);
21
+ };
22
+ /**
23
+ * Lets user pick from available packages to run the codemod on
24
+ */
25
+ const queryPackages = async (packages) => {
26
+ const message = "Path to run codemod on:";
27
+ const nonRootPackages = packages.filter((pkg$1) => pkg$1 !== ".");
28
+ if (packages.length === 1 && nonRootPackages.length === 0) {
29
+ logToInquirer(message, packages[0]);
30
+ return packages;
34
31
  }
35
- const transformFile = await (0, __inquirer_prompts.select)({
36
- message: "Select a codemod transform to run:",
32
+ if (nonRootPackages.length >= 1) return (0, __inquirer_prompts.checkbox)({
33
+ required: true,
34
+ message: "Select packages to transform:",
35
+ choices: nonRootPackages.map((file) => ({
36
+ name: file,
37
+ value: file,
38
+ checked: true
39
+ }))
40
+ });
41
+ };
42
+ /**
43
+ * Determine user choice between CLI arg and Inquirer prompt: codemod
44
+ */
45
+ const determineTransformer = async ({ candidate, transformFiles }) => {
46
+ const codemodMessage = "Select codemod to run:";
47
+ if (candidate && transformFiles.includes(candidate)) {
48
+ logToInquirer(codemodMessage, candidate);
49
+ return candidate;
50
+ }
51
+ return (0, __inquirer_prompts.select)({
52
+ message: codemodMessage,
37
53
  choices: transformFiles.map((file) => ({
38
54
  name: file,
39
55
  value: file
40
56
  }))
41
57
  });
42
- const targetPath = await (0, __inquirer_prompts.input)({
43
- message: "Enter the target directory or file path to run codemod on:",
44
- validate: (value) => value.trim() !== "" || "Target path cannot be empty"
45
- });
46
- const dry = await (0, __inquirer_prompts.confirm)({
47
- message: "Run in dry mode (no changes written to files)?",
48
- default: true
58
+ };
59
+ /**
60
+ * Determine user choice between CLI arg and Inquirer prompt: paths/packages to process
61
+ */
62
+ const determinePaths = async ({ candidate, root, packages }) => {
63
+ const targetPaths = [];
64
+ if (candidate && (0, node_fs.existsSync)((0, node_path.join)(root, candidate))) {
65
+ logToInquirer("Path to run codemod on", candidate);
66
+ targetPaths.push(candidate);
67
+ }
68
+ if (!targetPaths.length) {
69
+ const packagesToProcess = await queryPackages(packages);
70
+ targetPaths.push(...packagesToProcess ?? []);
71
+ }
72
+ return targetPaths;
73
+ };
74
+ /**
75
+ * Determine user choice between CLI arg and Inquirer prompt: dry mode
76
+ */
77
+ const determineIsDryMode = async (args) => {
78
+ const message = "Run in dry mode (no changes written to files)?";
79
+ if (args.includes("--dry") || args.includes("--dry-run")) {
80
+ logToInquirer(message, "Yes");
81
+ return true;
82
+ }
83
+ return (0, __inquirer_prompts.confirm)({
84
+ message,
85
+ default: false
49
86
  });
50
- const print = await (0, __inquirer_prompts.confirm)({
51
- message: "Print transformed source to console?",
87
+ };
88
+ /**
89
+ * Determine user choice between CLI arg and Inquirer prompt: print to CLI
90
+ */
91
+ const determineIsPrint = async (args) => {
92
+ const message = "Print transformed source to console?";
93
+ if (args.includes("--print")) {
94
+ logToInquirer(message, "Yes");
95
+ return true;
96
+ }
97
+ return (0, __inquirer_prompts.confirm)({
98
+ message,
52
99
  default: false
53
100
  });
54
- const ignorePattern = await (0, __inquirer_prompts.input)({
55
- message: "Enter ignore pattern(s) (comma separated) or leave empty:",
56
- validate: (value) => true
101
+ };
102
+ /**
103
+ * Determine user choice between CLI arg and Inquirer prompt: ignore patterns
104
+ */
105
+ const determineIgnorePatterns = async (args) => {
106
+ const message = "Enter ignore pattern(s) (comma separated) or leave empty:";
107
+ const ignorePatternIndex = args.findIndex((arg) => arg === "--ignore-pattern");
108
+ let ignorePattern;
109
+ if (ignorePatternIndex !== -1 && args.length > ignorePatternIndex + 1) ignorePattern = args[ignorePatternIndex + 1];
110
+ if (ignorePattern) {
111
+ logToInquirer(message, ignorePattern);
112
+ return ignorePattern;
113
+ }
114
+ return (0, __inquirer_prompts.input)({
115
+ message,
116
+ validate: () => true
57
117
  });
58
- const gitignore = await (0, __inquirer_prompts.confirm)({
59
- message: "Respect .gitignore files?",
118
+ };
119
+ /**
120
+ * Determine user choice between CLI arg and Inquirer prompt: gitignore
121
+ */
122
+ const determineGitIgnore = async (args) => {
123
+ const message = "Respect .gitignore files?";
124
+ if (args.includes("--gitignore")) {
125
+ logToInquirer(message, "Yes");
126
+ return true;
127
+ }
128
+ if (args.includes("--no-gitignore")) {
129
+ logToInquirer(message, "No");
130
+ return false;
131
+ }
132
+ return (0, __inquirer_prompts.confirm)({
133
+ message,
60
134
  default: true
61
135
  });
136
+ };
137
+ async function getOptions({ transformFiles, packages, root }) {
138
+ const args = process.argv.slice(2);
139
+ const transformFile = await determineTransformer({
140
+ candidate: args[0],
141
+ transformFiles
142
+ });
143
+ const targetPaths = await determinePaths({
144
+ candidate: args[1],
145
+ packages,
146
+ root
147
+ });
148
+ const isDry = await determineIsDryMode(args);
149
+ const isPrint = await determineIsPrint(args);
150
+ const ignorePatterns = await determineIgnorePatterns(args);
151
+ const useGitIgnore = await determineGitIgnore(args);
62
152
  return {
63
153
  transformFile,
64
- targetPath,
65
- dry,
66
- print,
67
- ignorePattern,
68
- gitignore
154
+ targetPaths,
155
+ isDry,
156
+ isPrint,
157
+ ignorePatterns,
158
+ useGitIgnore
69
159
  };
70
160
  }
71
161
  var getOptions_default = getOptions;
@@ -91,6 +181,52 @@ async function loadTransformModules(transformsDir) {
91
181
  }
92
182
  var loadTransformModules_default = loadTransformModules;
93
183
 
184
+ //#endregion
185
+ //#region src/utils/repository.ts
186
+ /**
187
+ * Finds the root of the project by looking for the `.git` directory.
188
+ */
189
+ function findProjectRoot() {
190
+ try {
191
+ const gitRoot = (0, node_child_process.execSync)("git rev-parse --show-toplevel", {
192
+ cwd: process.cwd(),
193
+ encoding: "utf8",
194
+ stdio: [
195
+ "ignore",
196
+ "pipe",
197
+ "ignore"
198
+ ]
199
+ }).trim();
200
+ return gitRoot && (0, node_fs.existsSync)(gitRoot) ? gitRoot : "";
201
+ } catch {
202
+ return "";
203
+ }
204
+ }
205
+ /**
206
+ * Quick and dirty way of determining package roots based on
207
+ * the presence of `package.json` files and them optimistically
208
+ * containing a `@transferwise/components` string.
209
+ * */
210
+ function findPackages() {
211
+ try {
212
+ const packages = (0, node_child_process.execSync)([
213
+ "find ./",
214
+ "-type f",
215
+ "-name \"package.json\"",
216
+ "-not -path \"*/node_modules/*\"",
217
+ "|",
218
+ "xargs grep -l \"@transferwise/components\""
219
+ ].join(" "), {
220
+ cwd: findProjectRoot(),
221
+ encoding: "utf8"
222
+ }).trim().split("\n").map(node_path.default.dirname);
223
+ if (packages.length === 0) throw new Error();
224
+ return packages;
225
+ } catch {
226
+ throw new Error("No suitable package roots found in the repository.");
227
+ }
228
+ }
229
+
94
230
  //#endregion
95
231
  //#region node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js
96
232
  var require_color_name = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js": ((exports, module) => {
@@ -1692,15 +1828,15 @@ var require_route = /* @__PURE__ */ require_reportManualReview.__commonJS({ "nod
1692
1828
  };
1693
1829
  }
1694
1830
  function wrapConversion(toModel, graph) {
1695
- const path$4 = [graph[toModel].parent, toModel];
1831
+ const path$5 = [graph[toModel].parent, toModel];
1696
1832
  let fn = conversions$1[graph[toModel].parent][toModel];
1697
1833
  let cur = graph[toModel].parent;
1698
1834
  while (graph[cur].parent) {
1699
- path$4.unshift(graph[cur].parent);
1835
+ path$5.unshift(graph[cur].parent);
1700
1836
  fn = link(conversions$1[graph[cur].parent][cur], fn);
1701
1837
  cur = graph[cur].parent;
1702
1838
  }
1703
- fn.conversion = path$4;
1839
+ fn.conversion = path$5;
1704
1840
  return fn;
1705
1841
  }
1706
1842
  module.exports = function(fromModel) {
@@ -4831,11 +4967,11 @@ var require_opts_arg = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
4831
4967
  const resolved = opts;
4832
4968
  const optsFs = opts.fs || {};
4833
4969
  opts.mkdir = opts.mkdir || optsFs.mkdir || fs_1$1.mkdir;
4834
- opts.mkdirAsync = opts.mkdirAsync ? opts.mkdirAsync : async (path$4, options) => {
4835
- return new Promise((res, rej) => resolved.mkdir(path$4, options, (er, made) => er ? rej(er) : res(made)));
4970
+ opts.mkdirAsync = opts.mkdirAsync ? opts.mkdirAsync : async (path$5, options) => {
4971
+ return new Promise((res, rej) => resolved.mkdir(path$5, options, (er, made) => er ? rej(er) : res(made)));
4836
4972
  };
4837
4973
  opts.stat = opts.stat || optsFs.stat || fs_1$1.stat;
4838
- opts.statAsync = opts.statAsync ? opts.statAsync : async (path$4) => new Promise((res, rej) => resolved.stat(path$4, (err, stats) => err ? rej(err) : res(stats)));
4974
+ opts.statAsync = opts.statAsync ? opts.statAsync : async (path$5) => new Promise((res, rej) => resolved.stat(path$5, (err, stats) => err ? rej(err) : res(stats)));
4839
4975
  opts.statSync = opts.statSync || optsFs.statSync || fs_1$1.statSync;
4840
4976
  opts.mkdirSync = opts.mkdirSync || optsFs.mkdirSync || fs_1$1.mkdirSync;
4841
4977
  return resolved;
@@ -4850,47 +4986,47 @@ var require_mkdirp_manual = /* @__PURE__ */ require_reportManualReview.__commonJ
4850
4986
  exports.mkdirpManual = exports.mkdirpManualSync = void 0;
4851
4987
  const path_1$3 = require("node:path");
4852
4988
  const opts_arg_js_1$3 = require_opts_arg();
4853
- const mkdirpManualSync = (path$4, options, made) => {
4854
- const parent = (0, path_1$3.dirname)(path$4);
4989
+ const mkdirpManualSync = (path$5, options, made) => {
4990
+ const parent = (0, path_1$3.dirname)(path$5);
4855
4991
  const opts = {
4856
4992
  ...(0, opts_arg_js_1$3.optsArg)(options),
4857
4993
  recursive: false
4858
4994
  };
4859
- if (parent === path$4) try {
4860
- return opts.mkdirSync(path$4, opts);
4995
+ if (parent === path$5) try {
4996
+ return opts.mkdirSync(path$5, opts);
4861
4997
  } catch (er) {
4862
4998
  const fer = er;
4863
4999
  if (fer && fer.code !== "EISDIR") throw er;
4864
5000
  return;
4865
5001
  }
4866
5002
  try {
4867
- opts.mkdirSync(path$4, opts);
4868
- return made || path$4;
5003
+ opts.mkdirSync(path$5, opts);
5004
+ return made || path$5;
4869
5005
  } catch (er) {
4870
5006
  const fer = er;
4871
- if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManualSync)(path$4, opts, (0, exports.mkdirpManualSync)(parent, opts, made));
5007
+ if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManualSync)(path$5, opts, (0, exports.mkdirpManualSync)(parent, opts, made));
4872
5008
  if (fer && fer.code !== "EEXIST" && fer && fer.code !== "EROFS") throw er;
4873
5009
  try {
4874
- if (!opts.statSync(path$4).isDirectory()) throw er;
5010
+ if (!opts.statSync(path$5).isDirectory()) throw er;
4875
5011
  } catch (_) {
4876
5012
  throw er;
4877
5013
  }
4878
5014
  }
4879
5015
  };
4880
5016
  exports.mkdirpManualSync = mkdirpManualSync;
4881
- exports.mkdirpManual = Object.assign(async (path$4, options, made) => {
5017
+ exports.mkdirpManual = Object.assign(async (path$5, options, made) => {
4882
5018
  const opts = (0, opts_arg_js_1$3.optsArg)(options);
4883
5019
  opts.recursive = false;
4884
- const parent = (0, path_1$3.dirname)(path$4);
4885
- if (parent === path$4) return opts.mkdirAsync(path$4, opts).catch((er) => {
5020
+ const parent = (0, path_1$3.dirname)(path$5);
5021
+ if (parent === path$5) return opts.mkdirAsync(path$5, opts).catch((er) => {
4886
5022
  const fer = er;
4887
5023
  if (fer && fer.code !== "EISDIR") throw er;
4888
5024
  });
4889
- return opts.mkdirAsync(path$4, opts).then(() => made || path$4, async (er) => {
5025
+ return opts.mkdirAsync(path$5, opts).then(() => made || path$5, async (er) => {
4890
5026
  const fer = er;
4891
- if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManual)(parent, opts).then((made$1) => (0, exports.mkdirpManual)(path$4, opts, made$1));
5027
+ if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManual)(parent, opts).then((made$1) => (0, exports.mkdirpManual)(path$5, opts, made$1));
4892
5028
  if (fer && fer.code !== "EEXIST" && fer.code !== "EROFS") throw er;
4893
- return opts.statAsync(path$4).then((st) => {
5029
+ return opts.statAsync(path$5).then((st) => {
4894
5030
  if (st.isDirectory()) return made;
4895
5031
  else throw er;
4896
5032
  }, () => {
@@ -4906,18 +5042,18 @@ var require_find_made = /* @__PURE__ */ require_reportManualReview.__commonJS({
4906
5042
  Object.defineProperty(exports, "__esModule", { value: true });
4907
5043
  exports.findMadeSync = exports.findMade = void 0;
4908
5044
  const path_1$2 = require("node:path");
4909
- const findMade = async (opts, parent, path$4) => {
4910
- if (path$4 === parent) return;
4911
- return opts.statAsync(parent).then((st) => st.isDirectory() ? path$4 : void 0, (er) => {
5045
+ const findMade = async (opts, parent, path$5) => {
5046
+ if (path$5 === parent) return;
5047
+ return opts.statAsync(parent).then((st) => st.isDirectory() ? path$5 : void 0, (er) => {
4912
5048
  const fer = er;
4913
5049
  return fer && fer.code === "ENOENT" ? (0, exports.findMade)(opts, (0, path_1$2.dirname)(parent), parent) : void 0;
4914
5050
  });
4915
5051
  };
4916
5052
  exports.findMade = findMade;
4917
- const findMadeSync = (opts, parent, path$4) => {
4918
- if (path$4 === parent) return void 0;
5053
+ const findMadeSync = (opts, parent, path$5) => {
5054
+ if (path$5 === parent) return void 0;
4919
5055
  try {
4920
- return opts.statSync(parent).isDirectory() ? path$4 : void 0;
5056
+ return opts.statSync(parent).isDirectory() ? path$5 : void 0;
4921
5057
  } catch (er) {
4922
5058
  const fer = er;
4923
5059
  return fer && fer.code === "ENOENT" ? (0, exports.findMadeSync)(opts, (0, path_1$2.dirname)(parent), parent) : void 0;
@@ -4935,32 +5071,32 @@ var require_mkdirp_native = /* @__PURE__ */ require_reportManualReview.__commonJ
4935
5071
  const find_made_js_1 = require_find_made();
4936
5072
  const mkdirp_manual_js_1$1 = require_mkdirp_manual();
4937
5073
  const opts_arg_js_1$2 = require_opts_arg();
4938
- const mkdirpNativeSync = (path$4, options) => {
5074
+ const mkdirpNativeSync = (path$5, options) => {
4939
5075
  const opts = (0, opts_arg_js_1$2.optsArg)(options);
4940
5076
  opts.recursive = true;
4941
- const parent = (0, path_1$1.dirname)(path$4);
4942
- if (parent === path$4) return opts.mkdirSync(path$4, opts);
4943
- const made = (0, find_made_js_1.findMadeSync)(opts, path$4);
5077
+ const parent = (0, path_1$1.dirname)(path$5);
5078
+ if (parent === path$5) return opts.mkdirSync(path$5, opts);
5079
+ const made = (0, find_made_js_1.findMadeSync)(opts, path$5);
4944
5080
  try {
4945
- opts.mkdirSync(path$4, opts);
5081
+ opts.mkdirSync(path$5, opts);
4946
5082
  return made;
4947
5083
  } catch (er) {
4948
5084
  const fer = er;
4949
- if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManualSync)(path$4, opts);
5085
+ if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManualSync)(path$5, opts);
4950
5086
  else throw er;
4951
5087
  }
4952
5088
  };
4953
5089
  exports.mkdirpNativeSync = mkdirpNativeSync;
4954
- exports.mkdirpNative = Object.assign(async (path$4, options) => {
5090
+ exports.mkdirpNative = Object.assign(async (path$5, options) => {
4955
5091
  const opts = {
4956
5092
  ...(0, opts_arg_js_1$2.optsArg)(options),
4957
5093
  recursive: true
4958
5094
  };
4959
- const parent = (0, path_1$1.dirname)(path$4);
4960
- if (parent === path$4) return await opts.mkdirAsync(path$4, opts);
4961
- return (0, find_made_js_1.findMade)(opts, path$4).then((made) => opts.mkdirAsync(path$4, opts).then((m$1) => made || m$1).catch((er) => {
5095
+ const parent = (0, path_1$1.dirname)(path$5);
5096
+ if (parent === path$5) return await opts.mkdirAsync(path$5, opts);
5097
+ return (0, find_made_js_1.findMade)(opts, path$5).then((made) => opts.mkdirAsync(path$5, opts).then((m$1) => made || m$1).catch((er) => {
4962
5098
  const fer = er;
4963
- if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManual)(path$4, opts);
5099
+ if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManual)(path$5, opts);
4964
5100
  else throw er;
4965
5101
  }));
4966
5102
  }, { sync: exports.mkdirpNativeSync });
@@ -4973,21 +5109,21 @@ var require_path_arg = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
4973
5109
  exports.pathArg = void 0;
4974
5110
  const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform;
4975
5111
  const path_1 = require("node:path");
4976
- const pathArg = (path$4) => {
4977
- if (/\0/.test(path$4)) throw Object.assign(/* @__PURE__ */ new TypeError("path must be a string without null bytes"), {
4978
- path: path$4,
5112
+ const pathArg = (path$5) => {
5113
+ if (/\0/.test(path$5)) throw Object.assign(/* @__PURE__ */ new TypeError("path must be a string without null bytes"), {
5114
+ path: path$5,
4979
5115
  code: "ERR_INVALID_ARG_VALUE"
4980
5116
  });
4981
- path$4 = (0, path_1.resolve)(path$4);
5117
+ path$5 = (0, path_1.resolve)(path$5);
4982
5118
  if (platform === "win32") {
4983
5119
  const badWinChars = /[*|"<>?:]/;
4984
- const { root } = (0, path_1.parse)(path$4);
4985
- if (badWinChars.test(path$4.substring(root.length))) throw Object.assign(/* @__PURE__ */ new Error("Illegal characters in path."), {
4986
- path: path$4,
5120
+ const { root } = (0, path_1.parse)(path$5);
5121
+ if (badWinChars.test(path$5.substring(root.length))) throw Object.assign(/* @__PURE__ */ new Error("Illegal characters in path."), {
5122
+ path: path$5,
4987
5123
  code: "EINVAL"
4988
5124
  });
4989
5125
  }
4990
- return path$4;
5126
+ return path$5;
4991
5127
  };
4992
5128
  exports.pathArg = pathArg;
4993
5129
  }) });
@@ -5057,10 +5193,10 @@ var require_src = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node_
5057
5193
  }
5058
5194
  });
5059
5195
  /* c8 ignore stop */
5060
- const mkdirpSync = (path$4, opts) => {
5061
- path$4 = (0, path_arg_js_1.pathArg)(path$4);
5196
+ const mkdirpSync = (path$5, opts) => {
5197
+ path$5 = (0, path_arg_js_1.pathArg)(path$5);
5062
5198
  const resolved = (0, opts_arg_js_1.optsArg)(opts);
5063
- return (0, use_native_js_1.useNativeSync)(resolved) ? (0, mkdirp_native_js_1.mkdirpNativeSync)(path$4, resolved) : (0, mkdirp_manual_js_1.mkdirpManualSync)(path$4, resolved);
5199
+ return (0, use_native_js_1.useNativeSync)(resolved) ? (0, mkdirp_native_js_1.mkdirpNativeSync)(path$5, resolved) : (0, mkdirp_manual_js_1.mkdirpManualSync)(path$5, resolved);
5064
5200
  };
5065
5201
  exports.mkdirpSync = mkdirpSync;
5066
5202
  exports.sync = exports.mkdirpSync;
@@ -5068,10 +5204,10 @@ var require_src = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node_
5068
5204
  exports.manualSync = mkdirp_manual_js_1.mkdirpManualSync;
5069
5205
  exports.native = mkdirp_native_js_1.mkdirpNative;
5070
5206
  exports.nativeSync = mkdirp_native_js_1.mkdirpNativeSync;
5071
- exports.mkdirp = Object.assign(async (path$4, opts) => {
5072
- path$4 = (0, path_arg_js_1.pathArg)(path$4);
5207
+ exports.mkdirp = Object.assign(async (path$5, opts) => {
5208
+ path$5 = (0, path_arg_js_1.pathArg)(path$5);
5073
5209
  const resolved = (0, opts_arg_js_1.optsArg)(opts);
5074
- return (0, use_native_js_1.useNative)(resolved) ? (0, mkdirp_native_js_1.mkdirpNative)(path$4, resolved) : (0, mkdirp_manual_js_1.mkdirpManual)(path$4, resolved);
5210
+ return (0, use_native_js_1.useNative)(resolved) ? (0, mkdirp_native_js_1.mkdirpNative)(path$5, resolved) : (0, mkdirp_manual_js_1.mkdirpManual)(path$5, resolved);
5075
5211
  }, {
5076
5212
  mkdirpSync: exports.mkdirpSync,
5077
5213
  mkdirpNative: mkdirp_native_js_1.mkdirpNative,
@@ -5286,44 +5422,57 @@ expect.extend({ toMatchFile: import_jest_file_snapshot.toMatchFile });
5286
5422
  //#region src/runCodemod.ts
5287
5423
  const currentFilePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
5288
5424
  const currentDirPath = node_path.default.dirname(currentFilePath);
5425
+ const resetReportFile = async (reportPath) => {
5426
+ try {
5427
+ await node_fs_promises.default.access(reportPath);
5428
+ await node_fs_promises.default.rm(reportPath);
5429
+ console.debug(`Removed existing report file: ${reportPath}`);
5430
+ } catch {
5431
+ console.debug(`No existing report file to remove: ${reportPath}`);
5432
+ }
5433
+ };
5434
+ const summariseReportFile = async (reportPath) => {
5435
+ try {
5436
+ const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
5437
+ const lines = reportContent.split("\n").filter(Boolean);
5438
+ if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
5439
+ else console.debug(`Report file exists but is empty: ${reportPath}`);
5440
+ } catch {
5441
+ console.debug(`No report file generated - no manual reviews needed`);
5442
+ }
5443
+ };
5289
5444
  async function runCodemod(transformsDir) {
5290
5445
  try {
5446
+ const packages = findPackages();
5447
+ const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
5291
5448
  const resolvedTransformsDir = transformsDir ?? node_path.default.resolve(currentDirPath, "../dist/transforms");
5292
5449
  console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);
5450
+ await resetReportFile(reportPath);
5293
5451
  const { transformFiles } = await loadTransformModules_default(resolvedTransformsDir);
5294
5452
  if (transformFiles.length === 0) throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);
5295
- const resolvedTransformFiles = await Promise.all(transformFiles);
5296
- const options = await getOptions_default(resolvedTransformFiles);
5453
+ const options = await getOptions_default({
5454
+ packages,
5455
+ root: findProjectRoot(),
5456
+ transformFiles: await Promise.all(transformFiles)
5457
+ });
5297
5458
  const codemodPath = node_path.default.resolve(resolvedTransformsDir, `${options.transformFile}.js`);
5298
5459
  console.debug(`Resolved codemod path: ${codemodPath}`);
5299
- const args = [
5300
- "-t",
5301
- codemodPath,
5302
- options.targetPath,
5303
- options.dry ? "--dry" : "",
5304
- options.print ? "--print" : "",
5305
- options.ignorePattern ? options.ignorePattern.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
5306
- options.gitignore ? "--gitignore" : ""
5307
- ].filter(Boolean);
5308
- const command = `npx jscodeshift ${args.join(" ")}`;
5309
- console.debug(`Running: ${command}`);
5310
- const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
5311
- try {
5312
- await node_fs_promises.default.access(reportPath);
5313
- await node_fs_promises.default.rm(reportPath);
5314
- console.debug(`Removed existing report file: ${reportPath}`);
5315
- } catch {
5316
- console.debug(`No existing report file to remove: ${reportPath}`);
5317
- }
5318
- (0, node_child_process.execSync)(command, { stdio: "inherit" });
5319
- try {
5320
- const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
5321
- const lines = reportContent.split("\n").filter(Boolean);
5322
- if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
5323
- else console.debug(`Report file exists but is empty: ${reportPath}`);
5324
- } catch {
5325
- console.debug(`No report file generated - no manual reviews needed`);
5326
- }
5460
+ options.targetPaths.map((targetPath) => {
5461
+ const args = [
5462
+ "-t",
5463
+ codemodPath,
5464
+ targetPath,
5465
+ options.isDry ? "--dry" : "",
5466
+ options.isPrint ? "--print" : "",
5467
+ options.ignorePatterns ? options.ignorePatterns.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
5468
+ options.useGitIgnore ? "--gitignore" : ""
5469
+ ].filter(Boolean);
5470
+ const command = `npx jscodeshift ${args.join(" ")}`;
5471
+ console.info(`⚙️ \x1b[1mProcessing:\x1b[0m \x1b[32m${targetPath}\x1b[0m`);
5472
+ console.debug(`Running: ${command}`);
5473
+ return (0, node_child_process.execSync)(command, { stdio: "inherit" });
5474
+ });
5475
+ await summariseReportFile(reportPath);
5327
5476
  } catch (error) {
5328
5477
  if (error instanceof Error) console.error("Error running codemod:", error.message);
5329
5478
  else console.error("Error running codemod:", error);