"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_map_set = require('../../primordials/map-set.js');
const require_external_tools_cdxgen_from_download = require('./from-download.js');
const require_external_tools_cdxgen_from_path = require('./from-path.js');
const require_external_tools_cdxgen_from_vfs = require('./from-vfs.js');

//#region src/external-tools/cdxgen/resolve.ts
/**
* @file `resolveCdxgen()` — cdxgen resolution entry point. Tries each source in
*   order:
*
*   1. VFS — smol binary's embedded cdxgen (if packed)
*   2. PATH — `cdxgen` on the system PATH
*   3. download — upstream SEA binary from the GitHub release (slim by default;
*      pass `variant: 'full'` for the bun+deno-bundled flavor) Single source of
*      truth: SEA binary only. No npm-package fallback — every fleet
*      platform-arch is covered by the SEA matrix, and routing through npm
*      would split the install surface in two for no benefit. Returns
*      `undefined` if all of the enabled sources miss. Memoized per
*      option-shape.
*/
const resolutionCache = new require_primordials_map_set.MapCtor();
function cacheKey(opts) {
	if (!opts?.downloadIfMissing) return "local-only";
	const { cacheDir, integrity, platformArch, variant, version } = opts.downloadIfMissing;
	const integrityKey = typeof integrity === "string" ? integrity : integrity ? `${integrity.type}:${integrity.value}` : "";
	return `dl:${version}:${platformArch}:${variant ?? "slim"}:${integrityKey}:${cacheDir ?? ""}`;
}
async function doResolveCdxgen(opts) {
	const fromVfs = await require_external_tools_cdxgen_from_vfs.cdxgenFromVfs();
	/* c8 ignore start - smol Node binary only. */
	if (fromVfs) return fromVfs;
	/* c8 ignore stop */
	const fromPath = await require_external_tools_cdxgen_from_path.cdxgenFromPath();
	if (fromPath) return fromPath;
	if (opts?.downloadIfMissing) return require_external_tools_cdxgen_from_download.cdxgenFromDownload(opts.downloadIfMissing);
}
/* c8 ignore start - test-only escape hatch. */
function resetCdxgenResolution() {
	resolutionCache.clear();
}
/* c8 ignore stop */
function resolveCdxgen(opts) {
	const key = cacheKey(opts);
	let cached = resolutionCache.get(key);
	if (!cached) {
		cached = doResolveCdxgen(opts);
		resolutionCache.set(key, cached);
	}
	return cached;
}

//#endregion
exports.cacheKey = cacheKey;
exports.doResolveCdxgen = doResolveCdxgen;
exports.resetCdxgenResolution = resetCdxgenResolution;
exports.resolveCdxgen = resolveCdxgen;