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

//#region src/external-tools/cdxgen/from-download.ts
/**
* @file `cdxgenFromDownload()` — fetches the upstream cdxgen SEA binary (slim
*   by default) and returns a `ResolvedCdxgen` pointing at the cached
*   executable. cdxgen ships bare-binary assets per platform (no archive
*   wrapper) with sidecar `.sha256` files; this helper passes the pinned
*   integrity through `downloadToolArchive`, then copies the downloaded blob to
*   `cdxgen[.exe]` and chmods it 0o755. Platforms upstream doesn't ship a SEA
*   for (none today; the asset map covers all 8 fleet targets) return
*   `undefined` — callers should fall back to `cdxgenFromNpm()` for those.
*/
async function cdxgenFromDownload(opts) {
	const { cacheDir, downloader, integrity, platformArch, variant = "slim", version } = opts;
	const url = require_external_tools_cdxgen_asset_names.getCdxgenDownloadUrl({
		platformArch,
		variant,
		version
	});
	const entry = require_external_tools_cdxgen_asset_names.getCdxgenAssetEntry(platformArch, variant);
	if (!url || !entry) return;
	const archive = await require_external_tools_from_download.downloadToolArchive({
		url,
		name: `cdxgen-${version}-${platformArch}-${variant}-${entry.asset}`,
		integrity,
		downloader
	});
	const targetDir = cacheDir ?? node_path.default.join(require_paths_socket.getSocketDlxDir(), "cdxgen", version, `${platformArch}-${variant}`);
	await require_fs_safe.safeMkdir(targetDir);
	const ext = node_process.default.platform === "win32" ? ".exe" : "";
	const finalPath = node_path.default.join(targetDir, `cdxgen${ext}`);
	await node_fs.promises.copyFile(archive.archivePath, finalPath);
	await node_fs.promises.chmod(finalPath, 493);
	return {
		path: finalPath,
		source: "download",
		integrity: archive.integrity
	};
}

//#endregion
exports.cdxgenFromDownload = cdxgenFromDownload;