formatText
uses node:child_process
text formatted as a file named like fileName (.ts, .tsx); undefined if oxfmt can't parse it.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { formatter } from "#codebase/tcmts/cli/fmt"; import { spawnSync } from "node:child_process"; import path from "node:path"; export function formatText(cb: Codebase, text: string, fileName: string): string | undefined { const { bin, config } = formatter(cb); const r = spawnSync( process.execPath, [bin, `--stdin-filepath=${path.basename(fileName)}`, "-c", config], { input: text, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }, ); return r.status === 0 ? r.stdout : undefined; }