@wise/wds-codemods 0.0.1-experimental-53a7adb → 0.0.1-experimental-23cf8ec

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,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_reportManualReview = require('./reportManualReview-Bf-sT2Ka.js');
2
+ const require_reportManualReview = require('./reportManualReview-6eUfvKRn.js');
3
3
  let node_child_process = require("node:child_process");
4
4
  node_child_process = require_reportManualReview.__toESM(node_child_process);
5
5
  let node_fs_promises = require("node:fs/promises");
@@ -405,7 +405,8 @@ var require_diff = /* @__PURE__ */ require_reportManualReview.__commonJS({ "node
405
405
  const highVersion = v1Higher ? v1 : v2;
406
406
  const lowVersion = v1Higher ? v2 : v1;
407
407
  const highHasPre = !!highVersion.prerelease.length;
408
- if (!!lowVersion.prerelease.length && !highHasPre) {
408
+ const lowHasPre = !!lowVersion.prerelease.length;
409
+ if (lowHasPre && !highHasPre) {
409
410
  if (!lowVersion.patch && !lowVersion.minor) return "major";
410
411
  if (lowVersion.compareMain(highVersion) === 0) {
411
412
  if (lowVersion.minor && !lowVersion.patch) return "minor";
@@ -632,7 +633,7 @@ var require_lrucache = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
632
633
  }
633
634
  get(key) {
634
635
  const value = this.map.get(key);
635
- if (value === void 0) return;
636
+ if (value === void 0) return void 0;
636
637
  else {
637
638
  this.map.delete(key);
638
639
  this.map.set(key, value);
@@ -643,7 +644,8 @@ var require_lrucache = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
643
644
  return this.map.delete(key);
644
645
  }
645
646
  set(key, value) {
646
- if (!this.delete(key) && value !== void 0) {
647
+ const deleted = this.delete(key);
648
+ if (!deleted && value !== void 0) {
647
649
  if (this.map.size >= this.max) {
648
650
  const firstKey = this.map.keys().next().value;
649
651
  this.delete(firstKey);
@@ -711,7 +713,8 @@ var require_range = /* @__PURE__ */ require_reportManualReview.__commonJS({ "nod
711
713
  return this.range;
712
714
  }
713
715
  parseRange(range) {
714
- const memoKey = ((this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE)) + ":" + range;
716
+ const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
717
+ const memoKey = memoOpts + ":" + range;
715
718
  const cached = cache.get(memoKey);
716
719
  if (cached) return cached;
717
720
  const loose = this.options.loose;
@@ -765,7 +768,8 @@ var require_range = /* @__PURE__ */ require_reportManualReview.__commonJS({ "nod
765
768
  }
766
769
  };
767
770
  module.exports = Range$11;
768
- const cache = new (require_lrucache())();
771
+ const LRU = require_lrucache();
772
+ const cache = new LRU();
769
773
  const parseOptions$1 = require_parse_options();
770
774
  const Comparator$4 = require_comparator();
771
775
  const debug$1 = require_debug();
@@ -1224,13 +1228,16 @@ var require_simplify = /* @__PURE__ */ require_reportManualReview.__commonJS({ "
1224
1228
  let first = null;
1225
1229
  let prev = null;
1226
1230
  const v = versions.sort((a, b) => compare$2(a, b, options));
1227
- for (const version of v) if (satisfies$2(version, range, options)) {
1228
- prev = version;
1229
- if (!first) first = version;
1230
- } else {
1231
- if (prev) set.push([first, prev]);
1232
- prev = null;
1233
- first = null;
1231
+ for (const version of v) {
1232
+ const included = satisfies$2(version, range, options);
1233
+ if (included) {
1234
+ prev = version;
1235
+ if (!first) first = version;
1236
+ } else {
1237
+ if (prev) set.push([first, prev]);
1238
+ prev = null;
1239
+ first = null;
1240
+ }
1234
1241
  }
1235
1242
  if (first) set.push([first, null]);
1236
1243
  const ranges = [];
@@ -1510,12 +1517,13 @@ const renderTable = (data, indexHeading = "index") => {
1510
1517
  const midSeparator = `├${firstCellLine}┼${remainingLines.join("┼")}┤`;
1511
1518
  const endSeparator = `└${firstCellLine}┴${remainingLines.join("┴")}┘`;
1512
1519
  const formatRow = (cells) => {
1513
- return `│${cells.map((cell, index) => {
1520
+ const formattedCells = cells.map((cell, index) => {
1514
1521
  const width = columnWidths[index];
1515
1522
  const displayWidth = getDisplayWidth(cell);
1516
1523
  const padding = width - displayWidth;
1517
1524
  return ` ${cell}${" ".repeat(Math.max(0, padding))} `;
1518
- }).join("│")}│`;
1525
+ });
1526
+ return `│${formattedCells.join("│")}│`;
1519
1527
  };
1520
1528
  console.info(topSeparator);
1521
1529
  console.info(formatRow(headings));
@@ -1556,7 +1564,8 @@ function getVersionFromNodeModules(packagePath, packageName) {
1556
1564
  try {
1557
1565
  const nodeModulesPackageJson = (0, node_path.join)(packagePath, "node_modules", packageName, "package.json");
1558
1566
  if (!(0, node_fs.existsSync)(nodeModulesPackageJson)) return "";
1559
- return JSON.parse((0, node_fs.readFileSync)(nodeModulesPackageJson, "utf8")).version || "";
1567
+ const packageJson = JSON.parse((0, node_fs.readFileSync)(nodeModulesPackageJson, "utf8"));
1568
+ return packageJson.version || "";
1560
1569
  } catch {
1561
1570
  return "";
1562
1571
  }
@@ -1683,15 +1692,17 @@ const queryPackages = async (packages) => {
1683
1692
  const message = "Path to run codemod on:";
1684
1693
  const nonRootPackages = packages.filter((pkg) => pkg !== "." && pkg !== "./");
1685
1694
  if (packages.length === 1 && (packages[0] === "." || packages[0] === "./")) {
1686
- if (await (0, __inquirer_prompts.confirm)({
1695
+ const useCustomPath = await (0, __inquirer_prompts.confirm)({
1687
1696
  message: "Do you want to target a specific folder instead of the entire project?",
1688
1697
  default: false
1689
- })) {
1698
+ });
1699
+ if (useCustomPath) {
1690
1700
  const customPath = await (0, __inquirer_prompts.search)({
1691
1701
  message: "Enter the folder path (relative to project root):",
1692
1702
  source: async (searchInput) => {
1693
1703
  const rootPath = process.cwd();
1694
- return getDirectoryChoices(rootPath, searchInput || "").map((choice) => ({
1704
+ const choices = getDirectoryChoices(rootPath, searchInput || "");
1705
+ return choices.map((choice) => ({
1695
1706
  name: choice === "." ? ". (entire project)" : choice,
1696
1707
  value: choice,
1697
1708
  description: choice === "." ? "Target the entire project" : `Target ${choice} directory`
@@ -1849,7 +1860,8 @@ async function loadTransformModules(transformsDir) {
1849
1860
  let transformModules = {};
1850
1861
  const transformers = await node_fs.promises.readdir(transformsDir);
1851
1862
  const transformFiles = await Promise.all(transformers.map(async (name) => {
1852
- const transformModule = await import(node_path.default.join(transformsDir, name, "transformer.js"));
1863
+ const transformPath = node_path.default.join(transformsDir, name, "transformer.js");
1864
+ const transformModule = await import(transformPath);
1853
1865
  transformModules = {
1854
1866
  ...transformModules,
1855
1867
  [name]: transformModule.default.default
@@ -1878,7 +1890,8 @@ const resetReportFile = async (reportPath) => {
1878
1890
  };
1879
1891
  const summariseReportFile = async (reportPath) => {
1880
1892
  try {
1881
- const lines = (await node_fs_promises.default.readFile(reportPath, "utf8")).split("\n").filter(Boolean);
1893
+ const reportContent = await node_fs_promises.default.readFile(reportPath, "utf8");
1894
+ const lines = reportContent.split("\n").filter(Boolean);
1882
1895
  if (lines.length) console.debug(`\n⚠️ ${lines.length} manual review${lines.length > 1 ? "s are" : " is"} required. See ${reportPath} for details.`);
1883
1896
  else console.debug(`Report file exists but is empty: ${reportPath}`);
1884
1897
  } catch {
@@ -1903,8 +1916,9 @@ async function runCodemod(transformsDir) {
1903
1916
  console.debug(`Resolved codemod path: ${codemodPath}`);
1904
1917
  options.targetPaths.map((targetPath) => {
1905
1918
  console.info(`\n\x1b[34m➙\x1b[0m \x1b[1mProcessing:\x1b[0m \x1b[32m${targetPath}\x1b[0m`);
1906
- if (assessPrerequisites(targetPath, codemodPath)) {
1907
- const command = `npx jscodeshift ${[
1919
+ const isCompliant = assessPrerequisites(targetPath, codemodPath);
1920
+ if (isCompliant) {
1921
+ const args = [
1908
1922
  "-t",
1909
1923
  codemodPath,
1910
1924
  targetPath,
@@ -1912,10 +1926,12 @@ async function runCodemod(transformsDir) {
1912
1926
  options.isPrint ? "--print" : "",
1913
1927
  options.ignorePatterns ? options.ignorePatterns.split(",").map((pattern) => `--ignore-pattern=${pattern.trim()}`).join(" ") : "",
1914
1928
  options.useGitIgnore ? "--gitignore" : ""
1915
- ].filter(Boolean).join(" ")}`;
1929
+ ].filter(Boolean);
1930
+ const command = `npx jscodeshift ${args.join(" ")}`;
1916
1931
  console.debug(`Running: ${command}`);
1917
1932
  return (0, node_child_process.execSync)(command, { stdio: "inherit" });
1918
1933
  }
1934
+ return void 0;
1919
1935
  });
1920
1936
  await summariseReportFile(reportPath);
1921
1937
  } catch (error) {