Skip to content

feat(oxfmt): Support oxfmt --stdin-filepath#16868

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-15-feat_oxfmt_support_oxfmt_--stdin-filepath
Dec 15, 2025
Merged

feat(oxfmt): Support oxfmt --stdin-filepath#16868
graphite-app[bot] merged 1 commit intomainfrom
12-15-feat_oxfmt_support_oxfmt_--stdin-filepath

Conversation

@leaysgur
Copy link
Copy Markdown
Member

@leaysgur leaysgur commented Dec 15, 2025

Fixes #14720

Copilot AI review requested due to automatic review settings December 15, 2025 05:15
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Dec 15, 2025
Copy link
Copy Markdown
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 StdinRunner struct 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.

Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 using default to apply exitCode for all non-JS-handled modes.
  • CLI mode additions (apps/oxfmt/src/cli/command.rs)
    • Added Mode::Stdin(PathBuf) behind feature = "napi".
    • Added --stdin-filepath <PATH> flag and grouped it with other mode options.
    • Adjusted Mode variants to be NAPI-gated for Lsp, Init, and Migrate.
  • Exports & module wiring
    • Re-exported FormatCommand from apps/oxfmt/src/cli/mod.rs.
    • Added new NAPI-only stdin module in apps/oxfmt/src/lib.rs.
  • NAPI runner routing (apps/oxfmt/src/main_napi.rs)
    • Added Mode::Stdin branch that runs a new StdinRunner.
    • Refactored external formatter creation to be inline for both cli and stdin.
  • New stdin implementation (apps/oxfmt/src/stdin/mod.rs)
    • Introduced StdinRunner to read from stdin, load config, select formatting strategy from the provided filepath, format, and write to stdout.

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 15, 2025 05:24
@leaysgur leaysgur force-pushed the 12-15-feat_oxfmt_support_oxfmt_--stdin-filepath branch 3 times, most recently from ec21ecf to aa12bb4 Compare December 15, 2025 05:34
@leaysgur leaysgur changed the title feat(oxfmt): Support oxfmt --stdin-filepath feat(oxfmt): Support oxfmt --stdin-filepath Dec 15, 2025
@leaysgur leaysgur force-pushed the 12-15-feat_oxfmt_support_oxfmt_--stdin-filepath branch 2 times, most recently from 362eb7a to f800298 Compare December 15, 2025 06:07
@leaysgur leaysgur requested a review from Dunqing December 15, 2025 06:18
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Dec 15, 2025
Copy link
Copy Markdown
Member

Boshen commented Dec 15, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 12-15-feat_oxfmt_support_oxfmt_--stdin-filepath branch from 7522bed to 5e3ceb8 Compare December 15, 2025 09:01
@graphite-app graphite-app bot merged commit 5e3ceb8 into main Dec 15, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-15-feat_oxfmt_support_oxfmt_--stdin-filepath branch December 15, 2025 09:07
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oxfmt: Support stdin and --stdin-filepath

4 participants