Skip to content

Commit c9750b2

Browse files
authored
feat: add test subcommand to vite_task_bin (#98)
feat: add test subcommand to vite_task_bin print <empty> for empty task call stack
1 parent 3c85add commit c9750b2

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

crates/vite_task_bin/src/lib.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ use vite_task::{
2020
#[derive(Debug, Subcommand)]
2121
pub enum CustomTaskSubcommand {
2222
/// oxlint
23+
#[clap(disable_help_flag = true)]
2324
Lint {
2425
#[clap(allow_hyphen_values = true, trailing_var_arg = true)]
2526
args: Vec<Str>,
2627
},
28+
/// vitest
29+
#[clap(disable_help_flag = true)]
30+
Test {
31+
#[clap(allow_hyphen_values = true, trailing_var_arg = true)]
32+
args: Vec<Str>,
33+
},
2734
/// Test command for testing additional_envs feature
2835
EnvTest {
2936
/// Environment variable name
@@ -72,21 +79,30 @@ impl vite_task::TaskSynthesizer<CustomTaskSubcommand> for TaskSynthesizer {
7279
async fn synthesize_task(
7380
&mut self,
7481
subcommand: CustomTaskSubcommand,
75-
7682
envs: &Arc<HashMap<Arc<OsStr>, Arc<OsStr>>>,
7783
cwd: &Arc<AbsolutePath>,
7884
) -> anyhow::Result<SyntheticPlanRequest> {
85+
let synthesize_node_modules_bin_task = |subcommand_name: &str,
86+
executable_name: &str,
87+
args: Vec<Str>|
88+
-> anyhow::Result<SyntheticPlanRequest> {
89+
let direct_execution_cache_key: Arc<[Str]> =
90+
iter::once(Str::from(subcommand_name)).chain(args.iter().cloned()).collect();
91+
Ok(SyntheticPlanRequest {
92+
program: find_executable(get_path_env(envs), &*cwd, executable_name)?,
93+
args: args.into(),
94+
task_options: Default::default(),
95+
direct_execution_cache_key,
96+
envs: Arc::clone(envs),
97+
})
98+
};
99+
79100
match subcommand {
80101
CustomTaskSubcommand::Lint { args } => {
81-
let direct_execution_cache_key: Arc<[Str]> =
82-
iter::once(Str::from("lint")).chain(args.iter().cloned()).collect();
83-
Ok(SyntheticPlanRequest {
84-
program: find_executable(get_path_env(envs), &*cwd, "oxlint")?,
85-
args: args.into(),
86-
task_options: Default::default(),
87-
direct_execution_cache_key,
88-
envs: Arc::clone(envs),
89-
})
102+
synthesize_node_modules_bin_task("lint", "oxlint", args)
103+
}
104+
CustomTaskSubcommand::Test { args } => {
105+
synthesize_node_modules_bin_task("test", "vitest", args)
90106
}
91107
CustomTaskSubcommand::EnvTest { name, value } => {
92108
let direct_execution_cache_key: Arc<[Str]> =

crates/vite_task_bin/src/main.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ use vite_task::{
88
use vite_task_bin::{CustomTaskSubcommand, NonTaskSubcommand, OwnedSessionCallbacks};
99

1010
#[tokio::main]
11-
async fn main() -> ExitCode {
12-
match run().await {
13-
Ok(exit_status) => exit_status.0.into(),
14-
Err(err) => {
15-
eprintln!("Error: {err}");
16-
ExitCode::FAILURE
17-
}
18-
}
11+
async fn main() -> anyhow::Result<ExitCode> {
12+
let exit_status = run().await?;
13+
Ok(exit_status.0.into())
1914
}
2015

2116
async fn run() -> anyhow::Result<ExitStatus> {

crates/vite_task_plan/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ pub struct TaskCallStackDisplay {
6666

6767
impl Display for TaskCallStackDisplay {
6868
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69+
if self.frames.is_empty() {
70+
write!(f, "<empty>")?;
71+
return Ok(());
72+
}
6973
for (i, frame) in self.frames.iter().enumerate() {
7074
if i > 0 {
7175
write!(f, " -> ")?;

0 commit comments

Comments
 (0)