"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_opengrep_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);

//#region src/external-tools/opengrep/from-download.ts
/**
* @file `opengrepFromDownload()` — fetches upstream OpenGrep and returns a
*   `ResolvedOpengrep` pointing at the cached binary. macOS/Linux assets are
*   bare binaries (no extraction); Windows ships a zip. The asset-map's
*   `isArchive` flag drives extraction vs. copy.
*/
async function opengrepFromDownload(opts) {
	const { cacheDir, downloader, integrity, platformArch, version } = opts;
	const url = require_external_tools_opengrep_asset_names.getOpengrepDownloadUrl({
		version,
		platformArch
	});
	const entry = require_external_tools_opengrep_asset_names.getOpengrepAssetEntry(platformArch);
	if (!url || !entry) return;
	const targetDir = cacheDir ?? node_path.default.join(require_paths_socket.getSocketDlxDir(), "opengrep", version, platformArch);
	if (entry.isArchive) {
		const archive = await require_external_tools_from_download.downloadAndExtractTool({
			url,
			name: `opengrep-${version}-${platformArch}-${entry.asset}`,
			integrity,
			extractedDir: targetDir,
			downloader
		});
		return {
			path: node_path.default.join(targetDir, entry.binaryInArchive),
			source: "download",
			integrity: archive.integrity
		};
	}
	const archive = await require_external_tools_from_download.downloadToolArchive({
		url,
		name: `opengrep-${version}-${platformArch}-${entry.asset}`,
		integrity,
		downloader
	});
	await require_fs_safe.safeMkdir(targetDir);
	const finalPath = node_path.default.join(targetDir, "opengrep");
	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.opengrepFromDownload = opengrepFromDownload;