-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmain.rs
More file actions
50 lines (47 loc) · 1.9 KB
/
Copy pathmain.rs
File metadata and controls
50 lines (47 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{process::ExitCode, sync::Arc};
use clap::Parser;
use vite_str::Str;
use vite_task::{
EnabledCacheConfig, ExitStatus, Session, UserCacheConfig, get_path_env,
plan_request::SyntheticPlanRequest,
};
use vite_task_bin::{Args, OwnedSessionCallbacks, find_executable};
#[tokio::main]
async fn main() -> anyhow::Result<ExitCode> {
let exit_status = run().await?;
Ok(exit_status.0.into())
}
async fn run() -> anyhow::Result<ExitStatus> {
let args = Args::parse();
let mut owned_callbacks = OwnedSessionCallbacks::default();
let session = Session::init(owned_callbacks.as_callbacks())?;
match args {
Args::Task(command) => session.main(command).await,
args => {
// If env FOO is set, run `print-env FOO` via Session::exec before proceeding.
// In vite-plus, Session::exec is used for auto-install.
let envs = session.envs();
if envs.contains_key(std::ffi::OsStr::new("FOO")) {
let program = find_executable(get_path_env(envs), session.cwd(), "print-env")?;
let request = SyntheticPlanRequest {
program,
args: [Str::from("FOO")].into(),
cache_config: UserCacheConfig::with_config({
EnabledCacheConfig {
envs: Some(Box::from([Str::from("FOO")])),
pass_through_envs: None,
}
}),
envs: Arc::clone(envs),
};
let cache_key: Arc<[Str]> = Arc::from([Str::from("print-env-foo")]);
let status = session.execute_synthetic(request, cache_key, true).await?;
if status != ExitStatus::SUCCESS {
return Ok(status);
}
}
println!("{:?}", args);
Ok(ExitStatus::SUCCESS)
}
}
}