Generated TypeScript formatting
State: open/verified · Kind: module · Audience: system
Summary
Section titled “Summary”- Formats ontogen-generated TypeScript by shelling out to the repo’s own
prettierthroughbun x, so generated code carries the same style as the hand-written code beside it. - Every failure names its cause (missing
bun, unresolved prettier, non-zero exit, empty output, captured diagnostic banner) instead of returning unformatted bytes.
Statement
Section titled “Statement”prettier-fmt is a dependency-free crate that formats a TypeScript string or file by spawning bun x prettier --stdin-filepath <path> from a caller-chosen working directory. Config resolution and
the prettier binary both come from the repo workspace, not a Rust-side reimplementation. It replaced
biome-fmt, which pulled five biome crates from a git tag to do the same job in-process. Every
codegen consumer wires it in as a build-time TsFormatter, trading hermeticity (bun and
node_modules must exist at build time) for one house style and one pinned prettier version.
What it provides
Section titled “What it provides”format_ts(src, path, cwd): formats a string;pathresolves config and parser,cwdresolves the binary.format_file_in_place(path, cwd): rewrites a file only when the output differs, so an unchanged file keeps its mtime.- A named error for every failure mode.
- A guard that strips
AI_AGENTandCLAUDECODEfrom the child environment and rejects stdout starting with{, catching proto’s NDJSON banner ahead of prettier’s output.
Underlying implementation
Section titled “Underlying implementation”packages/rust/prettier-fmt/src/lib.rs:format_ts,format_file_in_place.
Locations
Section titled “Locations”packages/rust/prettier-fmt/packages/rust/prettier-fmt/src/lib.rs#format_tspackages/rust/prettier-fmt/src/lib.rs#format_file_in_place