"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_string = require('../../primordials/string.js');
const require_fs_read_file = require('../../fs/read-file.js');
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);

//#region src/external-tools/bazel/read-bazel-version-file.ts
/**
* @file `readBazelVersionFile(workspaceDir)` — walks up from `workspaceDir`
*   looking for a `.bazelversion` file (the Bazel/Bazelisk convention for
*   pinning the project's Bazel version). Returns the trimmed contents as a
*   version string, or `undefined` when no file is found before reaching the
*   filesystem root. The walk respects the "first `.bazelversion` wins"
*   convention used by Bazelisk itself. Some special values that
*   `.bazelversion` can hold (`latest`, `last_green`, `rolling`, etc.) are
*   returned verbatim; resolution of those into concrete X.Y.Z versions is the
*   orchestrator's job.
*/
const BAZEL_VERSION_FILE = ".bazelversion";
async function readBazelVersionFile(startDir) {
	let current = node_path.default.resolve(startDir);
	while (true) {
		const content = await /* @__PURE__ */ require_fs_read_file.safeReadFile(node_path.default.join(current, BAZEL_VERSION_FILE), { encoding: "utf8" });
		if (content !== void 0) {
			const hashIdx = require_primordials_string.StringPrototypeIndexOf(content, "#");
			const version = require_primordials_string.StringPrototypeTrim(hashIdx === -1 ? content : require_primordials_string.StringPrototypeSlice(content, 0, hashIdx));
			return version.length > 0 ? version : void 0;
		}
		const parent = node_path.default.dirname(current);
		if (parent === current) return;
		current = parent;
	}
}

//#endregion
exports.readBazelVersionFile = readBazelVersionFile;