withTraces
uses node:path
Open the codebase's traces (.tcm/data/traces.sqlite, read only) for f, closed after; undefined if there are
none yet.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import fs from "node:fs"; import path from "node:path"; import { DatabaseSync } from "node:sqlite"; export function withTraces<T>(cb: Codebase, f: (db: DatabaseSync) => T): T | undefined { const file = path.join(cb.lay.tcmDir, "data", "traces.sqlite"); if (!fs.existsSync(file)) return undefined; const db = new DatabaseSync(file, { readOnly: true }); try { return f(db); } finally { db.close(); } }