Skip to content

Commit b4ba22c

Browse files
authored
fix: prevent args to the task being consumed by vp (#286)
Close #285 This PR merged `task_specifier` and `additional_args` into `task_and_args` field to ensure args after the task name to be directly passed to the task itself instead of Vite task.
1 parent 69cc6eb commit b4ba22c

File tree

12 files changed

+55
-19
lines changed

12 files changed

+55
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Install [Vite+](https://viteplus.dev), then run tasks from your workspace. See t
88

99
```bash
1010
vp run build # run a task in the current package
11-
vp run build -r # run across all packages in dependency order
12-
vp run @my/app#build -t # run in a package and its transitive dependencies
11+
vp run -r build # run across all packages in dependency order
12+
vp run -t @my/app#build # run in a package and its transitive dependencies
1313
vp run --cache build # run with caching enabled
1414
```
1515

crates/vite_task/src/cli/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ impl RunFlags {
7676
/// `ResolvedCommand::RunLastDetails` variant internally.
7777
#[derive(Debug, clap::Parser)]
7878
pub struct RunCommand {
79-
/// `packageName#taskName` or `taskName`. If omitted, lists all available tasks.
80-
pub(crate) task_specifier: Option<Str>,
81-
8279
#[clap(flatten)]
8380
pub(crate) flags: RunFlags,
8481

85-
/// Additional arguments to pass to the tasks
86-
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
87-
pub(crate) additional_args: Vec<Str>,
88-
8982
/// Display the detailed summary of the last run.
9083
#[clap(long, exclusive = true)]
9184
pub(crate) last_details: bool,
85+
86+
/// The task name and all arguments to pass to the task process
87+
/// Prevent flags after the task name to be consumed by Vite Task with `trailing_var_arg`
88+
///
89+
/// <https://github.com/voidzero-dev/vite-task/issues/285>
90+
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
91+
pub(crate) task_and_args: Vec<Str>,
9292
}
9393

9494
/// vite task CLI subcommands as parsed by clap.
@@ -162,10 +162,11 @@ impl RunCommand {
162162
/// Convert to the resolved run command, stripping the `last_details` flag.
163163
#[must_use]
164164
pub(crate) fn into_resolved(self) -> ResolvedRunCommand {
165+
let mut iter = self.task_and_args.into_iter();
165166
ResolvedRunCommand {
166-
task_specifier: self.task_specifier,
167+
task_specifier: iter.next(),
167168
flags: self.flags,
168-
additional_args: self.additional_args,
169+
additional_args: iter.collect(),
169170
}
170171
}
171172
}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-non-zero-exit/snapshots/builtin command with non-zero exit does not show cache not updated.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
[1]> vt run lint -- -D no-debugger
6-
$ vt lint -D no-debugger
6+
$ vt lint -- -D no-debugger
77

88
x eslint(no-debugger): `debugger` statement is not allowed
99
,-[bad.js:1:1]
@@ -15,7 +15,7 @@ $ vt lint -D no-debugger
1515
Found 0 warnings and 1 error.
1616
Finished in <duration> on 1 file with 93 rules using <n> threads.
1717
[1]> vt run lint -- -D no-debugger
18-
$ vt lint -D no-debugger
18+
$ vt lint -- -D no-debugger
1919
2020
x eslint(no-debugger): `debugger` statement is not allowed
2121
,-[bad.js:1:1]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test prints value from additional_envs.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run env-test -- SYNTHETIC_ENV_VAR test_value_from_synthesizer # prints env value
6-
$ vt env-test SYNTHETIC_ENV_VAR test_value_from_synthesizer
6+
$ vt env-test -- SYNTHETIC_ENV_VAR test_value_from_synthesizer
77
test_value_from_synthesizer

crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test with different values.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run env-test -- FOO bar # sets FOO=bar
6-
$ vt env-test FOO bar
6+
$ vt env-test -- FOO bar
77
bar
88
> vt run env-test -- BAZ qux # sets BAZ=qux
9-
$ vt env-test BAZ qux
9+
$ vt env-test -- BAZ qux
1010
qux
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"scripts": {
3+
"echo": "echo"
4+
}
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tests that arguments after task name should be passed to the task
2+
# https://github.com/voidzero-dev/vite-task/issues/285
3+
4+
[[e2e]]
5+
name = "pass args to task"
6+
steps = [
7+
"vt run echo --help", # Should just print `help` instead of Vite task's help
8+
"vt run echo --version", # Should just print `version` instead of Vite task's version
9+
"vt run echo -v", # Should just print `-v`
10+
"vt run echo -a", # Should just print `-a`
11+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vt run echo --help
6+
$ echo --helpcache disabled
7+
--help
8+
> vt run echo --version
9+
$ echo --versioncache disabled
10+
--version
11+
> vt run echo -v
12+
$ echo -vcache disabled
13+
-v
14+
> vt run echo -a
15+
$ echo -acache disabled
16+
-a
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cache": false
3+
}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ steps = ["vt run --verbose"]
214214
name = "verbose with typo enters selector"
215215
cwd = "packages/app"
216216
steps = [
217-
{ command = "vt run buid --verbose", interactions = [
217+
{ command = "vt run --verbose buid", interactions = [
218218
{ "expect-milestone" = "task-select:buid:0" },
219219
{ "write-key" = "enter" },
220220
] },

0 commit comments

Comments
 (0)