"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var exec_exports = {};
__export(exec_exports, {
  execBin: () => execBin
});
module.exports = __toCommonJS(exec_exports);
var import_platform = require("../constants/platform");
var import_normalize = require("../paths/normalize");
var import_array = require("../primordials/array");
var import_error = require("../primordials/error");
var import_spawn = require("../spawn/spawn");
var import_internal = require("./_internal");
var import_resolve = require("./resolve");
var import_which = require("./which");
// @__NO_SIDE_EFFECTS__
async function execBin(binPath, args, options) {
  let resolvedPath;
  if ((0, import_normalize.isPath)(binPath)) {
    resolvedPath = (0, import_resolve.resolveRealBinSync)(binPath);
  } else {
    const cached = import_internal.binPathCache.get(binPath);
    if (cached) {
      if ((0, import_internal.getFs)().existsSync(cached)) {
        resolvedPath = cached;
      } else {
        import_internal.binPathCache.delete(binPath);
      }
    }
    if (!resolvedPath) {
      resolvedPath = await (0, import_which.whichReal)(binPath);
      if (typeof resolvedPath === "string") {
        import_internal.binPathCache.set(binPath, resolvedPath);
      }
    }
  }
  if (!resolvedPath) {
    const error = new import_error.ErrorCtor(
      `Binary not found: ${binPath}
Possible causes:
  - Binary "${binPath}" is not installed or not in PATH
  - Binary name is incorrect or misspelled
  - Installation directory is not in system PATH
To resolve:
  1. Verify "${binPath}" is installed: which ${binPath} (Unix) or where ${binPath} (Windows)
  2. Install the binary if missing, ex: npm install -g ${binPath}
  3. Check PATH environment variable includes the binary location`
    );
    error.code = "ENOENT";
    throw error;
  }
  const binCommand = (0, import_array.ArrayIsArray)(resolvedPath) ? resolvedPath[0] : resolvedPath;
  return await (0, import_spawn.spawn)(binCommand, args ?? [], {
    shell: import_platform.WIN32,
    ...options
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  execBin
});
