"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 packages_exports = {};
__export(packages_exports, {
  AT_LATEST: () => AT_LATEST,
  LATEST: () => LATEST,
  PACKAGE: () => PACKAGE,
  PACKAGE_DEFAULT_VERSION: () => PACKAGE_DEFAULT_VERSION,
  clearPackumentCache: () => clearPackumentCache,
  getLifecycleScriptNames: () => getLifecycleScriptNames,
  getPackageDefaultNodeRange: () => getPackageDefaultNodeRange,
  getPackageDefaultSocketCategories: () => getPackageDefaultSocketCategories,
  getPackageExtensions: () => getPackageExtensions,
  getPackumentCache: () => getPackumentCache,
  getPacoteCachePath: () => getPacoteCachePath
});
module.exports = __toCommonJS(packages_exports);
var import_pacote = __toESM(require("../external/pacote"));
var import_data = require("../pkg-ext/data");
var import_normalize = require("../paths/normalize");
var import_lifecycle_script_names = require("./lifecycle-script-names");
var import_package_default_node_range = require("./package-default-node-range");
var import_package_default_socket_categories = require("./package-default-socket-categories");
var import_array = require("../primordials/array");
var import_object = require("../primordials/object");
var import_reflect = require("../primordials/reflect");
let _lifecycleScriptNames;
let _packageDefaultNodeRange;
let _packageDefaultSocketCategories;
let _packageExtensions;
let _pacoteCachePath;
let _packumentCache;
const PACKAGE = "package";
const AT_LATEST = "@latest";
const LATEST = "latest";
const PACKAGE_DEFAULT_VERSION = "1.0.0";
function clearPackumentCache() {
  if (_packumentCache !== void 0) {
    _packumentCache.clear();
  }
}
// @__NO_SIDE_EFFECTS__
function getLifecycleScriptNames() {
  if (_lifecycleScriptNames === void 0) {
    _lifecycleScriptNames = (0, import_array.ArrayFrom)(import_lifecycle_script_names.lifecycleScriptNames);
  }
  return _lifecycleScriptNames;
}
// @__NO_SIDE_EFFECTS__
function getPackageDefaultNodeRange() {
  if (_packageDefaultNodeRange === void 0) {
    _packageDefaultNodeRange = import_package_default_node_range.packageDefaultNodeRange;
  }
  return _packageDefaultNodeRange;
}
// @__NO_SIDE_EFFECTS__
function getPackageDefaultSocketCategories() {
  if (_packageDefaultSocketCategories === void 0) {
    _packageDefaultSocketCategories = import_package_default_socket_categories.packageDefaultSocketCategories;
  }
  return _packageDefaultSocketCategories;
}
// @__NO_SIDE_EFFECTS__
function getPackageExtensions() {
  if (_packageExtensions === void 0) {
    _packageExtensions = (0, import_object.ObjectEntries)(import_data.packageExtensions);
  }
  return _packageExtensions;
}
const PACKUMENT_CACHE_MAX = 500;
class BoundedPackumentCache extends Map {
  set(key, value) {
    if (this.has(key)) {
      this.delete(key);
    } else if (this.size >= PACKUMENT_CACHE_MAX) {
      const oldest = this.keys().next().value;
      if (oldest !== void 0) {
        this.delete(oldest);
      }
    }
    return super.set(key, value);
  }
}
// @__NO_SIDE_EFFECTS__
function getPackumentCache() {
  if (_packumentCache === void 0) {
    _packumentCache = new BoundedPackumentCache();
  }
  return _packumentCache;
}
// @__NO_SIDE_EFFECTS__
function getPacoteCachePath() {
  if (_pacoteCachePath === void 0) {
    try {
      const proto = (0, import_reflect.ReflectGetPrototypeOf)(
        import_pacote.default.RegistryFetcher.prototype
      );
      const PacoteFetcherBase = proto?.constructor;
      const cachePath = PacoteFetcherBase ? new PacoteFetcherBase(
        /*dummy package spec*/
        "x",
        {}
      ).cache : "";
      _pacoteCachePath = cachePath ? (0, import_normalize.normalizePath)(cachePath) : "";
    } catch {
      _pacoteCachePath = "";
    }
  }
  return _pacoteCachePath;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AT_LATEST,
  LATEST,
  PACKAGE,
  PACKAGE_DEFAULT_VERSION,
  clearPackumentCache,
  getLifecycleScriptNames,
  getPackageDefaultNodeRange,
  getPackageDefaultSocketCategories,
  getPackageExtensions,
  getPackumentCache,
  getPacoteCachePath
});
