/* Socket Lib - Built with esbuild */
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 normalize_exports = {};
__export(normalize_exports, {
  normalizePackageJson: () => normalizePackageJson,
  resolveEscapedScope: () => resolveEscapedScope,
  resolveOriginalPackageName: () => resolveOriginalPackageName,
  unescapeScope: () => unescapeScope
});
module.exports = __toCommonJS(normalize_exports);
var import_objects = require("../objects");
const ArrayIsArray = Array.isArray;
const ObjectHasOwn = Object.hasOwn;
let _REGISTRY_SCOPE_DELIMITER;
function getRegistryScopeDelimiter() {
  if (_REGISTRY_SCOPE_DELIMITER === void 0) {
    _REGISTRY_SCOPE_DELIMITER = /*@__INLINE__*/
    require("../../constants/socket").REGISTRY_SCOPE_DELIMITER;
  }
  return _REGISTRY_SCOPE_DELIMITER;
}
let _SOCKET_REGISTRY_SCOPE;
function getSocketRegistryScope() {
  if (_SOCKET_REGISTRY_SCOPE === void 0) {
    _SOCKET_REGISTRY_SCOPE = /*@__INLINE__*/
    require("../../constants/socket").SOCKET_REGISTRY_SCOPE;
  }
  return _SOCKET_REGISTRY_SCOPE;
}
let _escapeRegExp;
function getEscapeRegExp() {
  if (_escapeRegExp === void 0) {
    _escapeRegExp = require("../regexps").escapeRegExp;
  }
  return _escapeRegExp;
}
function getEscapedScopeRegExp() {
  const REGISTRY_SCOPE_DELIMITER = getRegistryScopeDelimiter();
  const escapeRegExp = getEscapeRegExp();
  const firstChar = REGISTRY_SCOPE_DELIMITER[0];
  return new RegExp(
    `^[^${escapeRegExp(firstChar)}]+${escapeRegExp(REGISTRY_SCOPE_DELIMITER)}(?!${escapeRegExp(firstChar)})`
  );
}
let _normalizePackageData;
// @__NO_SIDE_EFFECTS__
function getNormalizePackageData() {
  if (_normalizePackageData === void 0) {
    _normalizePackageData = require("../../external/normalize-package-data");
  }
  return _normalizePackageData;
}
// @__NO_SIDE_EFFECTS__
function normalizePackageJson(pkgJson, options) {
  const { preserve } = { __proto__: null, ...options };
  if (!ObjectHasOwn(pkgJson, "version")) {
    pkgJson.version = "0.0.0";
  }
  const preserved = [
    ["_id", void 0],
    ["readme", void 0],
    ...ObjectHasOwn(pkgJson, "bugs") ? [] : [["bugs", void 0]],
    ...ObjectHasOwn(pkgJson, "homepage") ? [] : [["homepage", void 0]],
    ...ObjectHasOwn(pkgJson, "name") ? [] : [["name", void 0]],
    ...ArrayIsArray(preserve) ? preserve.map((k) => [
      k,
      ObjectHasOwn(pkgJson, k) ? pkgJson[k] : void 0
    ]) : []
  ];
  const normalizePackageData = /* @__PURE__ */ getNormalizePackageData();
  normalizePackageData(pkgJson);
  const { findPackageExtensions } = require("./operations");
  if (pkgJson.name && pkgJson.version) {
    (0, import_objects.merge)(pkgJson, findPackageExtensions(pkgJson.name, pkgJson.version));
  }
  for (const { 0: key, 1: value } of preserved) {
    pkgJson[key] = value;
  }
  return pkgJson;
}
// @__NO_SIDE_EFFECTS__
function resolveEscapedScope(sockRegPkgName) {
  const escapedScopeRegExp = getEscapedScopeRegExp();
  const match = escapedScopeRegExp.exec(sockRegPkgName)?.[0];
  return match || void 0;
}
// @__NO_SIDE_EFFECTS__
function resolveOriginalPackageName(sockRegPkgName) {
  const SOCKET_REGISTRY_SCOPE = getSocketRegistryScope();
  const name = sockRegPkgName.startsWith(`${SOCKET_REGISTRY_SCOPE}/`) ? sockRegPkgName.slice(SOCKET_REGISTRY_SCOPE.length + 1) : sockRegPkgName;
  const escapedScope = /* @__PURE__ */ resolveEscapedScope(name);
  return escapedScope ? `${/* @__PURE__ */ unescapeScope(escapedScope)}/${name.slice(escapedScope.length)}` : name;
}
// @__NO_SIDE_EFFECTS__
function unescapeScope(escapedScope) {
  const REGISTRY_SCOPE_DELIMITER = getRegistryScopeDelimiter();
  return `@${escapedScope.slice(0, -REGISTRY_SCOPE_DELIMITER.length)}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  normalizePackageJson,
  resolveEscapedScope,
  resolveOriginalPackageName,
  unescapeScope
});
//# sourceMappingURL=normalize.js.map
