Skip to content

Export public sorting APIs to /sorter#438

Merged
Boshen merged 15 commits intotailwindlabs:mainfrom
Dunqing:feat/public-api
Feb 5, 2026
Merged

Export public sorting APIs to /sorter#438
Boshen merged 15 commits intotailwindlabs:mainfrom
Dunqing:feat/public-api

Conversation

@Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Feb 4, 2026

Continue work on https://github.com/tailwindlabs/prettier-plugin-tailwindcss/tree/feat/public-api

close: #430

Some differences from #430

  1. Export sorting APIs to /sorter, which is a more descriptive entry point
  2. Removed formatterConfigPath, I found this is useless, it is only used to log a warning, I think log base is okay.
  3. Minor API modification

Extra Optimization

843a4dc made an optimization to avoid unnecessary resolution of the Prettier configuration, which is quite expensive!

I think the following dub benchmark is at least half as fast due to this optimization because this repo has no Tailwind configuration set.

Benchmark

Note: new means the current branch, old means the latest package in npm, so it includes a few optimizations that have already been merged into the main branch, not all in this branch.

Benchmark repo: https://github.com/dubinc/dub

Benchmark 1: prettier-tailwindcss-new
  Time (mean ± σ):      8.038 s ±  0.216 s    [User: 12.546 s, System: 0.836 s]
  Range (min … max):    7.886 s …  8.191 s    2 runs
 
Benchmark 2: prettier-tailwindcss-old
  Time (mean ± σ):     11.923 s ±  0.060 s    [User: 14.954 s, System: 2.520 s]
  Range (min … max):   11.881 s … 11.966 s    2 runs
 
Benchmark 3: oxfmt-new
  Time (mean ± σ):     999.8 ms ±  32.1 ms    [User: 8968.9 ms, System: 2246.7 ms]
  Range (min … max):   977.2 ms … 1022.5 ms    2 runs
 
Benchmark 4: oxfmt-old
  Time (mean ± σ):      1.628 s ±  0.027 s    [User: 13.239 s, System: 4.980 s]
  Range (min … max):    1.609 s …  1.647 s    2 runs
 
Summary
  oxfmt-new ran
    1.63 ± 0.06 times faster than oxfmt-old
    8.04 ± 0.34 times faster than prettier-tailwindcss-new
   11.93 ± 0.39 times faster than prettier-tailwindcss-old

Benchmark repo: https://github.com/tailwindcsslab/headlessui

Benchmark 1: prettier-tailwindcss-new
  Time (mean ± σ):      3.588 s ±  0.056 s    [User: 6.432 s, System: 0.361 s]
  Range (min … max):    3.551 s …  3.670 s    4 runs
 
Benchmark 2: prettier-tailwindcss-old
  Time (mean ± σ):      4.134 s ±  0.108 s    [User: 6.919 s, System: 0.611 s]
  Range (min … max):    4.030 s …  4.246 s    4 runs
 
Benchmark 3: oxfmt-new
  Time (mean ± σ):     778.8 ms ±  28.9 ms    [User: 7633.6 ms, System: 912.9 ms]
  Range (min … max):   738.3 ms … 806.9 ms    4 runs
 
Benchmark 4: oxfmt-old
  Time (mean ± σ):      1.033 s ±  0.034 s    [User: 10.048 s, System: 1.454 s]
  Range (min … max):    0.994 s …  1.073 s    4 runs
 
Summary
  oxfmt-new ran
    1.33 ± 0.07 times faster than oxfmt-old
    5.61 ± 0.19 times faster than prettier-tailwindcss-new
    6.31 ± 0.24 times faster than prettier-tailwindcss-old

@Boshen Boshen changed the title Export public sorting APIs to /lib Export public sorting APIs to /sorter Feb 5, 2026
@Dunqing Dunqing marked this pull request as ready for review February 5, 2026 08:58
@Boshen Boshen merged commit ecdf567 into tailwindlabs:main Feb 5, 2026
1 check passed

