"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var find_exports = {};
__export(find_exports, {
  findRealBin: () => findRealBin,
  findRealNpm: () => findRealNpm,
  findRealPnpm: () => findRealPnpm,
  findRealYarn: () => findRealYarn
});
module.exports = __toCommonJS(find_exports);
var import_node_process = __toESM(require("node:process"));
var import_platform = require("../constants/platform");
var import_home = require("../env/home");
var import_windows = require("../env/windows");
var import_xdg = require("../env/xdg");
var import_which = __toESM(require("../external/which"));
var import_array = require("../primordials/array");
var import_internal = require("./_internal");
var import_shadow = require("./shadow");
var import_which2 = require("./which");
function findRealBin(binName, commonPaths = []) {
  const fs = (0, import_internal.getFs)();
  const path = (0, import_internal.getPath)();
  for (const binPath of commonPaths) {
    if (fs.existsSync(binPath)) {
      return binPath;
    }
  }
  const allPaths = import_which.default.sync(binName, { all: true, nothrow: true }) || [];
  const pathsArray = (0, import_array.ArrayIsArray)(allPaths) ? allPaths : typeof allPaths === "string" ? [allPaths] : [];
  if (pathsArray.length === 0) {
    return void 0;
  }
  for (const binPath of pathsArray) {
    const binDir = path.dirname(binPath);
    if (!(0, import_shadow.isShadowBinPath)(binDir)) {
      return binPath;
    }
  }
  return pathsArray[0];
}
function findRealNpm() {
  const fs = (0, import_internal.getFs)();
  const path = (0, import_internal.getPath)();
  const nodeDir = path.dirname(import_node_process.default.execPath);
  const nodeDirCandidates = import_platform.WIN32 ? [path.join(nodeDir, "npm.cmd"), path.join(nodeDir, "npm")] : [path.join(nodeDir, "npm")];
  for (const candidate of nodeDirCandidates) {
    if (fs.existsSync(candidate)) {
      return candidate;
    }
  }
  const appdata = (0, import_windows.getAppdata)();
  const commonPaths = import_platform.WIN32 ? [
    appdata ? path.join(appdata, "npm", "npm.cmd") : "",
    appdata ? path.join(appdata, "npm", "npm") : "",
    "C:\\Program Files\\nodejs\\npm.cmd",
    "C:\\Program Files\\nodejs\\npm"
  ].filter(Boolean) : ["/usr/local/bin/npm", "/usr/bin/npm"];
  const result = findRealBin("npm", commonPaths);
  if (result && fs.existsSync(result)) {
    return result;
  }
  const npmPath = (0, import_which2.whichRealSync)("npm", { nothrow: true });
  if (npmPath && typeof npmPath === "string" && fs.existsSync(npmPath)) {
    return npmPath;
  }
  return "npm";
}
function findRealPnpm() {
  const path = (0, import_internal.getPath)();
  const home = (0, import_home.getHome)();
  const appdata = (0, import_windows.getAppdata)();
  const localappdata = (0, import_windows.getLocalappdata)();
  const xdgDataHome = (0, import_xdg.getXdgDataHome)();
  const commonPaths = import_platform.WIN32 ? [
    appdata ? path.join(appdata, "npm", "pnpm.cmd") : "",
    appdata ? path.join(appdata, "npm", "pnpm") : "",
    localappdata ? path.join(localappdata, "pnpm", "pnpm.cmd") : "",
    localappdata ? path.join(localappdata, "pnpm", "pnpm") : "",
    "C:\\Program Files\\nodejs\\pnpm.cmd",
    "C:\\Program Files\\nodejs\\pnpm"
  ].filter(Boolean) : [
    "/usr/local/bin/pnpm",
    "/usr/bin/pnpm",
    xdgDataHome ? path.join(xdgDataHome, "pnpm/pnpm") : home ? path.join(home, ".local/share/pnpm/pnpm") : "",
    home ? path.join(home, ".pnpm/pnpm") : ""
  ].filter(Boolean);
  return findRealBin("pnpm", commonPaths) ?? "";
}
function findRealYarn() {
  const path = (0, import_internal.getPath)();
  const home = (0, import_home.getHome)();
  const appdata = (0, import_windows.getAppdata)();
  const commonPaths = import_platform.WIN32 ? [
    appdata ? path.join(appdata, "npm", "yarn.cmd") : "",
    appdata ? path.join(appdata, "npm", "yarn") : "",
    home ? path.join(home, ".yarn/bin/yarn.cmd") : "",
    home ? path.join(home, ".yarn/bin/yarn") : "",
    "C:\\Program Files\\nodejs\\yarn.cmd",
    "C:\\Program Files\\nodejs\\yarn"
  ].filter(Boolean) : [
    "/usr/local/bin/yarn",
    "/usr/bin/yarn",
    home ? path.join(home, ".yarn/bin/yarn") : "",
    home ? path.join(home, ".config/yarn/global/node_modules/.bin/yarn") : ""
  ].filter(Boolean);
  return findRealBin("yarn", commonPaths) ?? "";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  findRealBin,
  findRealNpm,
  findRealPnpm,
  findRealYarn
});
