'use strict';

var _5RAWDGJY_cjs = require('./5RAWDGJY.cjs');
var EDZNH6J4_cjs = require('./EDZNH6J4.cjs');
var VO65XOWD_cjs = require('./VO65XOWD.cjs');
var fs = require('fs');
var semver = require('semver');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var fs__default = /*#__PURE__*/_interopDefault(fs);
var semver__namespace = /*#__PURE__*/_interopNamespace(semver);

// src/utils/finder-utils.ts
VO65XOWD_cjs.init_cjs_shims();

// src/config/index.ts
VO65XOWD_cjs.init_cjs_shims();

// src/config/tools.ts
VO65XOWD_cjs.init_cjs_shims();

// src/utils/version-utils.ts
VO65XOWD_cjs.init_cjs_shims();
function versionsSatisfied(current, expected) {
  return semver__namespace.satisfies(current.version, expected.version);
}
VO65XOWD_cjs.__name(versionsSatisfied, "versionsSatisfied");
function parseAnchorTomlVersion(cwd, name) {
  const projectFolder = _5RAWDGJY_cjs.findParentDirectoryWithFile(cwd, "Anchor.toml");
  if (projectFolder === null) {
    throw new Error("Anchor project not found");
  }
  const toml = fs__default.default.readFileSync(projectFolder.file, "utf-8");
  const test = /^([a-z]+)(?:_version ?= ?")((?:[0-9]+\.?){3})(?:")$/gm;
  let match;
  while (match = test.exec(toml)) {
    const [, matchedName, version] = match;
    if (matchedName === name) {
      return {
        version
      };
    }
  }
  throw new Error(`${name} version not found in ${projectFolder.file}`);
}
VO65XOWD_cjs.__name(parseAnchorTomlVersion, "parseAnchorTomlVersion");
function findSemVersionFromString(input) {
  const match = input.match(/^(solana-cli|anchor-cli|aptos)\s+(([0-9]+\.?){3}).*?/m);
  if (match === null || match.length < 3) {
    throw new Error(`Invalid semver version: ${input}`);
  }
  return {
    version: match[2]
  };
}
VO65XOWD_cjs.__name(findSemVersionFromString, "findSemVersionFromString");
function validateToolVersion(toolName, version) {
  const supportedVersions = getToolSupportedVersions(toolName);
  return supportedVersions.includes(version);
}
VO65XOWD_cjs.__name(validateToolVersion, "validateToolVersion");

// src/config/tools.ts
var solanaDefaultVolumes = [
  {
    type: "isolate",
    containerPath: "/usr/local/cargo",
    name: "cargo"
  },
  {
    type: "isolate",
    containerPath: "/usr/local/rustup",
    name: "rustup"
  },
  {
    type: "isolate",
    containerPath: "/var/lib/docker",
    name: "docker"
  }
];
var tools = [
  {
    name: "hardhat",
    toolType: "evm",
    fromImage: "evm",
    defaultVolumes: []
  },
  {
    name: "forge",
    toolType: "evm",
    fromImage: "evm"
  },
  {
    name: "anchor",
    toolType: "solana",
    fromImage: "solana",
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersionCheckValue: /* @__PURE__ */ VO65XOWD_cjs.__name(({ cwd }) => {
      return parseAnchorTomlVersion(cwd, "anchor");
    }, "getSecondaryVersionCheckValue")
  },
  {
    name: "solana",
    toolType: "solana",
    fromImage: "solana",
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersionCheckValue: /* @__PURE__ */ VO65XOWD_cjs.__name(({ cwd }) => {
      return parseAnchorTomlVersion(cwd, "solana");
    }, "getSecondaryVersionCheckValue")
  },
  {
    name: "aptos",
    toolType: "aptos",
    fromImage: "aptos",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "aptos"
      }
    ]
  },
  {
    name: "initiad",
    toolType: "initia",
    fromImage: "initia",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "initia"
      }
    ]
  },
  {
    name: "blueprint",
    toolType: "ton",
    fromImage: "ton"
  },
  {
    name: "scarb",
    toolType: "starknet",
    fromImage: "starknet"
  },
  {
    name: "sui",
    toolType: "sui",
    fromImage: "sui",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "sui"
      },
      {
        type: "isolate",
        containerPath: "/root/.sui",
        name: "sui-config",
        shared: true,
        locked: true
      }
    ]
  },
  {
    name: "stellar",
    toolType: "stellar",
    fromImage: "stellar",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.config/stellar",
        name: "stellar-config",
        shared: true,
        locked: true
      },
      {
        type: "isolate",
        containerPath: "/usr/local/cargo",
        name: "stellar-cargo",
        shared: true,
        locked: false
      }
    ]
  }
];

