"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_synp_from_download = require('./from-download.js');
const require_external_tools_synp_from_path = require('./from-path.js');
const require_external_tools_synp_from_vfs = require('./from-vfs.js');

//#region src/external-tools/synp/resolve.ts
/**
* @file `resolveSynp()` — synp resolution entry point. Tries each source in
*   order:
*
*   1. VFS — smol binary's embedded synp (if packed)
*   2. PATH — `synp` on the system PATH
*   3. download — pinned npm package via dlx (only when `downloadIfMissing` is
*      passed) 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 { integrity, version } = opts.downloadIfMissing;
	return `dl:${version}:${integrity ?? ""}`;
}
async function doResolveSynp(opts) {
	const fromVfs = await require_external_tools_synp_from_vfs.synpFromVfs();
	/* c8 ignore start - smol Node binary only. */
	if (fromVfs) return fromVfs;
	/* c8 ignore stop */
	const fromPath = await require_external_tools_synp_from_path.synpFromPath();
	if (fromPath) return fromPath;
	if (opts?.downloadIfMissing) return require_external_tools_synp_from_download.synpFromDownload(opts.downloadIfMissing);
}
/* c8 ignore start - test-only escape hatch. */
function resetSynpResolution() {
	resolutionCache.clear();
}
/* c8 ignore stop */
function resolveSynp(opts) {
	const key = cacheKey(opts);
	let cached = resolutionCache.get(key);
	if (!cached) {
		cached = doResolveSynp(opts);
		resolutionCache.set(key, cached);
	}
	return cached;
}

//#endregion
exports.cacheKey = cacheKey;
exports.doResolveSynp = doResolveSynp;
exports.resetSynpResolution = resetSynpResolution;
exports.resolveSynp = resolveSynp;