/** * Shared host-script helpers: repo root and small JSON/text IO. */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' /** Absolute path to the monorepo root (parent of `scripts/`). */ export function repoRoot(fromMetaUrl = import.meta.url) { return path.resolve(path.dirname(fileURLToPath(fromMetaUrl)), '..', '..') } /** * @param {string} p * @param {unknown} [fallback] */ export function readJson(p, fallback) { try { return JSON.parse(fs.readFileSync(p, 'utf8')) } catch (err) { if (arguments.length > 1) return fallback throw err } } /** @param {string} p */ export function readText(p) { return fs.readFileSync(p, 'utf8') }