"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_primordials_error = require('../../primordials/error.js');
const require_paths_socket = require('../../paths/socket.js');
const require_external_tools_from_download = require('../from-download.js');
const require_external_tools_janus_asset_names = require('./asset-names.js');
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);

//#region src/external-tools/janus/from-download.ts
/**
* @file `janusFromDownload()` — fetches upstream janus and returns a
*   `ResolvedJanus` pointing at the extracted binary. janus ships tar.gz
*   archives containing a bare `janus` binary at the archive root (no nested
*   directory). Defaults install under the shared wheelhouse dir
*   (`~/.socket/_wheelhouse/janus/<version>/<platform-arch>/`) rather than the
*   per-process dlx cache, so multiple fleet consumers reuse the same extracted
*   binary.
*/
async function janusFromDownload(opts) {
	const { cacheDir, downloader, integrity, platformArch, version } = opts;
	if (!require_external_tools_janus_asset_names.JANUS_SUPPORTED_PLATFORM_ARCHES.includes(platformArch)) throw new require_primordials_error.ErrorCtor(`janusFromDownload: platformArch must be one of [${require_external_tools_janus_asset_names.JANUS_SUPPORTED_PLATFORM_ARCHES.map((p) => `\`${p}\``).join(", ")}], got \`${platformArch}\`. Upstream janus only publishes the macOS arm64 build (see https://github.com/divmain/janus/releases); request \`darwin-arm64\` or use a different tool for other platforms.`);
	const url = require_external_tools_janus_asset_names.getJanusDownloadUrl({
		version,
		platformArch
	});
	if (!url) throw new require_primordials_error.ErrorCtor(`janusFromDownload: no upstream asset for janus@${version} on \`${platformArch}\`. The platform is in the supported set but the version may be missing; check https://github.com/divmain/janus/releases/tag/v${version}.`);
	const extractedDir = cacheDir ?? node_path.default.join(require_paths_socket.getSocketWheelhouseDir(), "janus", version, platformArch);
	const archive = await require_external_tools_from_download.downloadAndExtractTool({
		url,
		name: `janus-${version}-${platformArch}.tar.gz`,
		integrity,
		extractedDir,
		downloader
	});
	return {
		path: node_path.default.join(extractedDir, "janus"),
		source: "download",
		integrity: archive.integrity
	};
}

//#endregion
exports.janusFromDownload = janusFromDownload;