@wise/wds-codemods 0.0.1-experimental-23cf8ec → 0.0.1-experimental-4078294

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