"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveHookBridgePath = resolveHookBridgePath;
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
let cached = null;
/**
 * Resolve the absolute path to `bin/cockpit-hook-bridge.mjs`.
 *
 * cockpit always runs from its package root: in dev `tsx` runs from the repo
 * root; in prod `bin/cockpit.js` chdirs to the package root before importing
 * `dist/server.js`. So `bin/cockpit-hook-bridge.mjs` lives at
 * `process.cwd()/bin/cockpit-hook-bridge.mjs` in both cases.
 *
 * Allow override via COCKPIT_HOOK_BRIDGE_BIN for tests and packaging quirks.
 */
function resolveHookBridgePath() {
    if (cached)
        return cached;
    const override = process.env.COCKPIT_HOOK_BRIDGE_BIN;
    if (override && (0, node_fs_1.existsSync)(override)) {
        cached = override;
        return override;
    }
    const candidate = node_path_1.default.resolve(process.cwd(), "bin", "cockpit-hook-bridge.mjs");
    if ((0, node_fs_1.existsSync)(candidate)) {
        cached = candidate;
        return candidate;
    }
    throw new Error(`cockpit-hook-bridge.mjs not found at ${candidate}`);
}
