Skip to content

Commit b369e8e

Browse files
fix: correctly forward passthrough arguments when using pkg#task format (#10087)
### Description Closes #10086. Parses the task as a `TaskName` before checking if task matches for passthrough args, to account for tasks being passed `pkg#task`. ### Testing Instructions Added a test for passthrough args
1 parent cf5a1f9 commit b369e8e

File tree

7 files changed

+106
-3
lines changed

7 files changed

+106
-3
lines changed

crates/turborepo-lib/src/opts.rs

+51-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
OutputLogsMode, RunArgs,
1414
},
1515
config::ConfigurationOptions,
16-
run::task_id::TaskId,
16+
run::task_id::{TaskId, TaskName},
1717
turbo_json::{UIMode, CONFIG_FILE},
1818
Args,
1919
};
@@ -258,7 +258,7 @@ impl<'a> TaskArgs<'a> {
258258
&& self
259259
.tasks
260260
.iter()
261-
.any(|task| task.as_str() == task_id.task())
261+
.any(|task| TaskName::from(task.as_str()).task() == task_id.task())
262262
{
263263
Some(self.pass_through_args)
264264
} else {
@@ -550,12 +550,13 @@ mod test {
550550
use turborepo_cache::{CacheActions, CacheConfig, CacheOpts};
551551
use turborepo_ui::ColorConfig;
552552

553-
use super::{APIClientOpts, RepoOpts, RunOpts};
553+
use super::{APIClientOpts, RepoOpts, RunOpts, TaskArgs};
554554
use crate::{
555555
cli::{Command, ContinueMode, DryRunMode, RunArgs},
556556
commands::CommandBase,
557557
config::ConfigurationOptions,
558558
opts::{Opts, RunCacheOpts, ScopeOpts},
559+
run::task_id::TaskId,
559560
turbo_json::{UIMode, CONFIG_FILE},
560561
Args,
561562
};
@@ -876,4 +877,51 @@ mod test {
876877

877878
Ok(())
878879
}
880+
881+
#[test_case(
882+
vec!["build".to_string()],
883+
vec!["passthrough".to_string()],
884+
TaskId::new("web", "build"),
885+
Some(vec!["passthrough".to_string()]);
886+
"single task"
887+
)]
888+
#[test_case(
889+
vec!["lint".to_string(), "build".to_string()],
890+
vec!["passthrough".to_string()],
891+
TaskId::new("web", "build"),
892+
Some(vec!["passthrough".to_string()]);
893+
"multiple tasks"
894+
)]
895+
#[test_case(
896+
vec!["web#build".to_string()],
897+
vec!["passthrough".to_string()],
898+
TaskId::new("web", "build"),
899+
Some(vec!["passthrough".to_string()]);
900+
"task with package"
901+
)]
902+
#[test_case(
903+
vec!["lint".to_string()],
904+
vec![],
905+
TaskId::new("ui", "lint"),
906+
None;
907+
"no passthrough args"
908+
)]
909+
fn test_get_args_for_tasks(
910+
tasks: Vec<String>,
911+
pass_through_args: Vec<String>,
912+
expected_task: TaskId<'static>,
913+
expected_args: Option<Vec<String>>,
914+
) -> Result<(), anyhow::Error> {
915+
let task_opts = TaskArgs {
916+
tasks: &tasks,
917+
pass_through_args: &pass_through_args,
918+
};
919+
920+
assert_eq!(
921+
task_opts.args_for_task(&expected_task),
922+
expected_args.as_deref()
923+
);
924+
925+
Ok(())
926+
}
879927
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.turbo
3+
.npmrc

turborepo-tests/integration/fixtures/passthrough/apps/my-app/.env.local

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "my-app",
3+
"scripts": {
4+
"echo": "echo"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "monorepo",
3+
"workspaces": [
4+
"apps/**"
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"tasks": {
4+
"echo": {}
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Setup
2+
$ . ${TESTDIR}/../../helpers/setup_integration_test.sh passthrough
3+
4+
$ ${TURBO} -F my-app echo -- hello
5+
\xe2\x80\xa2 Packages in scope: my-app (esc)
6+
\xe2\x80\xa2 Running echo in 1 packages (esc)
7+
\xe2\x80\xa2 Remote caching disabled (esc)
8+
my-app:echo: cache miss, executing c0813f759149b8af
9+
my-app:echo:
10+
my-app:echo: > echo
11+
my-app:echo: > echo hello
12+
my-app:echo:
13+
my-app:echo: hello
14+
15+
Tasks: 1 successful, 1 total
16+
Cached: 0 cached, 1 total
17+
Time: .*s (re)
18+
19+
20+
$ ${TURBO} my-app#echo -- goodbye
21+
\xe2\x80\xa2 Packages in scope: my-app (esc)
22+
\xe2\x80\xa2 Running my-app#echo in 1 packages (esc)
23+
\xe2\x80\xa2 Remote caching disabled (esc)
24+
my-app:echo: cache miss, executing f4397252b3a3d780
25+
my-app:echo:
26+
my-app:echo: > echo
27+
my-app:echo: > echo goodbye
28+
my-app:echo:
29+
my-app:echo: goodbye
30+
31+
Tasks: 1 successful, 1 total
32+
Cached: 0 cached, 1 total
33+
Time: .*s (re)
34+

0 commit comments

Comments
 (0)