From 38880c5dabf0bb6de420f3b561c5f204b2b0e504 Mon Sep 17 00:00:00 2001 From: Rory Abraham <47436092+roryabraham@users.noreply.github.com> Date: Thu, 19 Feb 2026 14:20:53 -0800 Subject: [PATCH] Add support for @prettier/plugin-oxc parsers @prettier/plugin-oxc registers `oxc` and `oxc-ts` parsers that override the built-in `babel` and `typescript` parsers for JS/TS files. Since this plugin only attaches its import-sorting preprocess hook to `babel`/`typescript`/`flow`/`vue` parsers, import sorting is silently skipped when OXC is active. This adds `oxc` and `oxc-ts` parser entries that compose OXC's parser with the sort-imports `defaultPreprocessor`. The import is wrapped in try/catch so `@prettier/plugin-oxc` remains an optional dependency. --- package.json | 5 +++++ src/index.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/package.json b/package.json index 9f1a2a3..7c3e863 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ }, "devDependencies": { "@babel/core": "^7.26.7", + "@prettier/plugin-oxc": "^0.1.3", "@types/babel__core": "^7.20.5", "@types/babel__generator": "^7.27.0", "@types/babel__traverse": "^7.20.7", @@ -61,6 +62,7 @@ "vitest": "^3.2.4" }, "peerDependencies": { + "@prettier/plugin-oxc": ">= 0.1.0", "@vue/compiler-sfc": "3.x", "prettier": "2.x - 3.x", "prettier-plugin-ember-template-tag": ">= 2.0.0", @@ -71,6 +73,9 @@ "node": ">= 20" }, "peerDependenciesMeta": { + "@prettier/plugin-oxc": { + "optional": true + }, "@vue/compiler-sfc": { "optional": true }, diff --git a/src/index.ts b/src/index.ts index b449bfd..cdc33b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,11 @@ import { createSvelteParsers } from './utils/create-svelte-parsers.js'; const emberParsers = await createEmberParsers(); const svelteParsers = await createSvelteParsers(); +let oxcParsers: Record = {}; +try { + oxcParsers = (await import('@prettier/plugin-oxc')).parsers; +} catch {} + const options: Options = { importOrderExclude: { type: 'path', @@ -129,6 +134,18 @@ export default { }, } : {}), + ...(oxcParsers.oxc + ? { + oxc: { + ...oxcParsers.oxc, + preprocess: defaultPreprocessor, + }, + 'oxc-ts': { + ...oxcParsers['oxc-ts'], + preprocess: defaultPreprocessor, + }, + } + : {}), }, options, };