import { readFile } from "node:fs/promises"; export function isNotFound(error: unknown): boolean { return typeof error === "object" && error !== null && "code" in error && (error as { code?: string }).code === "ENOENT"; } export async function readJsonIfExists(path: string): Promise { try { return JSON.parse(await readFile(path, "utf8")) as T; } catch (error) { if (isNotFound(error)) return undefined; throw error; } }