Skip to content

Export getTailwindConfig and sortClasses for Oxfmt formatter integration #430

@Dunqing

Description

@Dunqing

Hi Tailwind CSS team! I'm a maintainer of Oxc. We're currently working on Tailwind CSS class sorting support in Oxfmt (a Rust-based JavaScript formatter aiming for 100% Prettier compatibility), and it's nearly complete. Tailwind CSS sorting is the most requested feature from users looking to migrate from Prettier to Oxfmt.

Implementation in Oxfmt

For Tailwind CSS support, we're using getTailwindConfig and sortClasses from this plugin under the hood to follow Tailwind CSS's official sorting rules. However, this package doesn't export these two functions, making it impossible to use them directly. We're currently using pnpm patch as a workaround to export them for development, but this isn't an ideal long-term solution—especially since we're patching a minified package.

Proposed Changes

In addition to exporting these two functions, we'd need small modifications to make the integration work smoothly and more performantly:

  1. Change getTailwindConfig to accept configDir and configPath (naming TBD) instead of inferring them from filepath. This allows us to avoid redundant calls to resolvePrettierConfigPath when we already have the config paths resolved on the Oxfmt side. It also avoids bundling prettier in Oxfmt, since resolvePrettierConfigPath depends on it.

  2. Re-export getTailwindConfig and sortClasses from a new file like lib.ts using the exports field to make it tree-shakeable. Currently, index.ts contains let base = await loadPlugins();, which imports all parsers and prevents tree-shaking.

Would you consider making these changes and exporting these two functions? This would greatly facilitate our integration efforts and ensure consistency with Tailwind CSS's official sorting logic. All Tailwind CSS users would benefit, as they could use a faster formatter without losing their beloved Tailwind CSS sorting feature.

I'd be happy to work on a PR for this if you're open to the idea. Thank you for your consideration!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions