feat(oxfmt): Support oxfmt --stdin-filepath#16868
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for the --stdin-filepath option to oxfmt, enabling the formatter to read code from stdin and determine the appropriate parser based on a provided filepath. This brings oxfmt closer to feature parity with Prettier's CLI options.
Key Changes
- Introduces a new
StdinRunnerstruct that handles stdin-based formatting with filepath-based parser detection - Adds
Mode::Stdin(PathBuf)variant to handle the new CLI mode - Updates the NAPI interface to support the stdin mode with proper external formatter integration
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxfmt/src/stdin/mod.rs | New module implementing StdinRunner that reads from stdin, determines format strategy from filepath, and formats using appropriate formatter |
| apps/oxfmt/src/main_napi.rs | Updates NAPI entry point to handle Mode::Stdin by initializing and running StdinRunner with external formatter callbacks |
| apps/oxfmt/src/lib.rs | Adds stdin module to exports, gated behind napi feature flag |
| apps/oxfmt/src/cli/mod.rs | Exports FormatCommand to make it available for StdinRunner |
| apps/oxfmt/src/cli/command.rs | Adds Mode::Stdin(PathBuf) variant and --stdin-filepath CLI argument parsing |
| apps/oxfmt/src-js/cli.ts | Simplifies mode handling by consolidating Rust-handled modes into default case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
The stdin feature is largely well-integrated, but there are a few correctness/behavior concerns: StdinRunner::new can panic instead of returning a controlled CLI failure, stdin read errors are misclassified as InvalidOptionConfig, and run_lsp now always reports exit code 0 which may mask abnormal termination. Additionally, the non-napi bpaf parser was refactored in a way that’s unnecessary and could subtly change CLI behavior.
Summary of changes
Summary
This PR adds support for oxfmt --stdin-filepath (NAPI/JS entry) so formatting can read from stdin while using a provided filepath to select the parser.
Key changes
- JS CLI dispatch (
apps/oxfmt/src-js/cli.ts)- Simplified mode handling by removing explicit
"lsp"/"cli"cases and usingdefaultto applyexitCodefor all non-JS-handled modes.
- Simplified mode handling by removing explicit
- CLI mode additions (
apps/oxfmt/src/cli/command.rs)- Added
Mode::Stdin(PathBuf)behindfeature = "napi". - Added
--stdin-filepath <PATH>flag and grouped it with other mode options. - Adjusted
Modevariants to be NAPI-gated forLsp,Init, andMigrate.
- Added
- Exports & module wiring
- Re-exported
FormatCommandfromapps/oxfmt/src/cli/mod.rs. - Added new NAPI-only
stdinmodule inapps/oxfmt/src/lib.rs.
- Re-exported
- NAPI runner routing (
apps/oxfmt/src/main_napi.rs)- Added
Mode::Stdinbranch that runs a newStdinRunner. - Refactored external formatter creation to be inline for both
cliandstdin.
- Added
- New stdin implementation (
apps/oxfmt/src/stdin/mod.rs)- Introduced
StdinRunnerto read fromstdin, load config, select formatting strategy from the provided filepath, format, and write tostdout.
- Introduced
ec21ecf to
aa12bb4
Compare
oxfmt --stdin-filepath
362eb7a to
f800298
Compare
Merge activity
|
7522bed to
5e3ceb8
Compare

Fixes #14720