diff --git a/crates/turborepo-lib/src/opts.rs b/crates/turborepo-lib/src/opts.rs index b72eb7aa8a96c..28af416109c93 100644 --- a/crates/turborepo-lib/src/opts.rs +++ b/crates/turborepo-lib/src/opts.rs @@ -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, }; @@ -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 { @@ -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, }; @@ -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, + pass_through_args: Vec, + expected_task: TaskId<'static>, + expected_args: Option>, + ) -> 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(()) + } } diff --git a/turborepo-tests/integration/fixtures/passthrough/.gitignore b/turborepo-tests/integration/fixtures/passthrough/.gitignore new file mode 100644 index 0000000000000..77af9fc60321d --- /dev/null +++ b/turborepo-tests/integration/fixtures/passthrough/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.turbo +.npmrc diff --git a/turborepo-tests/integration/fixtures/passthrough/apps/my-app/.env.local b/turborepo-tests/integration/fixtures/passthrough/apps/my-app/.env.local new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/turborepo-tests/integration/fixtures/passthrough/apps/my-app/package.json b/turborepo-tests/integration/fixtures/passthrough/apps/my-app/package.json new file mode 100644 index 0000000000000..64be4aef4f1fc --- /dev/null +++ b/turborepo-tests/integration/fixtures/passthrough/apps/my-app/package.json @@ -0,0 +1,6 @@ +{ + "name": "my-app", + "scripts": { + "echo": "echo" + } +} diff --git a/turborepo-tests/integration/fixtures/passthrough/package.json b/turborepo-tests/integration/fixtures/passthrough/package.json new file mode 100644 index 0000000000000..9557291c8197e --- /dev/null +++ b/turborepo-tests/integration/fixtures/passthrough/package.json @@ -0,0 +1,6 @@ +{ + "name": "monorepo", + "workspaces": [ + "apps/**" + ] +} diff --git a/turborepo-tests/integration/fixtures/passthrough/turbo.json b/turborepo-tests/integration/fixtures/passthrough/turbo.json new file mode 100644 index 0000000000000..1a9adbeb779a7 --- /dev/null +++ b/turborepo-tests/integration/fixtures/passthrough/turbo.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://turbo.build/schema.json", + "tasks": { + "echo": {} + } +} diff --git a/turborepo-tests/integration/tests/passthrough-args.t b/turborepo-tests/integration/tests/passthrough-args.t new file mode 100644 index 0000000000000..3e8d6e141925a --- /dev/null +++ b/turborepo-tests/integration/tests/passthrough-args.t @@ -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) +