Skip to content

Commit 2b3673c

Browse files
committed
refactor: refactor oxc parser loader
1 parent 6b448a5 commit 2b3673c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

lib/lint/file.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import PrettierPluginOxc from "@prettier/plugin-oxc";
43
import PrettierPluginXml from "@prettier/plugin-xml";
54
import editorconfig from "editorconfig";
65
import { ESLint as EsLint } from "eslint";
@@ -103,12 +102,23 @@ const DEFAULT_ESLINT_CONFIG_JAVASCRIPT = import.meta.resolve( "#resources/eslint
103102
DEFAULT_ESLINT_CONFIG_VUE = import.meta.resolve( "#resources/eslint.config.vue.js" ),
104103
DEFAULT_ESLINT_CONFIG_TYPESCRIPT = import.meta.resolve( "#resources/eslint.config.typescript.js" );
105104

105+
var PrettierPluginOxc,
106+
PRETTIER_JS_PARSER = "babel",
107+
PRETTIER_TS_PARSER = "typescript";
108+
109+
try {
110+
PrettierPluginOxc = await import( "@prettier/plugin-oxc" );
111+
PRETTIER_JS_PARSER = "oxc";
112+
PRETTIER_TS_PARSER = "oxc-ts";
113+
}
114+
catch {}
115+
106116
const USE_PRETTIER_FOR_JS = true,
107117
TYPES = {
108118
"text/javascript": {
109119
"prettier": {
110120
"parser": USE_PRETTIER_FOR_JS
111-
? "oxc"
121+
? PRETTIER_JS_PARSER
112122
: null,
113123
},
114124
"eslint": {
@@ -130,7 +140,7 @@ const USE_PRETTIER_FOR_JS = true,
130140
"application/x-typescript": {
131141
"prettier": {
132142
"parser": USE_PRETTIER_FOR_JS
133-
? "oxc-ts"
143+
? PRETTIER_TS_PARSER
134144
: null,
135145
},
136146
"eslint": {

0 commit comments

Comments
 (0)