Skip to content

Commit 076cef4

Browse files
authored
fix: enable task selection for vt run --cache (#313)
- normalizes the run command to ignore if cache flag is specified or not such that `vt run --cache` is treated like `vt run` and triggers interactive task selection Fixes #312
1 parent 9edeeac commit 076cef4

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
- **Fixed** `vp run --cache` now supports running without a task specifier and opens the interactive task selector, matching bare `vp run` behavior ([#312](https://github.com/voidzero-dev/vite-task/pull/313))
34
- **Fixed** Ctrl-C now prevents future tasks from being scheduled and prevents caching of in-flight task results ([#309](https://github.com/voidzero-dev/vite-task/pull/309))
45
- **Added** `--concurrency-limit` flag to limit the number of tasks running at the same time (defaults to 4) ([#288](https://github.com/voidzero-dev/vite-task/pull/288), [#309](https://github.com/voidzero-dev/vite-task/pull/309))
56
- **Added** `--parallel` flag to ignore task dependencies and run all tasks at once with unlimited concurrency (unless `--concurrency-limit` is also specified) ([#309](https://github.com/voidzero-dev/vite-task/pull/309))

crates/vite_task/src/session/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ impl<'a> Session<'a> {
298298
let bare = RunCommand::try_parse_from::<_, &str>([])
299299
.expect("parsing hardcoded bare command should never fail")
300300
.into_resolved();
301-
if run_command != bare {
301+
302+
// Normalize the run_command for comparison by ignoring cache flags, which don't affect task selection.
303+
let mut normalized_run_command = run_command.clone();
304+
normalized_run_command.flags.cache = false;
305+
306+
if normalized_run_command != bare {
302307
return Err(vite_task_plan::Error::MissingTaskSpecifier.into());
303308
}
304309
let qpr = self.handle_no_task(is_interactive, &run_command).await?;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "cache-task-select-test",
3+
"private": true
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[[e2e]]
2+
name = "cache hit with interactive selector and --cache"
3+
steps = [
4+
{ argv = [
5+
"vt",
6+
"run",
7+
"--cache",
8+
], interactions = [
9+
{ "expect-milestone" = "task-select::0" },
10+
{ "write-key" = "enter" },
11+
] },
12+
{ argv = [
13+
"vt",
14+
"run",
15+
"--cache",
16+
], interactions = [
17+
{ "expect-milestone" = "task-select::0" },
18+
{ "write-key" = "enter" },
19+
] },
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
assertion_line: 441
4+
expression: e2e_outputs
5+
---
6+
> vt run --cache
7+
@ expect-milestone: task-select::0
8+
Select a task (↑/↓, Enter to run, type to search):
9+
10+
build vtt print-file src/main.ts
11+
lint echo lint app
12+
@ write-key: enter
13+
Selected task: build
14+
$ vtt print-file src/main.ts
15+
export const main = 'initial';
16+
> vt run --cache
17+
@ expect-milestone: task-select::0
18+
Select a task (↑/↓, Enter to run, type to search):
19+
20+
build vtt print-file src/main.ts
21+
lint echo lint app
22+
@ write-key: enter
23+
Selected task: build
24+
$ vtt print-file src/main.tscache hit, replaying
25+
export const main = 'initial';
26+
27+
---
28+
vt run: cache hit.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const main = 'initial';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"tasks": {
3+
"build": {
4+
"command": "vtt print-file src/main.ts",
5+
"cache": true
6+
},
7+
"lint": {
8+
"command": "echo lint app"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)