"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 parse_lockfile_exports = {};
__export(parse_lockfile_exports, {
  jsParseLockfile: () => jsParseLockfile,
  parseLockfile: () => parseLockfile,
  sniffLockfileFormat: () => sniffLockfileFormat
});
module.exports = __toCommonJS(parse_lockfile_exports);
var import_manifest_error = require("./manifest-error");
var import_parse_lockfile = require("../cargo/parse-lockfile");
var import_parse_lockfile2 = require("../npm/npm/parse-lockfile");
var import_parse_lockfile3 = require("../npm/pnpm/parse-lockfile");
var import_parse_lockfile4 = require("../npm/yarnpkg/yarn/parse-lockfile");
var import_string = require("../../primordials/string");
var import_manifest = require("../../smol/manifest");
function jsParseLockfile(content, ecosystem, format) {
  if (ecosystem === "cargo") {
    return (0, import_parse_lockfile.parseCargoLock)(content);
  }
  if (ecosystem !== "npm") {
    throw new import_manifest_error.ManifestError(
      `Unsupported ecosystem: ${ecosystem}`,
      "ERR_UNSUPPORTED"
    );
  }
  const fmt = format ?? sniffLockfileFormat(content);
  switch (fmt) {
    case "npm":
      return (0, import_parse_lockfile2.parsePackageLock)(content);
    case "yarn":
      return (0, import_parse_lockfile4.parseYarnLock)(content);
    case "pnpm":
      return (0, import_parse_lockfile3.parsePnpmLock)(content);
    case "cargo":
      return (0, import_parse_lockfile.parseCargoLock)(content);
    default:
      throw new import_manifest_error.ManifestError(
        "Unable to detect lockfile format",
        "ERR_UNKNOWN_FORMAT"
      );
  }
}
function sniffLockfileFormat(content) {
  if ((0, import_string.StringPrototypeIndexOf)(content, '"lockfileVersion"') !== -1) {
    return "npm";
  }
  if ((0, import_string.StringPrototypeIndexOf)(content, "yarn lockfile") !== -1 || (0, import_string.StringPrototypeIndexOf)(content, "__metadata:") !== -1) {
    return "yarn";
  }
  if ((0, import_string.StringPrototypeIndexOf)(content, "lockfileVersion:") !== -1) {
    return "pnpm";
  }
  return void 0;
}
const _smol = (0, import_manifest.getSmolManifest)();
const parseLockfile = _smol ? (
  /* c8 ignore start - smol Node binary only. */
  (content, ecosystem, format) => _smol.parseLockfile(
    content,
    ecosystem,
    format
  )
) : (
  /* c8 ignore stop */
  jsParseLockfile
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  jsParseLockfile,
  parseLockfile,
  sniffLockfileFormat
});
