"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_string = require('../../primordials/string.js');
const require_smol_manifest = require('../../smol/manifest.js');
const require_eco_cargo_parse_lockfile = require('../cargo/parse-lockfile.js');
const require_eco_manifest_manifest_error = require('./manifest-error.js');
const require_eco_npm_npm_parse_lockfile = require('../npm/npm/parse-lockfile.js');
const require_eco_npm_pnpm_parse_lockfile = require('../npm/pnpm/parse-lockfile.js');
const require_eco_npm_yarnpkg_yarn_parse_lockfile = require('../npm/yarnpkg/yarn/parse-lockfile.js');

//#region src/eco/manifest/parse-lockfile.ts
/**
* @file `parseLockfile(content, ecosystem, format?)` — dispatches to the right
*   per-PM lockfile parser. When `format` is omitted, the content is sniffed
*   (npm `lockfileVersion`, yarn `__metadata:` or `yarn lockfile`, pnpm
*   `lockfileVersion:`). On socket-btm's smol Node binary this routes to
*   `node:smol-manifest`'s native `parseLockfile`; on stock Node it dispatches
*   to one of the `src/eco/npm/<pm>/parse-lockfile.ts` leaves. Throws
*   `ManifestError(ERR_UNSUPPORTED)` for unrecognized ecosystems, and
*   `ManifestError(ERR_UNKNOWN_FORMAT)` when content can't be sniffed.
*/
function jsParseLockfile(content, ecosystem, format) {
	if (ecosystem === "cargo") return require_eco_cargo_parse_lockfile.parseCargoLock(content);
	if (ecosystem !== "npm") throw new require_eco_manifest_manifest_error.ManifestError(`Unsupported ecosystem: ${ecosystem}`, "ERR_UNSUPPORTED");
	switch (format ?? sniffLockfileFormat(content)) {
		case "npm": return require_eco_npm_npm_parse_lockfile.parsePackageLock(content);
		case "yarn": return require_eco_npm_yarnpkg_yarn_parse_lockfile.parseYarnLock(content);
		case "pnpm": return require_eco_npm_pnpm_parse_lockfile.parsePnpmLock(content);
		case "cargo": return require_eco_cargo_parse_lockfile.parseCargoLock(content);
		default: throw new require_eco_manifest_manifest_error.ManifestError("Unable to detect lockfile format", "ERR_UNKNOWN_FORMAT");
	}
}
function sniffLockfileFormat(content) {
	if (require_primordials_string.StringPrototypeIndexOf(content, "\"lockfileVersion\"") !== -1) return "npm";
	if (require_primordials_string.StringPrototypeIndexOf(content, "yarn lockfile") !== -1 || require_primordials_string.StringPrototypeIndexOf(content, "__metadata:") !== -1) return "yarn";
	if (require_primordials_string.StringPrototypeIndexOf(content, "lockfileVersion:") !== -1) return "pnpm";
}
const _smol = /* @__PURE__ */ require_smol_manifest.getSmolManifest();
const parseLockfile = _smol ? (content, ecosystem, format) => _smol.parseLockfile(content, ecosystem, format) : jsParseLockfile;

//#endregion
exports.jsParseLockfile = jsParseLockfile;
exports.parseLockfile = parseLockfile;
exports.sniffLockfileFormat = sniffLockfileFormat;