Skip to content

feat(oxfmt): use prettier directly and bundle prettier#15544

Merged
graphite-app[bot] merged 1 commit intomainfrom
11-10-feat_oxfmt_bundle_prettier_and_prettier_sync
Nov 10, 2025
Merged

feat(oxfmt): use prettier directly and bundle prettier#15544
graphite-app[bot] merged 1 commit intomainfrom
11-10-feat_oxfmt_bundle_prettier_and_prettier_sync

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Nov 10, 2025

@prettier/sync is the synchronous version of prettier, which uses the Worker to hack it and make it synchronous.

Everything worked fine before we wanted to bundle them together. However, it hangs when they are bundled. I haven't found the reason why it hangs. Anyway, I don't think @prettier/sync is a good choice because it is not real synchronous, which sacrifices some performance to make it available.

Note: I am not familiar with NAPI, so I'm not sure whether the API is used correctly.

@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Nov 10, 2025
Copy link
Member Author

Dunqing commented Nov 10, 2025


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.

@Dunqing Dunqing changed the title feat(oxfmt): bundle prettier and @prettier/sync feat(oxfmt): use prettier directly and bundle prettier Nov 10, 2025
@Dunqing Dunqing force-pushed the 11-10-feat_oxfmt_bundle_prettier_and_prettier_sync branch 2 times, most recently from 54d55d3 to 8dcee8c Compare November 10, 2025 07:47
@Dunqing Dunqing marked this pull request as ready for review November 10, 2025 07:57
Copilot AI review requested due to automatic review settings November 10, 2025 07:57
@Dunqing Dunqing requested review from Boshen and leaysgur November 10, 2025 07:57
Copy link
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 migrates from the synchronous @prettier/sync package to the standard async prettier package for formatting embedded languages (CSS, GraphQL, HTML, Markdown) in template literals.

Key changes:

  • Removes the @prettier/sync dependency in favor of the standard async prettier package
  • Updates the TypeScript/JavaScript code to use async/await pattern with Promises
  • Modifies the Rust FFI layer to handle Promise return types using block_on to await promise resolution
  • Configures bundler to include prettier as an internal dependency

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Removes @prettier/sync dependency from the lockfile
apps/oxfmt/package.json Removes @prettier/sync from dependencies
apps/oxfmt/tsdown.config.ts Configures bundler to bundle prettier instead of treating it as external
apps/oxfmt/src-js/embedded.ts Converts formatEmbeddedCode from sync to async, returns Promise and uses promise chaining
apps/oxfmt/src/run.rs Changes parameter type from reference to owned Vec to avoid unnecessary allocation
apps/oxfmt/src/prettier_plugins/external_formatter.rs Updates type signatures to handle Promise<String> and uses block_on to await promise resolution
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@leaysgur
Copy link
Member

I think this would be ideal if there were no drawbacks.

Let me try, run benchmark locally.

Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

LGTM.

Now we can remove dependencies field from npm/oxfmt/package.json.

"dependencies": {

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 10, 2025
Copy link
Member Author

Dunqing commented Nov 10, 2025

Merge activity

`@prettier/sync` is the synchronous version of `prettier`, which uses the `Worker` to hack it and make it synchronous.

Everything worked fine before we wanted to bundle them together. However, it hangs when they are bundled. I haven't found the reason why it hangs. Anyway, I don't think `@prettier/sync` is a good choice because it is not `real` synchronous, which sacrifices some performance to make it available.

Note: I am not familiar with NAPI, so I'm not sure whether the API is used correctly.
@graphite-app graphite-app bot force-pushed the 11-10-feat_oxfmt_bundle_prettier_and_prettier_sync branch from 0dd7326 to 3251000 Compare November 10, 2025 08:24
@graphite-app graphite-app bot merged commit 3251000 into main Nov 10, 2025
19 checks passed
@graphite-app graphite-app bot deleted the 11-10-feat_oxfmt_bundle_prettier_and_prettier_sync branch November 10, 2025 08:30
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 10, 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.

4 participants