Skip to content

Commit f45c026

Browse files
committed
feat(cli): validate vite-plus installation before task completions
1 parent b8a3d62 commit f45c026

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

crates/vite_global_cli/src/cli.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{
2020
},
2121
error::Error,
2222
help,
23+
js_executor::JsExecutor,
2324
};
2425

2526
#[derive(Clone, Copy, Debug)]
@@ -1488,9 +1489,12 @@ fn should_force_global_delegate(command: &str, args: &[String]) -> bool {
14881489
/// which returns a list of available tasks in the format "task_name: description".
14891490
14901491
fn run_tasks_completions(current: &OsStr) -> Vec<clap_complete::CompletionCandidate> {
1491-
let cwd = match std::env::current_dir() {
1492-
Ok(cwd) => cwd,
1493-
Err(_) => return vec![],
1492+
let Some(cwd) = std::env::current_dir()
1493+
.ok()
1494+
.and_then(AbsolutePathBuf::new)
1495+
.filter(|p| JsExecutor::resolve_local_vite_plus(p).is_some())
1496+
else {
1497+
return vec![];
14941498
};
14951499

14961500
let current = current
@@ -1501,7 +1505,6 @@ fn run_tasks_completions(current: &OsStr) -> Vec<clap_complete::CompletionCandid
15011505

15021506
let output = tokio::task::block_in_place(|| {
15031507
Runtime::new().ok().and_then(|rt| {
1504-
let cwd = AbsolutePathBuf::new(cwd)?;
15051508
rt.block_on(async { commands::delegate::execute_output(cwd, "run", &[]).await.ok() })
15061509
})
15071510
});

crates/vite_global_cli/src/js_executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl JsExecutor {
297297
}
298298

299299
/// Resolve the local vite-plus package's `dist/bin.js` from the project directory.
300-
fn resolve_local_vite_plus(project_path: &AbsolutePath) -> Option<AbsolutePathBuf> {
300+
pub fn resolve_local_vite_plus(project_path: &AbsolutePath) -> Option<AbsolutePathBuf> {
301301
use oxc_resolver::{ResolveOptions, Resolver};
302302

303303
let resolver = Resolver::new(ResolveOptions {

0 commit comments

Comments
 (0)