@wise/wds-codemods 0.0.1-experimental-70cf678 → 0.0.1-experimental-4e597ee
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 +277 -130
- package/dist/index.js.map +1 -1
- package/dist/{reportManualReview-CQm-npxR.js → reportManualReview-cd73vDXT.js} +3 -4
- package/dist/{reportManualReview-CQm-npxR.js.map → reportManualReview-cd73vDXT.js.map} +1 -1
- package/dist/transforms/button.js +7 -10
- package/dist/transforms/button.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,74 +1,163 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_reportManualReview = require('./reportManualReview-
|
|
3
|
-
const node_fs_promises = require_reportManualReview.__toESM(require("node:fs/promises"));
|
|
2
|
+
const require_reportManualReview = require('./reportManualReview-cd73vDXT.js');
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
154
|
+
targetPaths,
|
|
155
|
+
isDry,
|
|
156
|
+
isPrint,
|
|
157
|
+
ignorePatterns,
|
|
158
|
+
useGitIgnore
|
|
69
159
|
};
|
|
70
160
|
}
|
|
71
|
-
var getOptions_default = getOptions;
|
|
72
161
|
|
|
73
162
|
//#endregion
|
|
74
163
|
//#region src/utils/loadTransformModules.ts
|
|
@@ -89,7 +178,52 @@ async function loadTransformModules(transformsDir) {
|
|
|
89
178
|
transformFiles
|
|
90
179
|
};
|
|
91
180
|
}
|
|
92
|
-
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/utils/repository.ts
|
|
184
|
+
/**
|
|
185
|
+
* Finds the root of the project by looking for the `.git` directory.
|
|
186
|
+
*/
|
|
187
|
+
function findProjectRoot() {
|
|
188
|
+
try {
|
|
189
|
+
const gitRoot = (0, node_child_process.execSync)("git rev-parse --show-toplevel", {
|
|
190
|
+
cwd: process.cwd(),
|
|
191
|
+
encoding: "utf8",
|
|
192
|
+
stdio: [
|
|
193
|
+
"ignore",
|
|
194
|
+
"pipe",
|
|
195
|
+
"ignore"
|
|
196
|
+
]
|
|
197
|
+
}).trim();
|
|
198
|
+
return gitRoot && (0, node_fs.existsSync)(gitRoot) ? gitRoot : "";
|
|
199
|
+
} catch {
|
|
200
|
+
return "";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Quick and dirty way of determining package roots based on
|
|
205
|
+
* the presence of `package.json` files and them optimistically
|
|
206
|
+
* containing a `@transferwise/components` string.
|
|
207
|
+
* */
|
|
208
|
+
function findPackages() {
|
|
209
|
+
try {
|
|
210
|
+
const packages = (0, node_child_process.execSync)([
|
|
211
|
+
"find ./",
|
|
212
|
+
"-type f",
|
|
213
|
+
"-name \"package.json\"",
|
|
214
|
+
"-not -path \"*/node_modules/*\"",
|
|
215
|
+
"|",
|
|
216
|
+
"xargs grep -l \"@transferwise/components\""
|
|
217
|
+
].join(" "), {
|
|
218
|
+
cwd: findProjectRoot(),
|
|
219
|
+
encoding: "utf8"
|
|
220
|
+
}).trim().split("\n").map(node_path.default.dirname);
|
|
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
|
+
}
|
|
93
227
|
|
|
94
228
|
//#endregion
|
|
95
229
|
//#region node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js
|
|
@@ -1692,15 +1826,15 @@ var require_route = /* @__PURE__ */ require_reportManualReview.__commonJS({ "nod
|
|
|
1692
1826
|
};
|
|
1693
1827
|
}
|
|
1694
1828
|
function wrapConversion(toModel, graph) {
|
|
1695
|
-
const path$
|
|
1829
|
+
const path$5 = [graph[toModel].parent, toModel];
|
|
1696
1830
|
let fn = conversions$1[graph[toModel].parent][toModel];
|
|
1697
1831
|
let cur = graph[toModel].parent;
|
|
1698
1832
|
while (graph[cur].parent) {
|
|
1699
|
-
path$
|
|
1833
|
+
path$5.unshift(graph[cur].parent);
|
|
1700
1834
|
fn = link(conversions$1[graph[cur].parent][cur], fn);
|
|
1701
1835
|
cur = graph[cur].parent;
|
|
1702
1836
|
}
|
|
1703
|
-
fn.conversion = path$
|
|
1837
|
+
fn.conversion = path$5;
|
|
1704
1838
|
return fn;
|
|
1705
1839
|
}
|
|
1706
1840
|
module.exports = function(fromModel) {
|
|
@@ -4831,11 +4965,11 @@ var require_opts_arg = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
|
|
|
4831
4965
|
const resolved = opts;
|
|
4832
4966
|
const optsFs = opts.fs || {};
|
|
4833
4967
|
opts.mkdir = opts.mkdir || optsFs.mkdir || fs_1$1.mkdir;
|
|
4834
|
-
opts.mkdirAsync = opts.mkdirAsync ? opts.mkdirAsync : async (path$
|
|
4835
|
-
return new Promise((res, rej) => resolved.mkdir(path$
|
|
4968
|
+
opts.mkdirAsync = opts.mkdirAsync ? opts.mkdirAsync : async (path$5, options) => {
|
|
4969
|
+
return new Promise((res, rej) => resolved.mkdir(path$5, options, (er, made) => er ? rej(er) : res(made)));
|
|
4836
4970
|
};
|
|
4837
4971
|
opts.stat = opts.stat || optsFs.stat || fs_1$1.stat;
|
|
4838
|
-
opts.statAsync = opts.statAsync ? opts.statAsync : async (path$
|
|
4972
|
+
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
4973
|
opts.statSync = opts.statSync || optsFs.statSync || fs_1$1.statSync;
|
|
4840
4974
|
opts.mkdirSync = opts.mkdirSync || optsFs.mkdirSync || fs_1$1.mkdirSync;
|
|
4841
4975
|
return resolved;
|
|
@@ -4850,47 +4984,47 @@ var require_mkdirp_manual = /* @__PURE__ */ require_reportManualReview.__commonJ
|
|
|
4850
4984
|
exports.mkdirpManual = exports.mkdirpManualSync = void 0;
|
|
4851
4985
|
const path_1$3 = require("node:path");
|
|
4852
4986
|
const opts_arg_js_1$3 = require_opts_arg();
|
|
4853
|
-
const mkdirpManualSync = (path$
|
|
4854
|
-
const parent = (0, path_1$3.dirname)(path$
|
|
4987
|
+
const mkdirpManualSync = (path$5, options, made) => {
|
|
4988
|
+
const parent = (0, path_1$3.dirname)(path$5);
|
|
4855
4989
|
const opts = {
|
|
4856
4990
|
...(0, opts_arg_js_1$3.optsArg)(options),
|
|
4857
4991
|
recursive: false
|
|
4858
4992
|
};
|
|
4859
|
-
if (parent === path$
|
|
4860
|
-
return opts.mkdirSync(path$
|
|
4993
|
+
if (parent === path$5) try {
|
|
4994
|
+
return opts.mkdirSync(path$5, opts);
|
|
4861
4995
|
} catch (er) {
|
|
4862
4996
|
const fer = er;
|
|
4863
4997
|
if (fer && fer.code !== "EISDIR") throw er;
|
|
4864
4998
|
return;
|
|
4865
4999
|
}
|
|
4866
5000
|
try {
|
|
4867
|
-
opts.mkdirSync(path$
|
|
4868
|
-
return made || path$
|
|
5001
|
+
opts.mkdirSync(path$5, opts);
|
|
5002
|
+
return made || path$5;
|
|
4869
5003
|
} catch (er) {
|
|
4870
5004
|
const fer = er;
|
|
4871
|
-
if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManualSync)(path$
|
|
5005
|
+
if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManualSync)(path$5, opts, (0, exports.mkdirpManualSync)(parent, opts, made));
|
|
4872
5006
|
if (fer && fer.code !== "EEXIST" && fer && fer.code !== "EROFS") throw er;
|
|
4873
5007
|
try {
|
|
4874
|
-
if (!opts.statSync(path$
|
|
5008
|
+
if (!opts.statSync(path$5).isDirectory()) throw er;
|
|
4875
5009
|
} catch (_) {
|
|
4876
5010
|
throw er;
|
|
4877
5011
|
}
|
|
4878
5012
|
}
|
|
4879
5013
|
};
|
|
4880
5014
|
exports.mkdirpManualSync = mkdirpManualSync;
|
|
4881
|
-
exports.mkdirpManual = Object.assign(async (path$
|
|
5015
|
+
exports.mkdirpManual = Object.assign(async (path$5, options, made) => {
|
|
4882
5016
|
const opts = (0, opts_arg_js_1$3.optsArg)(options);
|
|
4883
5017
|
opts.recursive = false;
|
|
4884
|
-
const parent = (0, path_1$3.dirname)(path$
|
|
4885
|
-
if (parent === path$
|
|
5018
|
+
const parent = (0, path_1$3.dirname)(path$5);
|
|
5019
|
+
if (parent === path$5) return opts.mkdirAsync(path$5, opts).catch((er) => {
|
|
4886
5020
|
const fer = er;
|
|
4887
5021
|
if (fer && fer.code !== "EISDIR") throw er;
|
|
4888
5022
|
});
|
|
4889
|
-
return opts.mkdirAsync(path$
|
|
5023
|
+
return opts.mkdirAsync(path$5, opts).then(() => made || path$5, async (er) => {
|
|
4890
5024
|
const fer = er;
|
|
4891
|
-
if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManual)(parent, opts).then((made$1) => (0, exports.mkdirpManual)(path$
|
|
5025
|
+
if (fer && fer.code === "ENOENT") return (0, exports.mkdirpManual)(parent, opts).then((made$1) => (0, exports.mkdirpManual)(path$5, opts, made$1));
|
|
4892
5026
|
if (fer && fer.code !== "EEXIST" && fer.code !== "EROFS") throw er;
|
|
4893
|
-
return opts.statAsync(path$
|
|
5027
|
+
return opts.statAsync(path$5).then((st) => {
|
|
4894
5028
|
if (st.isDirectory()) return made;
|
|
4895
5029
|
else throw er;
|
|
4896
5030
|
}, () => {
|
|
@@ -4906,18 +5040,18 @@ var require_find_made = /* @__PURE__ */ require_reportManualReview.__commonJS({
|
|
|
4906
5040
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4907
5041
|
exports.findMadeSync = exports.findMade = void 0;
|
|
4908
5042
|
const path_1$2 = require("node:path");
|
|
4909
|
-
const findMade = async (opts, parent, path$
|
|
4910
|
-
if (path$
|
|
4911
|
-
return opts.statAsync(parent).then((st) => st.isDirectory() ? path$
|
|
5043
|
+
const findMade = async (opts, parent, path$5) => {
|
|
5044
|
+
if (path$5 === parent) return;
|
|
5045
|
+
return opts.statAsync(parent).then((st) => st.isDirectory() ? path$5 : void 0, (er) => {
|
|
4912
5046
|
const fer = er;
|
|
4913
5047
|
return fer && fer.code === "ENOENT" ? (0, exports.findMade)(opts, (0, path_1$2.dirname)(parent), parent) : void 0;
|
|
4914
5048
|
});
|
|
4915
5049
|
};
|
|
4916
5050
|
exports.findMade = findMade;
|
|
4917
|
-
const findMadeSync = (opts, parent, path$
|
|
4918
|
-
if (path$
|
|
5051
|
+
const findMadeSync = (opts, parent, path$5) => {
|
|
5052
|
+
if (path$5 === parent) return void 0;
|
|
4919
5053
|
try {
|
|
4920
|
-
return opts.statSync(parent).isDirectory() ? path$
|
|
5054
|
+
return opts.statSync(parent).isDirectory() ? path$5 : void 0;
|
|
4921
5055
|
} catch (er) {
|
|
4922
5056
|
const fer = er;
|
|
4923
5057
|
return fer && fer.code === "ENOENT" ? (0, exports.findMadeSync)(opts, (0, path_1$2.dirname)(parent), parent) : void 0;
|
|
@@ -4935,32 +5069,32 @@ var require_mkdirp_native = /* @__PURE__ */ require_reportManualReview.__commonJ
|
|
|
4935
5069
|
const find_made_js_1 = require_find_made();
|
|
4936
5070
|
const mkdirp_manual_js_1$1 = require_mkdirp_manual();
|
|
4937
5071
|
const opts_arg_js_1$2 = require_opts_arg();
|
|
4938
|
-
const mkdirpNativeSync = (path$
|
|
5072
|
+
const mkdirpNativeSync = (path$5, options) => {
|
|
4939
5073
|
const opts = (0, opts_arg_js_1$2.optsArg)(options);
|
|
4940
5074
|
opts.recursive = true;
|
|
4941
|
-
const parent = (0, path_1$1.dirname)(path$
|
|
4942
|
-
if (parent === path$
|
|
4943
|
-
const made = (0, find_made_js_1.findMadeSync)(opts, path$
|
|
5075
|
+
const parent = (0, path_1$1.dirname)(path$5);
|
|
5076
|
+
if (parent === path$5) return opts.mkdirSync(path$5, opts);
|
|
5077
|
+
const made = (0, find_made_js_1.findMadeSync)(opts, path$5);
|
|
4944
5078
|
try {
|
|
4945
|
-
opts.mkdirSync(path$
|
|
5079
|
+
opts.mkdirSync(path$5, opts);
|
|
4946
5080
|
return made;
|
|
4947
5081
|
} catch (er) {
|
|
4948
5082
|
const fer = er;
|
|
4949
|
-
if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManualSync)(path$
|
|
5083
|
+
if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManualSync)(path$5, opts);
|
|
4950
5084
|
else throw er;
|
|
4951
5085
|
}
|
|
4952
5086
|
};
|
|
4953
5087
|
exports.mkdirpNativeSync = mkdirpNativeSync;
|
|
4954
|
-
exports.mkdirpNative = Object.assign(async (path$
|
|
5088
|
+
exports.mkdirpNative = Object.assign(async (path$5, options) => {
|
|
4955
5089
|
const opts = {
|
|
4956
5090
|
...(0, opts_arg_js_1$2.optsArg)(options),
|
|
4957
5091
|
recursive: true
|
|
4958
5092
|
};
|
|
4959
|
-
const parent = (0, path_1$1.dirname)(path$
|
|
4960
|
-
if (parent === path$
|
|
4961
|
-
return (0, find_made_js_1.findMade)(opts, path$
|
|
5093
|
+
const parent = (0, path_1$1.dirname)(path$5);
|
|
5094
|
+
if (parent === path$5) return await opts.mkdirAsync(path$5, opts);
|
|
5095
|
+
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
5096
|
const fer = er;
|
|
4963
|
-
if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManual)(path$
|
|
5097
|
+
if (fer && fer.code === "ENOENT") return (0, mkdirp_manual_js_1$1.mkdirpManual)(path$5, opts);
|
|
4964
5098
|
else throw er;
|
|
4965
5099
|
}));
|
|
4966
5100
|
}, { sync: exports.mkdirpNativeSync });
|
|
@@ -4973,21 +5107,21 @@ var require_path_arg = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
|
|
|
4973
5107
|
exports.pathArg = void 0;
|
|
4974
5108
|
const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform;
|
|
4975
5109
|
const path_1 = require("node:path");
|
|
4976
|
-
const pathArg = (path$
|
|
4977
|
-
if (/\0/.test(path$
|
|
4978
|
-
path: path$
|
|
5110
|
+
const pathArg = (path$5) => {
|
|
5111
|
+
if (/\0/.test(path$5)) throw Object.assign(/* @__PURE__ */ new TypeError("path must be a string without null bytes"), {
|
|
5112
|
+
path: path$5,
|
|
4979
5113
|
code: "ERR_INVALID_ARG_VALUE"
|
|
4980
5114
|
});
|
|
4981
|
-
path$
|
|
5115
|
+
path$5 = (0, path_1.resolve)(path$5);
|
|
4982
5116
|
if (platform === "win32") {
|
|
4983
5117
|
const badWinChars = /[*|"<>?:]/;
|
|
4984
|
-
const { root } = (0, path_1.parse)(path$
|
|
4985
|
-
if (badWinChars.test(path$
|
|
4986
|
-
path: path$
|
|
5118
|
+
const { root } = (0, path_1.parse)(path$5);
|
|
5119
|
+
if (badWinChars.test(path$5.substring(root.length))) throw Object.assign(/* @__PURE__ */ new Error("Illegal characters in path."), {
|
|
5120
|
+
path: path$5,
|
|
4987
5121
|
code: "EINVAL"
|
|
4988
5122
|
});
|
|
4989
5123
|
}
|
|
4990
|
-
return path$
|
|
5124
|
+
return path$5;
|
|
4991
5125
|
};
|
|
4992
5126
|
exports.pathArg = pathArg;
|
|
4993
5127
|
}) });
|
|
@@ -5057,10 +5191,10 @@ var require_src = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node_
|
|
|
5057
5191
|
}
|
|
5058
5192
|
});
|
|
5059
5193
|
/* c8 ignore stop */
|
|
5060
|
-
const mkdirpSync = (path$
|
|
5061
|
-
path$
|
|
5194
|
+
const mkdirpSync = (path$5, opts) => {
|
|
5195
|
+
path$5 = (0, path_arg_js_1.pathArg)(path$5);
|
|
5062
5196
|
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$
|
|
5197
|
+
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
5198
|
};
|
|
5065
5199
|
exports.mkdirpSync = mkdirpSync;
|
|
5066
5200
|
exports.sync = exports.mkdirpSync;
|
|
@@ -5068,10 +5202,10 @@ var require_src = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node_
|
|
|
5068
5202
|
exports.manualSync = mkdirp_manual_js_1.mkdirpManualSync;
|
|
5069
5203
|
exports.native = mkdirp_native_js_1.mkdirpNative;
|
|
5070
5204
|
exports.nativeSync = mkdirp_native_js_1.mkdirpNativeSync;
|
|
5071
|
-
exports.mkdirp = Object.assign(async (path$
|
|
5072
|
-
path$
|
|
5205
|
+
exports.mkdirp = Object.assign(async (path$5, opts) => {
|
|
5206
|
+
path$5 = (0, path_arg_js_1.pathArg)(path$5);
|
|
5073
5207
|
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$
|
|
5208
|
+
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
5209
|
}, {
|
|
5076
5210
|
mkdirpSync: exports.mkdirpSync,
|
|
5077
5211
|
mkdirpNative: mkdirp_native_js_1.mkdirpNative,
|
|
@@ -5286,44 +5420,57 @@ expect.extend({ toMatchFile: import_jest_file_snapshot.toMatchFile });
|
|
|
5286
5420
|
//#region src/runCodemod.ts
|
|
5287
5421
|
const currentFilePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
5288
5422
|
const currentDirPath = node_path.default.dirname(currentFilePath);
|
|
5423
|
+
const resetReportFile = async (reportPath) => {
|
|
5424
|
+
try {
|
|
5425
|
+
await node_fs_promises.default.access(reportPath);
|
|
5426
|
+
await node_fs_promises.default.rm(reportPath);
|
|
5427
|
+
console.debug(`Removed existing report file: ${reportPath}`);
|
|
5428
|
+
} catch {
|
|
5429
|
+
console.debug(`No existing report file to remove: ${reportPath}`);
|
|
5430
|
+
}
|
|
5431
|
+
};
|
|
5432
|
+
const summariseReportFile = async (reportPath) => {
|
|
5433
|
+
try {
|
|
5434
|
+
const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
|
|
5435
|
+
const lines = reportContent.split("\n").filter(Boolean);
|
|
5436
|
+
if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
|
|
5437
|
+
else console.debug(`Report file exists but is empty: ${reportPath}`);
|
|
5438
|
+
} catch {
|
|
5439
|
+
console.debug(`No report file generated - no manual reviews needed`);
|
|
5440
|
+
}
|
|
5441
|
+
};
|
|
5289
5442
|
async function runCodemod(transformsDir) {
|
|
5290
5443
|
try {
|
|
5444
|
+
const packages = findPackages();
|
|
5445
|
+
const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
|
|
5291
5446
|
const resolvedTransformsDir = transformsDir ?? node_path.default.resolve(currentDirPath, "../dist/transforms");
|
|
5292
5447
|
console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);
|
|
5293
|
-
|
|
5448
|
+
await resetReportFile(reportPath);
|
|
5449
|
+
const { transformFiles } = await loadTransformModules(resolvedTransformsDir);
|
|
5294
5450
|
if (transformFiles.length === 0) throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);
|
|
5295
|
-
const
|
|
5296
|
-
|
|
5451
|
+
const options = await getOptions({
|
|
5452
|
+
packages,
|
|
5453
|
+
root: findProjectRoot(),
|
|
5454
|
+
transformFiles: await Promise.all(transformFiles)
|
|
5455
|
+
});
|
|
5297
5456
|
const codemodPath = node_path.default.resolve(resolvedTransformsDir, `${options.transformFile}.js`);
|
|
5298
5457
|
console.debug(`Resolved codemod path: ${codemodPath}`);
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
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
|
-
}
|
|
5458
|
+
options.targetPaths.map((targetPath) => {
|
|
5459
|
+
const args = [
|
|
5460
|
+
"-t",
|
|
5461
|
+
codemodPath,
|
|
5462
|
+
targetPath,
|
|
5463
|
+
options.isDry ? "--dry" : "",
|
|
5464
|
+
options.isPrint ? "--print" : "",
|
|
5465
|
+
options.ignorePatterns ? options.ignorePatterns.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
|
|
5466
|
+
options.useGitIgnore ? "--gitignore" : ""
|
|
5467
|
+
].filter(Boolean);
|
|
5468
|
+
const command = `npx jscodeshift ${args.join(" ")}`;
|
|
5469
|
+
console.info(`⚙️ \x1b[1mProcessing:\x1b[0m \x1b[32m${targetPath}\x1b[0m`);
|
|
5470
|
+
console.debug(`Running: ${command}`);
|
|
5471
|
+
return (0, node_child_process.execSync)(command, { stdio: "inherit" });
|
|
5472
|
+
});
|
|
5473
|
+
await summariseReportFile(reportPath);
|
|
5327
5474
|
} catch (error) {
|
|
5328
5475
|
if (error instanceof Error) console.error("Error running codemod:", error.message);
|
|
5329
5476
|
else console.error("Error running codemod:", error);
|