这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: correctly forward passthrough arguments when using pkg#task format #10087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
OutputLogsMode, RunArgs,
},
config::ConfigurationOptions,
run::task_id::TaskId,
run::task_id::{TaskId, TaskName},
turbo_json::{UIMode, CONFIG_FILE},
Args,
};
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<'a> TaskArgs<'a> {
&& self
.tasks
.iter()
.any(|task| task.as_str() == task_id.task())
.any(|task| TaskName::from(task.as_str()).task() == task_id.task())
{
Some(self.pass_through_args)
} else {
Expand Down Expand Up @@ -550,12 +550,13 @@ mod test {
use turborepo_cache::{CacheActions, CacheConfig, CacheOpts};
use turborepo_ui::ColorConfig;

use super::{APIClientOpts, RepoOpts, RunOpts};
use super::{APIClientOpts, RepoOpts, RunOpts, TaskArgs};
use crate::{
cli::{Command, ContinueMode, DryRunMode, RunArgs},
commands::CommandBase,
config::ConfigurationOptions,
opts::{Opts, RunCacheOpts, ScopeOpts},
run::task_id::TaskId,
turbo_json::{UIMode, CONFIG_FILE},
Args,
};
Expand Down Expand Up @@ -876,4 +877,51 @@ mod test {

Ok(())
}

#[test_case(
vec!["build".to_string()],
vec!["passthrough".to_string()],
TaskId::new("web", "build"),
Some(vec!["passthrough".to_string()]);
"single task"
)]
#[test_case(
vec!["lint".to_string(), "build".to_string()],
vec!["passthrough".to_string()],
TaskId::new("web", "build"),
Some(vec!["passthrough".to_string()]);
"multiple tasks"
)]
#[test_case(
vec!["web#build".to_string()],
vec!["passthrough".to_string()],
TaskId::new("web", "build"),
Some(vec!["passthrough".to_string()]);
"task with package"
)]
#[test_case(
vec!["lint".to_string()],
vec![],
TaskId::new("ui", "lint"),
None;
"no passthrough args"
)]
fn test_get_args_for_tasks(
tasks: Vec<String>,
pass_through_args: Vec<String>,
expected_task: TaskId<'static>,
expected_args: Option<Vec<String>>,
) -> Result<(), anyhow::Error> {
let task_opts = TaskArgs {
tasks: &tasks,
pass_through_args: &pass_through_args,
};

assert_eq!(
task_opts.args_for_task(&expected_task),
expected_args.as_deref()
);

Ok(())
}
}
3 changes: 3 additions & 0 deletions turborepo-tests/integration/fixtures/passthrough/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.turbo
.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "my-app",
"scripts": {
"echo": "echo"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "monorepo",
"workspaces": [
"apps/**"
]
}
6 changes: 6 additions & 0 deletions turborepo-tests/integration/fixtures/passthrough/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"echo": {}
}
}
34 changes: 34 additions & 0 deletions turborepo-tests/integration/tests/passthrough-args.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Setup
$ . ${TESTDIR}/../../helpers/setup_integration_test.sh passthrough

$ ${TURBO} -F my-app echo -- hello
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running echo in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:echo: cache miss, executing c0813f759149b8af
my-app:echo:
my-app:echo: > echo
my-app:echo: > echo hello
my-app:echo:
my-app:echo: hello

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time: .*s (re)


$ ${TURBO} my-app#echo -- goodbye
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running my-app#echo in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:echo: cache miss, executing f4397252b3a3d780
my-app:echo:
my-app:echo: > echo
my-app:echo: > echo goodbye
my-app:echo:
my-app:echo: goodbye

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time: .*s (re)

Loading