// src/config/index.ts
var AWS_ACCOUNT_ID = "438003944538";
var AWS_REGION = "us-east-1";

// src/utils/finder-utils.ts
function findToolByName(toolName) {
  return tools.find((tool) => tool.name === toolName);
}
VO65XOWD_cjs.__name(findToolByName, "findToolByName");
function findToolsByType(type) {
  return tools.filter((tool) => tool.toolType === type);
}
VO65XOWD_cjs.__name(findToolsByType, "findToolsByType");
function getToolType(toolName) {
  const tool = findToolByName(toolName);
  return tool?.toolType;
}
VO65XOWD_cjs.__name(getToolType, "getToolType");
function findMatrixByType(type) {
  return EDZNH6J4_cjs.versionMatrices.find((matrix) => matrix.toolType === type);
}
VO65XOWD_cjs.__name(findMatrixByType, "findMatrixByType");
function findDefaultCombination(matrix) {
  const recommended = matrix.combinations.find((combo) => combo.isRecommended === true);
  if (recommended) {
    return recommended;
  }
  if (matrix.combinations.length === 0) {
    throw new Error(`No combinations found in matrix for type '${matrix.toolType}'`);
  }
  return matrix.combinations[0];
}
VO65XOWD_cjs.__name(findDefaultCombination, "findDefaultCombination");
function getToolDefaultVersion(toolName) {
  const tool = findToolByName(toolName);
  if (!tool) {
    throw new Error(`Tool '${toolName}' not found`);
  }
  const matrix = findMatrixByType(tool.toolType);
  if (!matrix) {
    throw new Error(`No version matrix found for tool type '${tool.toolType}'`);
  }
  const defaultCombination = findDefaultCombination(matrix);
  const defaultVersion = defaultCombination.versions[toolName];
  if (!defaultVersion?.length) {
    console.warn(`No default version found for tool '${toolName}' in matrix`);
    return null;
  }
  return defaultVersion;
}
VO65XOWD_cjs.__name(getToolDefaultVersion, "getToolDefaultVersion");
function getToolSupportedVersions(toolName) {
  const tool = findToolByName(toolName);
  if (!tool) {
    throw new Error(`Tool '${toolName}' not found`);
  }
  const matrix = findMatrixByType(tool.toolType);
  if (!matrix) {
    throw new Error(`No version matrix found for tool type '${tool.toolType}'`);
  }
  const versions = /* @__PURE__ */ new Set();
  for (const combination of matrix.combinations) {
    const version = combination.versions[toolName];
    if (version != null && version.length > 0) {
      versions.add(version);
    }
  }
  return Array.from(versions).sort();
}
VO65XOWD_cjs.__name(getToolSupportedVersions, "getToolSupportedVersions");

exports.AWS_ACCOUNT_ID = AWS_ACCOUNT_ID;
exports.AWS_REGION = AWS_REGION;
exports.findDefaultCombination = findDefaultCombination;
exports.findMatrixByType = findMatrixByType;
exports.findSemVersionFromString = findSemVersionFromString;
exports.findToolByName = findToolByName;
exports.findToolsByType = findToolsByType;
exports.getToolDefaultVersion = getToolDefaultVersion;
exports.getToolSupportedVersions = getToolSupportedVersions;
exports.getToolType = getToolType;
exports.parseAnchorTomlVersion = parseAnchorTomlVersion;
exports.tools = tools;
exports.validateToolVersion = validateToolVersion;
exports.versionsSatisfied = versionsSatisfied;
//# sourceMappingURL=DWHHPWIY.cjs.map
//# sourceMappingURL=DWHHPWIY.cjs.map