Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021import { chmodSync, renameSync, writeFileSync } from "node:fs";import { join } from "node:path";import { parseBridgeConfig } from "../shared/bridgeConfig";
/** * Writes bridge.json next to the extension files so the extension can find the bridge and its token. * The file is checked with the extension's own parser first, written with mode 600, and moved into place in one step * so Chrome never reads a half-written file. */export function writeBridgeConfig(extensionDir: string, bridge: { endpoint: string; token: string }, profile: string): string { const text = JSON.stringify({ url: bridge.endpoint, token: bridge.token, profile }, null, 2) + "\n"; const checked = parseBridgeConfig(text); if (!checked.ok) throw new Error(`cannot write bridge.json:\n - ${checked.problems.join("\n - ")}`); const target = join(extensionDir, "bridge.json"); const temp = join(extensionDir, `.bridge.json.${process.pid}.tmp`); writeFileSync(temp, text, { mode: 0o600 }); chmodSync(temp, 0o600); renameSync(temp, target); return target;}