Skip to content

Commit be1826f

Browse files
committed
fix(cli): address Codex review round 2
- known value-taking flags (--port 4000, --mode production) keep an invocation bare so root elicitation still applies; unknown/optional-value flags keep the conservative fallback - refresh POSIX PWD wherever -C or an elicited target applies (global main, local bin, binding env for retargeted tools) so process.env.PWD readers match the cd form - a runnable workspace root stays selectable as a '.' row (picker, listing, auto-select), with a PTY regression fixture - open field maps now record explicit NonStatic declarations, so a spread followed by defaultPackage: process.env.X errors instead of being silently ignored - apply -C before shell completion so cwd-sensitive completers suggest from the target directory
1 parent f69e793 commit be1826f

15 files changed

Lines changed: 216 additions & 35 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<h1>root app</h1>
5+
</body>
6+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "runnable-root", "private": true, "workspaces": ["packages/*"] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "ui", "private": true, "type": "module", "main": "src/index.ts" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ui = true;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[case]]
2+
name = "auto_select_root"
3+
vp = ["local", "global"]
4+
comment = """
5+
A workspace root that is itself the only runnable app stays selectable: bare
6+
vp build auto-selects the root (shown as `.`) and runs in place, matching
7+
today's behavior for root apps (rfcs/cwd-flag.md, picker contents).
8+
"""
9+
steps = [["vp", "build"]]
10+
11+
[[case]]
12+
name = "listing_includes_root"
13+
vp = ["local", "global"]
14+
comment = "The non-interactive listing offers the runnable root as a `.` row."
15+
steps = [{ argv = ["vp", "build"], tty = false }]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# auto_select_root
2+
3+
A workspace root that is itself the only runnable app stays selectable: bare
4+
vp build auto-selects the root (shown as `.`) and runs in place, matching
5+
today's behavior for root apps (rfcs/cwd-flag.md, picker contents).
6+
7+
## `vp build`
8+
9+
```
10+
VITE+ - The Unified Toolchain for the Web
11+
12+
Selected package: runnable-root (.)
13+
Tip: run this directly with `vp -C . build`
14+
vite <version> building client environment for production...
15+
✓ 2 modules transformed.
16+
computing gzip size...
17+
dist/index.html <size> kB │ gzip: <size> kB
18+
19+
✓ built in <duration>
20+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# auto_select_root
2+
3+
A workspace root that is itself the only runnable app stays selectable: bare
4+
vp build auto-selects the root (shown as `.`) and runs in place, matching
5+
today's behavior for root apps (rfcs/cwd-flag.md, picker contents).
6+
7+
## `vp build`
8+
9+
```
10+
Selected package: runnable-root (.)
11+
Tip: run this directly with `vp -C . build`
12+
vite <version> building client environment for production...
13+
✓ 2 modules transformed.
14+
computing gzip size...
15+
dist/index.html <size> kB │ gzip: <size> kB
16+
17+
✓ built in <duration>
18+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# listing_includes_root
2+
3+
The non-interactive listing offers the runnable root as a `.` row.
4+
5+
## `vp build`
6+
7+
**Exit code:** 1
8+
9+
```
10+
error: `vp build` at the workspace root needs a target package.
11+
12+
Packages in this workspace:
13+
runnable-root .
14+
ui packages/ui
15+
16+
Pass a directory: vp -C . build
17+
Or run every package's build script: vp run -r build
18+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# listing_includes_root
2+
3+
The non-interactive listing offers the runnable root as a `.` row.
4+
5+
## `vp build`
6+
7+
**Exit code:** 1
8+
9+
```
10+
error: `vp build` at the workspace root needs a target package.
11+
12+
Packages in this workspace:
13+
runnable-root .
14+
ui packages/ui
15+
16+
Pass a directory: vp -C . build
17+
Or run every package's build script: vp run -r build
18+
```

crates/vite_global_cli/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ async fn main() -> ExitCode {
325325
}
326326

327327
// Handle shell completion
328+
// `complete()` exits before the normal `-C` handling below runs, so apply
329+
// the target directory here too: cwd-sensitive completers (run tasks)
330+
// should suggest from <dir>, where the completed command will run.
331+
if env::var_os("VP_COMPLETE").is_some()
332+
&& let Some((dir, _)) = parse_leading_chdir(&args)
333+
&& let Ok(current) = vite_path::current_dir()
334+
{
335+
let target = current.join(&dir).clean();
336+
if target.as_path().is_dir() {
337+
let _ = std::env::set_current_dir(target.as_path());
338+
}
339+
}
328340
CompleteEnv::with_factory(command_with_help).var("VP_COMPLETE").complete();
329341

330342
// Check for shim mode (invoked as node, npm, or npx)
@@ -363,6 +375,13 @@ async fn main() -> ExitCode {
363375
output::error(&format!("Failed to change directory to {dir}: {e}"));
364376
return ExitCode::FAILURE;
365377
}
378+
// Keep the POSIX PWD in sync, like a real `cd`: Node tools commonly
379+
// read process.env.PWD.
380+
#[cfg(unix)]
381+
// SAFETY: single-threaded startup, before any command logic runs.
382+
unsafe {
383+
std::env::set_var("PWD", cwd.as_path());
384+
}
366385
args.drain(1..=consumed);
367386
}
368387

0 commit comments

Comments
 (0)