@wise/wds-codemods 0.0.1-experimental-4a59f73 → 0.0.1-experimental-e47d8df

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.cjs ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ const require_reportManualReview = require('./reportManualReview-BfeMigw4.cjs');
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
+ const node_path = require_reportManualReview.__toESM(require("node:path"));
6
+ const node_url = require_reportManualReview.__toESM(require("node:url"));
7
+ const __inquirer_prompts = require_reportManualReview.__toESM(require("@inquirer/prompts"));
8
+ const node_fs = require_reportManualReview.__toESM(require("node:fs"));
9
+
10
+ //#region src/utils/getOptions.ts
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
+ };
33
+ }
34
+ const transformFile = await (0, __inquirer_prompts.select)({
35
+ message: "Select a codemod transform to run:",
36
+ choices: transformFiles.map((file) => ({
37
+ name: file,
38
+ value: file
39
+ }))
40
+ });
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"
44
+ });
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?",
51
+ default: false
52
+ });
53
+ const ignorePattern = await (0, __inquirer_prompts.input)({
54
+ message: "Enter ignore pattern(s) (comma separated) or leave empty:",
55
+ validate: (value) => true
56
+ });
57
+ const gitignore = await (0, __inquirer_prompts.confirm)({
58
+ message: "Respect .gitignore files?",
59
+ default: true
60
+ });
61
+ return {
62
+ transformFile,
63
+ targetPath,
64
+ dry,
65
+ print,
66
+ ignorePattern,
67
+ gitignore
68
+ };
69
+ }
70
+
71
+ //#endregion
72
+ //#region src/utils/loadTransformModules.ts
73
+ async function loadTransformModules(transformsDir) {
74
+ let transformModules = {};
75
+ const files = await node_fs.promises.readdir(transformsDir);
76
+ const transformFiles = await Promise.all(files.filter((file) => file.endsWith(".js")).map(async (file) => {
77
+ const transformPath = node_path.default.join(transformsDir, file);
78
+ const transformModule = await import(transformPath);
79
+ transformModules = {
80
+ ...transformModules,
81
+ [file]: transformModule.default.default
82
+ };
83
+ return file.replace(".js", "");
84
+ }));
85
+ return {
86
+ transformModules,
87
+ transformFiles
88
+ };
89
+ }
90
+
91
+ //#endregion
92
+ //#region src/runCodemod.ts
93
+ const currentFilePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
94
+ const currentDirPath = node_path.default.dirname(currentFilePath);
95
+ async function runCodemod(transformsDir) {
96
+ try {
97
+ const resolvedTransformsDir = transformsDir ?? node_path.default.resolve(currentDirPath, "../dist/transforms");
98
+ console.debug(`Resolved transforms directory: ${resolvedTransformsDir}`);
99
+ const { transformFiles } = await loadTransformModules(resolvedTransformsDir);
100
+ if (transformFiles.length === 0) throw new Error(`No transform scripts found in directory: ${resolvedTransformsDir}`);
101
+ const resolvedTransformFiles = await Promise.all(transformFiles);
102
+ const options = await getOptions(resolvedTransformFiles);
103
+ const codemodPath = node_path.default.resolve(resolvedTransformsDir, `${options.transformFile}.js`);
104
+ console.debug(`Resolved codemod path: ${codemodPath}`);
105
+ const args = [
106
+ "-t",
107
+ codemodPath,
108
+ options.targetPath,
109
+ options.dry ? "--dry" : "",
110
+ options.print ? "--print" : "",
111
+ options.ignorePattern ? options.ignorePattern.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
112
+ options.gitignore ? "--gitignore" : ""
113
+ ].filter(Boolean);
114
+ const command = `npx jscodeshift ${args.join(" ")}`;
115
+ console.debug(`Running: ${command}`);
116
+ const reportPath = node_path.default.resolve(process.cwd(), "codemod-report.txt");
117
+ try {
118
+ await node_fs_promises.default.access(reportPath);
119
+ await node_fs_promises.default.rm(reportPath);
120
+ console.debug(`Removed existing report file: ${reportPath}`);
121
+ } catch {
122
+ console.debug(`No existing report file to remove: ${reportPath}`);
123
+ }
124
+ (0, node_child_process.execSync)(command, { stdio: "inherit" });
125
+ try {
126
+ const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
127
+ const lines = reportContent.split("\n").filter(Boolean);
128
+ if (lines.length) console.log(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
129
+ else console.debug(`Report file exists but is empty: ${reportPath}`);
130
+ } catch {
131
+ console.debug(`No report file generated - no manual reviews needed`);
132
+ }
133
+ } catch (error) {
134
+ if (error instanceof Error) console.error("Error running codemod:", error.message);
135
+ else console.error("Error running codemod:", error);
136
+ if (process.env.NODE_ENV !== "test") process.exit(1);
137
+ }
138
+ }
139
+
140
+ //#endregion
141
+ //#region src/index.ts
142
+ runCodemod();
143
+
144
+ //#endregion
145
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["transformFile","targetPath","dry","print","ignorePattern: string | undefined","gitignore","transformModules: Record<string, unknown>","fs","path","path","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,aAAW,GAAG;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;EAE5C,MAAMC,cAAY,KAAK,SAAS;EAChC,MAAM,cAAc,KAAK,SAAS;AAElC,MAAI,CAACL,mBAAiB,CAAC,eAAe,SAASA,iBAC7C,OAAM,IAAI,MAAM;AAElB,MAAI,CAACC,aACH,OAAM,IAAI,MAAM;EAIlB,MAAM,eAAe,CAAC,EAAEI,eAAc,CAACA,eAAa,CAAC;AAErD,SAAO;GAAE;GAAe;GAAY;GAAK;GAAO;GAAe,WAAW;GAAc;CACzF;CAED,MAAM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kBAAK,QAAQ,uBAAuB,GAAG,QAAQ,cAAc;AACjF,UAAQ,MAAM,0BAA0B;EAExC,MAAM,OAAO;GACX;GACA;GACA,QAAQ;GACR,QAAQ,MAAM,UAAU;GACxB,QAAQ,QAAQ,YAAY;GAC5B,QAAQ,gBACJ,QAAQ,cACL,MAAM,KACN,KAAK,YAAY,oBAAoB,QAAQ,UAC7C,KAAK,OACR;GACJ,QAAQ,YAAY,gBAAgB;GACrC,CAAC,OAAO;EAET,MAAM,UAAU,mBAAmB,KAAK,KAAK;AAE7C,UAAQ,MAAM,YAAY;EAE1B,MAAM,aAAaA,kBAAK,QAAQ,QAAQ,OAAO;AAE/C,MAAI;AACF,SAAMC,yBAAG,OAAO;AAChB,SAAMA,yBAAG,GAAG;AACZ,WAAQ,MAAM,iCAAiC;EAChD,QAAO;AACN,WAAQ,MAAM,sCAAsC;EACrD;AAED,mCAAS,SAAS,EAAE,OAAO,WAAW;AAEtC,MAAI;GACF,MAAM,gBAAgB,MAAMA,yBAAG,SAAS,YAAY;GACpD,MAAM,QAAQ,cAAc,MAAM,MAAM,OAAO;AAC/C,OAAI,MAAM,OACR,SAAQ,IACN,SAAS,MAAM,OAAO,gBAAgB,MAAM,SAAS,IAAI,UAAU,MAAM,iBAAiB,WAAW;OAGvG,SAAQ,MAAM,oCAAoC;EAErD,QAAO;AACN,WAAQ,MAAM;EACf;CACF,SAAQC,OAAgB;AACvB,MAAI,iBAAiB,MACnB,SAAQ,MAAM,0BAA0B,MAAM;MAE9C,SAAQ,MAAM,0BAA0B;AAE1C,MAAI,QAAQ,IAAI,aAAa,OAC3B,SAAQ,KAAK;CAEhB;AACF;;;;AClFI"}
@@ -0,0 +1,50 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const node_fs_promises = __toESM(require("node:fs/promises"));
25
+ const node_path = __toESM(require("node:path"));
26
+
27
+ //#region src/utils/reportManualReview.ts
28
+ const REPORT_PATH = node_path.default.resolve(process.cwd(), "codemod-report.txt");
29
+ const reportManualReview = async (filePath, message) => {
30
+ const lineMatch = /at line (\d+)/u.exec(message);
31
+ const lineNumber = lineMatch?.[1];
32
+ const cleanMessage = message.replace(/ at line \d+/u, "");
33
+ const lineInfo = lineNumber ? `:${lineNumber}` : "";
34
+ await node_fs_promises.default.appendFile(REPORT_PATH, `[${filePath}${lineInfo}] ${cleanMessage}\n`, "utf8");
35
+ };
36
+
37
+ //#endregion
38
+ Object.defineProperty(exports, '__toESM', {
39
+ enumerable: true,
40
+ get: function () {
41
+ return __toESM;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, 'reportManualReview', {
45
+ enumerable: true,
46
+ get: function () {
47
+ return reportManualReview;
48
+ }
49
+ });
50
+ //# sourceMappingURL=reportManualReview-BfeMigw4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reportManualReview-BfeMigw4.cjs","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;AAChF"}