"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 socket_exports = {};
__export(socket_exports, {
  getOsHomeDir: () => getOsHomeDir,
  getOsTmpDir: () => getOsTmpDir,
  getSocketAppCacheDir: () => getSocketAppCacheDir,
  getSocketAppCacheTtlDir: () => getSocketAppCacheTtlDir,
  getSocketAppDir: () => getSocketAppDir,
  getSocketCacacheDir: () => getSocketCacacheDir,
  getSocketCliDir: () => getSocketCliDir,
  getSocketDlxDir: () => getSocketDlxDir,
  getSocketHomePath: () => getSocketHomePath,
  getSocketRegistryDir: () => getSocketRegistryDir,
  getSocketRegistryGithubCacheDir: () => getSocketRegistryGithubCacheDir,
  getSocketUserDir: () => getSocketUserDir,
  getSocketWheelhouseDir: () => getSocketWheelhouseDir,
  getUserHomeDir: () => getUserHomeDir
});
module.exports = __toCommonJS(socket_exports);
var import_github = require("../constants/github");
var import_socket = require("../constants/socket");
var import_home = require("../env/home");
var import_socket2 = require("../env/socket");
var import_windows = require("../env/windows");
var import_dirnames = require("./dirnames");
var import_normalize = require("./normalize");
var import_rewire = require("./rewire");
var import_os = require("../node/os");
var import_path = require("../node/path");
function getOsHomeDir() {
  return (0, import_rewire.getPathValue)("homedir", () => (0, import_os.getNodeOs)().homedir());
}
function getOsTmpDir() {
  return (0, import_rewire.getPathValue)("tmpdir", () => (0, import_os.getNodeOs)().tmpdir());
}
function getSocketAppCacheDir(appName) {
  return (0, import_normalize.normalizePath)((0, import_path.getNodePath)().join(getSocketAppDir(appName), import_dirnames.CACHE_DIR));
}
function getSocketAppCacheTtlDir(appName) {
  return (0, import_normalize.normalizePath)(
    (0, import_path.getNodePath)().join(getSocketAppCacheDir(appName), import_dirnames.CACHE_TTL_DIR)
  );
}
function getSocketAppDir(appName) {
  return (0, import_normalize.normalizePath)(
    (0, import_path.getNodePath)().join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}${appName}`)
  );
}
function getSocketCacacheDir() {
  return (0, import_rewire.getPathValue)("socket-cacache-dir", () => {
    if ((0, import_socket2.getSocketCacacheDirEnv)()) {
      return (0, import_normalize.normalizePath)((0, import_socket2.getSocketCacacheDirEnv)());
    }
    return (0, import_normalize.normalizePath)(
      (0, import_path.getNodePath)().join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}cacache`)
    );
  });
}
function getSocketCliDir() {
  return getSocketAppDir(import_socket.SOCKET_CLI_APP_NAME);
}
function getSocketDlxDir() {
  return (0, import_rewire.getPathValue)("socket-dlx-dir", () => {
    if ((0, import_socket2.getSocketDlxDirEnv)()) {
      return (0, import_normalize.normalizePath)((0, import_socket2.getSocketDlxDirEnv)());
    }
    return (0, import_normalize.normalizePath)(
      (0, import_path.getNodePath)().join(
        getSocketUserDir(),
        `${import_socket.SOCKET_APP_PREFIX}${import_socket.SOCKET_DLX_APP_NAME}`
      )
    );
  });
}
function getSocketHomePath() {
  return getSocketUserDir();
}
function getSocketRegistryDir() {
  return getSocketAppDir(import_socket.SOCKET_REGISTRY_APP_NAME);
}
function getSocketRegistryGithubCacheDir() {
  return (0, import_normalize.normalizePath)(
    (0, import_path.getNodePath)().join(
      getSocketAppCacheTtlDir(import_socket.SOCKET_REGISTRY_APP_NAME),
      import_github.CACHE_GITHUB_DIR
    )
  );
}
function getSocketUserDir() {
  return (0, import_rewire.getPathValue)("socket-user-dir", () => {
    const socketHome = (0, import_socket2.getSocketHome)();
    if (socketHome) {
      return (0, import_normalize.normalizePath)(socketHome);
    }
    return (0, import_normalize.normalizePath)((0, import_path.getNodePath)().join(getUserHomeDir(), import_dirnames.DOT_SOCKET_DIR));
  });
}
function getSocketWheelhouseDir() {
  return (0, import_rewire.getPathValue)("socket-wheelhouse-dir", () => {
    return (0, import_normalize.normalizePath)(
      (0, import_path.getNodePath)().join(
        getSocketUserDir(),
        `${import_socket.SOCKET_APP_PREFIX}${import_socket.SOCKET_WHEELHOUSE_APP_NAME}`
      )
    );
  });
}
function getUserHomeDir() {
  const home = (0, import_home.getHome)();
  if (home) {
    return home;
  }
  const userProfile = (0, import_windows.getUserprofile)();
  if (userProfile) {
    return userProfile;
  }
  try {
    const osHome = getOsHomeDir();
    if (osHome) {
      return osHome;
    }
  } catch {
  }
  return getOsTmpDir();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getOsHomeDir,
  getOsTmpDir,
  getSocketAppCacheDir,
  getSocketAppCacheTtlDir,
  getSocketAppDir,
  getSocketCacacheDir,
  getSocketCliDir,
  getSocketDlxDir,
  getSocketHomePath,
  getSocketRegistryDir,
  getSocketRegistryGithubCacheDir,
  getSocketUserDir,
  getSocketWheelhouseDir,
  getUserHomeDir
});