/**
* Get a Tailwind CSS API instance based on the provided options.
* @internal
Copy link

@hyoban hyoban Feb 9, 2026

Choose a reason for hiding this comment

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

May I ask why this isn't being exported as a public API? @Dunqing

I think this is very helpful for those who want to implement other tailwind integrations.

Copy link
Contributor Author

@Dunqing Dunqing Feb 9, 2026

Choose a reason for hiding this comment

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

There is no usage in the Oxfmt. We can use createSorter directly, which has already called getTailwindConfig inside.

What is your reason for using getTailwindConfig rather than createSorter?

Copy link

@hyoban hyoban Feb 9, 2026

Choose a reason for hiding this comment

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

To my knowledge, the design system also offers several additional methods.

https://github.com/tailwindlabs/tailwindcss/blob/8ed67bf5510d8435d2be766b25245abe15b3bcef/packages/tailwindcss/src/design-system.ts#L35-L68

Maybe we can create an access layer compatible with v3 and v4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is out of scope for this plugin. This is not a library for those who want to build something on top of Tailwind CSS.

Speaking of which, I personally think some of the resolving logic should move into tailwindcss and export a public method from it; that would be very useful.

graphite-app bot pushed a commit to oxc-project/oxc that referenced this pull request Feb 9, 2026
### Resolve issues:
* close: #18072

The new version of `prettier-plugin-tailwindcss` solved all root causes mentioned in the description of the above issue, see the commit history at https://github.com/tailwindlabs/prettier-plugin-tailwindcss/commits/main/

* close: #17972
* close: #18459
* close: #18628

These three issues are related to resolving the TailwindCSS configuration of that plugin, the new version decoupled with Prettier, and provides a public `createSorter` sorting API to `/sorter`, so that we can configure `base` correctly, which is the key for the plugin to resolve `stylesheet` and `config` from `base`.

### Key change on Oxfmt side

In this PR, the `stylesheets` and `config` options are normalized to absolute paths using the Oxfmt configuration directory before calling `createSorter` and delegating to `Prettier`.

The reason is as follows:

For formatting non-JS/TS files, Oxfmt delegates to Prettier. Therefore, we should continue using `prettier-plugin-tailwindcss` to handle this, ensuring that Prettier's configuration resolution remains intact. I made a change in [that plugin](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/blob/125a8bc77639529a5a0c7e4e8a02174d7ed2d70b/src/config.ts#L50-L54) to prevent resolution when both `stylesheet` and `config` are absolute paths. This change is valid and could enhance the plugin's performance for both Oxfmt and Prettier users. The plugin needs to resolve the Prettier configuration to obtain the directory of the configuration file and join it with `stylesheet` and `config`. If they are already absolute, there is no need to join them.

### Benchmark
> Copy from tailwindlabs/prettier-plugin-tailwindcss#438

Note: `new` means the current branch, `old` means the latest package in npm, so it includes a few optimizations that have already been merged into the main branch, not all in this branch.

Benchmark repo: https://github.com/dubinc/dub
```shell
Benchmark 3: oxfmt-new
  Time (mean ± σ):     999.8 ms ±  32.1 ms    [User: 8968.9 ms, System: 2246.7 ms]
  Range (min … max):   977.2 ms … 1022.5 ms    2 runs

Benchmark 4: oxfmt-old
  Time (mean ± σ):      1.628 s ±  0.027 s    [User: 13.239 s, System: 4.980 s]
  Range (min … max):    1.609 s …  1.647 s    2 runs

Summary
  oxfmt-new ran
    1.63 ± 0.06 times faster than oxfmt-old
```

Benchmark repo: https://github.com/tailwindcsslab/headlessui

```shell
Benchmark 3: oxfmt-new
  Time (mean ± σ):     778.8 ms ±  28.9 ms    [User: 7633.6 ms, System: 912.9 ms]
  Range (min … max):   738.3 ms … 806.9 ms    4 runs

Benchmark 4: oxfmt-old
  Time (mean ± σ):      1.033 s ±  0.034 s    [User: 10.048 s, System: 1.454 s]
  Range (min … max):    0.994 s …  1.073 s    4 runs

Summary
  oxfmt-new ran
    1.33 ± 0.07 times faster than oxfmt-old
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export getTailwindConfig and sortClasses for Oxfmt formatter integration

4 participants