Skip to content

Commit b17614e

Browse files
committed
fix(cli): stop injecting -c config for oxlint/oxfmt
oxlint 1.60.0 and oxfmt 0.45.0 auto-discover the nearest vite.config.ts from cwd up (gated by VP_VERSION, which vp injects via merge_resolved_envs_with_version and the bin wrappers). Injecting `-c <root vite.config.ts>` broke the nested-workspace case: running `vp lint` / `vp fmt` from a sub-package applied the root config instead of the sub-package's own config. Drop the -c injection from the Lint/Fmt resolver arms and propagate the now-unused resolved_vite_config parameter removal through resolve_and_execute, resolve_and_capture_output, and their callers. resolve_universal_vite_config() stays for check/mod.rs's LintMessageKind derivation. Snapshot updates: - nested-oxc-config-proj-1: both vp lint and vp fmt --check pass when run from packages/proj-1 (regression test for oxc-project/oxc#20416). - workspace-lint-subpackage: sub-package's no-console:off now wins over root's no-console:warn as documented. Closes oxc-project/oxc#20416
1 parent 8bbffbe commit b17614e

File tree

8 files changed

+30
-97
lines changed

8 files changed

+30
-97
lines changed

packages/cli/binding/src/check/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub(crate) async fn execute_check(
5454
let captured = resolve_and_capture_output(
5555
resolver,
5656
SynthesizableSubcommand::Fmt { args },
57-
Some(&resolved_vite_config),
5857
envs,
5958
cwd,
6059
cwd_arc,
@@ -133,7 +132,6 @@ pub(crate) async fn execute_check(
133132
let captured = resolve_and_capture_output(
134133
resolver,
135134
SynthesizableSubcommand::Lint { args },
136-
Some(&resolved_vite_config),
137135
envs,
138136
cwd,
139137
cwd_arc,
@@ -200,7 +198,6 @@ pub(crate) async fn execute_check(
200198
let captured = resolve_and_capture_output(
201199
resolver,
202200
SynthesizableSubcommand::Fmt { args },
203-
Some(&resolved_vite_config),
204201
envs,
205202
cwd,
206203
cwd_arc,

packages/cli/binding/src/cli/execution.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@ use vite_task::ExitStatus;
77

88
use super::{
99
resolver::SubcommandResolver,
10-
types::{CapturedCommandOutput, ResolvedUniversalViteConfig, SynthesizableSubcommand},
10+
types::{CapturedCommandOutput, SynthesizableSubcommand},
1111
};
1212

1313
/// Resolve a subcommand into a prepared `tokio::process::Command`.
1414
async fn resolve_and_build_command(
1515
resolver: &SubcommandResolver,
1616
subcommand: SynthesizableSubcommand,
17-
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,
1817
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
1918
cwd: &AbsolutePathBuf,
2019
cwd_arc: &Arc<AbsolutePath>,
2120
) -> Result<tokio::process::Command, Error> {
22-
let resolved = resolver
23-
.resolve(subcommand, resolved_vite_config, envs, cwd_arc)
24-
.await
25-
.map_err(|e| Error::Anyhow(e))?;
21+
let resolved =
22+
resolver.resolve(subcommand, envs, cwd_arc).await.map_err(|e| Error::Anyhow(e))?;
2623

2724
// Resolve the program path using `which` to handle Windows .cmd/.bat files (PATHEXT)
2825
let program_path = {
@@ -52,14 +49,11 @@ async fn resolve_and_build_command(
5249
pub(super) async fn resolve_and_execute(
5350
resolver: &SubcommandResolver,
5451
subcommand: SynthesizableSubcommand,
55-
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,
5652
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
5753
cwd: &AbsolutePathBuf,
5854
cwd_arc: &Arc<AbsolutePath>,
5955
) -> Result<ExitStatus, Error> {
60-
let mut cmd =
61-
resolve_and_build_command(resolver, subcommand, resolved_vite_config, envs, cwd, cwd_arc)
62-
.await?;
56+
let mut cmd = resolve_and_build_command(resolver, subcommand, envs, cwd, cwd_arc).await?;
6357
let mut child = cmd.spawn().map_err(|e| Error::Anyhow(e.into()))?;
6458
let status = child.wait().await.map_err(|e| Error::Anyhow(e.into()))?;
6559
Ok(ExitStatus(status.code().unwrap_or(1) as u8))
@@ -75,16 +69,13 @@ pub(super) enum FilterStream {
7569
pub(super) async fn resolve_and_execute_with_filter(
7670
resolver: &SubcommandResolver,
7771
subcommand: SynthesizableSubcommand,
78-
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,
7972
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
8073
cwd: &AbsolutePathBuf,
8174
cwd_arc: &Arc<AbsolutePath>,
8275
stream: FilterStream,
8376
filter: impl Fn(&str) -> Cow<'_, str>,
8477
) -> Result<ExitStatus, Error> {
85-
let mut cmd =
86-
resolve_and_build_command(resolver, subcommand, resolved_vite_config, envs, cwd, cwd_arc)
87-
.await?;
78+
let mut cmd = resolve_and_build_command(resolver, subcommand, envs, cwd, cwd_arc).await?;
8879
match stream {
8980
FilterStream::Stdout => cmd.stdout(Stdio::piped()),
9081
FilterStream::Stderr => cmd.stderr(Stdio::piped()),
@@ -111,15 +102,12 @@ pub(super) async fn resolve_and_execute_with_filter(
111102
pub(crate) async fn resolve_and_capture_output(
112103
resolver: &SubcommandResolver,
113104
subcommand: SynthesizableSubcommand,
114-
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,
115105
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
116106
cwd: &AbsolutePathBuf,
117107
cwd_arc: &Arc<AbsolutePath>,
118108
force_color_if_terminal: bool,
119109
) -> Result<CapturedCommandOutput, Error> {
120-
let mut cmd =
121-
resolve_and_build_command(resolver, subcommand, resolved_vite_config, envs, cwd, cwd_arc)
122-
.await?;
110+
let mut cmd = resolve_and_build_command(resolver, subcommand, envs, cwd, cwd_arc).await?;
123111
cmd.stdout(Stdio::piped());
124112
cmd.stderr(Stdio::piped());
125113
if force_color_if_terminal && std::io::stdout().is_terminal() {

packages/cli/binding/src/cli/handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl CommandHandler for VitePlusCommandHandler {
7171
)))
7272
}
7373
CLIArgs::Synthesizable(subcmd) => {
74-
let resolved =
75-
self.resolver.resolve(subcmd, None, &command.envs, &command.cwd).await?;
74+
let resolved = self.resolver.resolve(subcmd, &command.envs, &command.cwd).await?;
7675
Ok(HandledCommand::Synthesized(resolved.into_synthetic_plan_request()))
7776
}
7877
CLIArgs::ViteTask(cmd) => Ok(HandledCommand::ViteTaskCommand(cmd)),

packages/cli/binding/src/cli/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ async fn execute_direct_subcommand(
7474
resolve_and_execute_with_filter(
7575
&resolver,
7676
other,
77-
None,
7877
&envs,
7978
cwd,
8079
&cwd_arc,
@@ -86,7 +85,6 @@ async fn execute_direct_subcommand(
8685
resolve_and_execute_with_filter(
8786
&resolver,
8887
other,
89-
None,
9088
&envs,
9189
cwd,
9290
&cwd_arc,
@@ -95,7 +93,7 @@ async fn execute_direct_subcommand(
9593
)
9694
.await?
9795
} else {
98-
resolve_and_execute(&resolver, other, None, &envs, cwd, &cwd_arc).await?
96+
resolve_and_execute(&resolver, other, &envs, cwd, &cwd_arc).await?
9997
}
10098
}
10199
};

packages/cli/binding/src/cli/resolver.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,17 @@ impl SubcommandResolver {
6565
pub(super) async fn resolve(
6666
&self,
6767
subcommand: SynthesizableSubcommand,
68-
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,
6968
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
7069
cwd: &Arc<AbsolutePath>,
7170
) -> anyhow::Result<ResolvedSubcommand> {
7271
match subcommand {
73-
SynthesizableSubcommand::Lint { mut args } => {
72+
SynthesizableSubcommand::Lint { args } => {
7473
let cli_options = self.cli_options()?;
7574
let resolved = (cli_options.lint)().await?;
7675
let js_path = resolved.bin_path;
7776
let js_path_str = js_path
7877
.to_str()
7978
.ok_or_else(|| anyhow::anyhow!("lint JS path is not valid UTF-8"))?;
80-
let owned_resolved_vite_config;
81-
let resolved_vite_config = if let Some(config) = resolved_vite_config {
82-
config
83-
} else {
84-
owned_resolved_vite_config = self.resolve_universal_vite_config().await?;
85-
&owned_resolved_vite_config
86-
};
87-
88-
if let (Some(_), Some(config_file)) =
89-
(&resolved_vite_config.lint, &resolved_vite_config.config_file)
90-
{
91-
args.insert(0, "-c".to_string());
92-
args.insert(1, config_file.clone());
93-
}
9479

9580
Ok(ResolvedSubcommand {
9681
program: Arc::from(OsStr::new("node")),
@@ -106,27 +91,13 @@ impl SubcommandResolver {
10691
envs: merge_resolved_envs_with_version(envs, resolved.envs),
10792
})
10893
}
109-
SynthesizableSubcommand::Fmt { mut args } => {
94+
SynthesizableSubcommand::Fmt { args } => {
11095
let cli_options = self.cli_options()?;
11196
let resolved = (cli_options.fmt)().await?;
11297
let js_path = resolved.bin_path;
11398
let js_path_str = js_path
11499
.to_str()
115100
.ok_or_else(|| anyhow::anyhow!("fmt JS path is not valid UTF-8"))?;
116-
let owned_resolved_vite_config;
117-
let resolved_vite_config = if let Some(config) = resolved_vite_config {
118-
config
119-
} else {
120-
owned_resolved_vite_config = self.resolve_universal_vite_config().await?;
121-
&owned_resolved_vite_config
122-
};
123-
124-
if let (Some(_), Some(config_file)) =
125-
(&resolved_vite_config.fmt, &resolved_vite_config.config_file)
126-
{
127-
args.insert(0, "-c".to_string());
128-
args.insert(1, config_file.clone());
129-
}
130101

131102
Ok(ResolvedSubcommand {
132103
program: Arc::from(OsStr::new("node")),
Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
> # Reproduces oxc-project/oxc#20416: nested vite.config.ts in packages/proj-1
2-
> # should override root config when `vp lint` / `vp fmt` run from that cwd.
3-
> # proj-1 disables no-debugger and turns off singleQuote, so both commands
4-
> # should pass. If the root config leaks through, lint reports a debugger
5-
> # violation and fmt reports a quote-style diff.
6-
[1]> cd packages/proj-1 && vp lint # expected: pass (proj-1 disables no-debugger); actual: fails with root rule
7-
8-
× eslint(no-debugger): `debugger` statement is not allowed
9-
╭─[src/index.js:2:3]
10-
1 │ function hello() {
11-
2 │ debugger;
12-
· ─────────
13-
3 │ return "hello from proj-1";
14-
╰────
15-
help: Remove the debugger statement
16-
17-
Found 0 warnings and 1 error.
1+
> # Regression test for oxc-project/oxc#20416: nested vite.config.ts in
2+
> # packages/proj-1 must override the workspace root config when `vp lint`
3+
> # and `vp fmt` run from that cwd. Root has `no-debugger: error` and
4+
> # `singleQuote: true`, proj-1 overrides both to `off` / `false`. If the
5+
> # root config leaks through, lint reports a debugger violation and fmt
6+
> # reports a quote-style diff.
7+
> cd packages/proj-1 && vp lint
8+
Found 0 warnings and 0 errors.
189
Finished in <variable>ms on 2 files with <variable> rules using <variable> threads.
1910

20-
[1]> cd packages/proj-1 && vp fmt --check # expected: pass (proj-1 sets singleQuote:false); actual: fails with root singleQuote:true
11+
> cd packages/proj-1 && vp fmt --check src
2112
Checking formatting...
22-
src/index.js (<variable>ms)
23-
24-
Format issues found in above 1 files. Run without `--check` to fix.
25-
Finished in <variable>ms on 3 files using <variable> threads.
13+
All matched files use the correct format.
14+
Finished in <variable>ms on 1 files using <variable> threads.
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"ignoredPlatforms": ["win32"],
33
"commands": [
4-
"# Reproduces oxc-project/oxc#20416: nested vite.config.ts in packages/proj-1",
5-
"# should override root config when `vp lint` / `vp fmt` run from that cwd.",
6-
"# proj-1 disables no-debugger and turns off singleQuote, so both commands",
7-
"# should pass. If the root config leaks through, lint reports a debugger",
8-
"# violation and fmt reports a quote-style diff.",
9-
"cd packages/proj-1 && vp lint # expected: pass (proj-1 disables no-debugger); actual: fails with root rule",
10-
"cd packages/proj-1 && vp fmt --check # expected: pass (proj-1 sets singleQuote:false); actual: fails with root singleQuote:true"
4+
"# Regression test for oxc-project/oxc#20416: nested vite.config.ts in",
5+
"# packages/proj-1 must override the workspace root config when `vp lint`",
6+
"# and `vp fmt` run from that cwd. Root has `no-debugger: error` and",
7+
"# `singleQuote: true`, proj-1 overrides both to `off` / `false`. If the",
8+
"# root config leaks through, lint reports a debugger violation and fmt",
9+
"# reports a quote-style diff.",
10+
"cd packages/proj-1 && vp lint",
11+
"cd packages/proj-1 && vp fmt --check src"
1112
]
1213
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
> cd packages/app-a && vp lint # sub-workspace has no-console:off but root has no-console:warn
2-
3-
⚠ eslint(no-console): Unexpected console statement.
4-
╭─[src/index.js:2:3]
5-
1 │ function hello() {
6-
2 │ console.log('hello from app-a');
7-
· ───────────
8-
3 │ return 'hello';
9-
╰────
10-
help: Delete this console statement.
11-
12-
Found 1 warning and 0 errors.
2+
Found 0 warnings and 0 errors.
133
Finished in <variable>ms on 2 files with <variable> rules using <variable> threads.

0 commit comments

Comments
 (0)