-
-
Notifications
You must be signed in to change notification settings - Fork 925
Description
To support Vite+, we recently added vite.config.ts support in addition to our config files.
However, this change has caused Oxlint and Oxfmt to throw errors under specific conditions, even in projects that aren't using Vite+.
At least, I want to avoid affecting existing Oxapps users.
What's happening
Oxfmt CLI + LSP, and Oxlint LSP try to auto discover root config files.
First, It starts searching from the cwd, then find-up.
The priority order is: the respective config files (such as .oxfmtrc.json) and then vite.config.ts.
And for loading .ts config file, we are using bare dynamic import().
For example, situation like this:
- .oxlintrc.json
- vite.config.ts
- packages/
- proj-1
- vite.config.ts
CLI run from root should work, which successfully find our config first from root.
However, if CLI or LSP is used from proj-1 as cwd, it finds vite.config.ts and tries to load it.
This is where the problem lies.
The problem happens when vite.config.ts is written with the assumption that it will be loaded via Vite. Vite bundles configuration files by default, so it may NOT be compatible with native import().
For actual usecases, please see also voidzero-dev/vite-plus#930.
The CLI immediately reports an error and exits, but the LSP falls back to the default and continues running.
Proposal
This is what I've done in #20417.
- Check env var
VITE_PLUS_VERSIONexists - If true:
- Only
vite.config.tswill be used as a config file - Existing config files (.oxlintrc.json, oxlint.config.ts, etc) will NOT be referenced
- Only
- else:
- Only existing config files (.oxlintrc.json, oxlint.config.ts, etc) will be used
- The same as it was before implementing
vite.config.tssupport
Since Vite+ ensures the entry points for both CLI (vp lint|fmt) and LSP (--lsp bin wrapper), this is possible.
PR: voidzero-dev/vite-plus#946
Why environment variables instead of CLI flags:
- CLI flags are specifically for the CLI
- For LSP, the relevant are the settings sent per workspace in the initialization request
- Env vars can be easily read from the JS as well
Why not just append `vite.config.ts`:
- With Vite+, there is no motivation to combine our config files
- And also using Oxlint or Oxfmt directly is not encouraged
- By this flag, we may be able to switch loading function
- What if
import("vite-plus/config").then(({ loadConfig }) => loadConfig(path, "lint")?
- What if
We should address import() cannot cover all vite.config.ts issue separately for Vite+ though, but this helps existing Oxapps users.
I think vite-plus side could provide a function for loading the configs.
Workaround
In the meantime, here's what you can do:
- Rollback to the version before
vite.config.tssupport was addedoxlint@1.52andoxfmt@0.37
- or Always use
-c, --configto disable auto discovery- For LSP, set
oxc.configPathandoxc.fmt.configPath
- For LSP, set
- or Place Oxapps config next to
vite.config.ts- and re-export root config
- Please note that relative path related options should be updated
- or Update your
vite.config.tsto be compatible with--configLoader=native
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority
Effort
Start date
Target date