"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_releases_github_listing = require('../../releases/github-listing.js');
const require_external_tools_bazel_read_bazel_version_file = require('./read-bazel-version-file.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);

//#region src/external-tools/bazel/resolve-bazel-version.ts
/**
* @file `resolveBazelVersion({ cwd })` — picks the Bazel version to run for a
*   project, matching the bazelisk precedence:
*
*   1. `USE_BAZEL_VERSION` env var
*   2. `.bazelversion` walking up from `cwd`
*   3. Fallback to the latest stable release queried from GitHub Releases (via
*      socket-lib's `getLatestRelease`, which already handles GH_TOKEN auth,
*      retry, and the REST/GraphQL fallback). Returns `undefined` only if both
*      steps 2 and 3 fail with no env override — in that case the caller
*      surfaces an actionable error.
*/
async function resolveBazelVersion(options) {
	const cwd = options?.cwd ?? node_process.default.cwd();
	const envOverride = node_process.default.env["USE_BAZEL_VERSION"];
	if (envOverride && envOverride.length > 0) return envOverride;
	const fromFile = await require_external_tools_bazel_read_bazel_version_file.readBazelVersionFile(cwd);
	if (fromFile) return fromFile;
	return await require_releases_github_listing.getLatestRelease("", {
		owner: "bazelbuild",
		repo: "bazel"
	}, { nothrow: true }) ?? void 0;
	/* c8 ignore stop */
}

//#endregion
exports.resolveBazelVersion = resolveBazelVersion;