"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 edit_exports = {};
__export(edit_exports, {
  getEditablePackageJsonClass: () => import_edit_class2.getEditablePackageJsonClass,
  toEditablePackageJson: () => toEditablePackageJson,
  toEditablePackageJsonSync: () => toEditablePackageJsonSync
});
module.exports = __toCommonJS(edit_exports);
var import_json = require("../primordials/json");
var import_normalize = require("../paths/normalize");
var import_packages = require("../paths/packages");
var import_edit_class = require("./edit-class");
var import_normalize2 = require("./normalize");
var import_edit_class2 = require("./edit-class");
// @__NO_SIDE_EFFECTS__
async function toEditablePackageJson(pkgJson, options) {
  const { path: filepath, ...restOptions } = {
    __proto__: null,
    ...options
  };
  const { normalize, ...normalizeOptions } = restOptions;
  const EditablePackageJson = (0, import_edit_class.getEditablePackageJsonClass)();
  if (typeof filepath !== "string") {
    return new EditablePackageJson().fromContent(
      normalize ? (0, import_normalize2.normalizePackageJson)(pkgJson, normalizeOptions) : pkgJson
    );
  }
  const pkgJsonPath = (0, import_packages.resolvePackageJsonDirname)(filepath);
  return (await EditablePackageJson.load(pkgJsonPath, { create: true })).fromJSON(
    `${(0, import_json.JSONStringify)(
      normalize ? (0, import_normalize2.normalizePackageJson)(pkgJson, {
        ...(0, import_normalize.isNodeModules)(pkgJsonPath) ? {} : { preserve: ["repository"] },
        ...normalizeOptions
      }) : pkgJson,
      void 0,
      2
    )}
`
  );
}
// @__NO_SIDE_EFFECTS__
function toEditablePackageJsonSync(pkgJson, options) {
  const { path: filepath, ...restOptions } = {
    __proto__: null,
    ...options
  };
  const { normalize, ...normalizeOptions } = restOptions;
  const EditablePackageJson = (0, import_edit_class.getEditablePackageJsonClass)();
  if (typeof filepath !== "string") {
    return new EditablePackageJson().fromContent(
      normalize ? (0, import_normalize2.normalizePackageJson)(pkgJson, normalizeOptions) : pkgJson
    );
  }
  const pkgJsonPath = (0, import_packages.resolvePackageJsonDirname)(filepath);
  return new EditablePackageJson().create(pkgJsonPath).fromJSON(
    `${(0, import_json.JSONStringify)(
      normalize ? (0, import_normalize2.normalizePackageJson)(pkgJson, {
        ...(0, import_normalize.isNodeModules)(pkgJsonPath) ? {} : { preserve: ["repository"] },
        ...normalizeOptions
      }) : pkgJson,
      void 0,
      2
    )}
`
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getEditablePackageJsonClass,
  toEditablePackageJson,
  toEditablePackageJsonSync
});
