Skip to content

Generated TypeScript formatting

State: open/verified · Kind: module · Audience: system

  • Formats ontogen-generated TypeScript by shelling out to the repo’s own prettier through bun 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.

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.

  • format_ts(src, path, cwd): formats a string; path resolves config and parser, cwd resolves 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_AGENT and CLAUDECODE from the child environment and rejects stdout starting with {, catching proto’s NDJSON banner ahead of prettier’s output.
  • packages/rust/prettier-fmt/src/lib.rs: format_ts, format_file_in_place.
  • packages/rust/prettier-fmt/
  • packages/rust/prettier-fmt/src/lib.rs#format_ts
  • packages/rust/prettier-fmt/src/lib.rs#format_file_in_place

← Back to Capabilities