diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c08d81abb05fb7..cdeaa1b335682c 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -5277,8 +5277,15 @@ fn task_parse( unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime); node_modules_arg_parse(flags, matches); - let filter = matches.remove_one::("filter"); - let recursive = matches.get_flag("recursive") || filter.is_some(); + let mut recursive = matches.get_flag("recursive"); + let filter = if let Some(filter) = matches.remove_one::("filter") { + recursive = false; + Some(filter) + } else if recursive { + Some("*".to_string()) + } else { + None + }; let mut task_flags = TaskFlags { cwd: matches.remove_one::("cwd"), @@ -10538,7 +10545,7 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, - recursive: true, + recursive: false, filter: Some("*".to_string()), eval: false, }), @@ -10555,7 +10562,7 @@ mod tests { task: Some("build".to_string()), is_run: false, recursive: true, - filter: None, + filter: Some("*".to_string()), eval: false, }), ..Flags::default() @@ -10571,7 +10578,7 @@ mod tests { task: Some("build".to_string()), is_run: false, recursive: true, - filter: None, + filter: Some("*".to_string()), eval: false, }), ..Flags::default() diff --git a/cli/tools/task.rs b/cli/tools/task.rs index 01d6ac16ee5fc3..fc1410aa0e2f6d 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -88,6 +88,7 @@ pub async fn execute_script( &package_regex, filter, force_use_pkg_json, + task_flags.recursive, )?; return Ok(0); @@ -97,7 +98,9 @@ pub async fn execute_script( let mut packages_task_info: Vec = vec![]; for folder in workspace.config_folders() { - if !matches_package(folder.1, force_use_pkg_json, &package_regex) { + if !task_flags.recursive + && !matches_package(folder.1, force_use_pkg_json, &package_regex) + { continue; } @@ -700,12 +703,15 @@ fn print_available_tasks_workspace( package_regex: &Regex, filter: &str, force_use_pkg_json: bool, + recursive: bool, ) -> Result<(), AnyError> { let workspace = cli_options.workspace(); let mut matched = false; for folder in workspace.config_folders() { - if !matches_package(folder.1, force_use_pkg_json, package_regex) { + if !recursive + && !matches_package(folder.1, force_use_pkg_json, package_regex) + { continue; } matched = true; diff --git a/tests/specs/task/filter/__test__.jsonc b/tests/specs/task/filter/__test__.jsonc index 45f4e7d7d8b163..10e2e8f6db9b77 100644 --- a/tests/specs/task/filter/__test__.jsonc +++ b/tests/specs/task/filter/__test__.jsonc @@ -40,6 +40,21 @@ "args": "task --filter *", "output": "npm_filter_no_task.out" }, + "npm_recursive": { + "cwd": "./npm", + "args": "task -r dev", + "output": "npm_recursive.out" + }, + "npm_recursive_no_pkg": { + "cwd": "./npm_recursive_no_pkg", + "args": "task -r dev", + "output": "npm_recursive_no_pkg.out" + }, + "npm_filter_recursive": { + "cwd": "./npm", + "args": "task -r --filter foo dev", + "output": "npm_filter_recursive.out" + }, "deno_all": { "cwd": "./deno", "args": "task --filter * dev", @@ -74,6 +89,21 @@ "cwd": "./deno", "args": "task --filter *", "output": "deno_filter_no_task.out" + }, + "deno_recursive": { + "cwd": "./deno", + "args": "task -r dev", + "output": "deno_recursive.out" + }, + "deno_recursive_no_pkg": { + "cwd": "./deno_recursive_no_pkg", + "args": "task -r dev", + "output": "deno_recursive_no_pkg.out" + }, + "deno_filter_recursive": { + "cwd": "./deno", + "args": "task -r --filter @deno/foo dev", + "output": "deno_filter_recursive.out" } } } diff --git a/tests/specs/task/filter/deno_filter_recursive.out b/tests/specs/task/filter/deno_filter_recursive.out new file mode 100644 index 00000000000000..4bfebd6e929077 --- /dev/null +++ b/tests/specs/task/filter/deno_filter_recursive.out @@ -0,0 +1,2 @@ +Task dev echo '@deno/foo' +@deno/foo diff --git a/tests/specs/task/filter/deno_recursive.out b/tests/specs/task/filter/deno_recursive.out new file mode 100644 index 00000000000000..c3c34415597c3a --- /dev/null +++ b/tests/specs/task/filter/deno_recursive.out @@ -0,0 +1,4 @@ +Task dev echo '@deno/bar' +@deno/bar +Task dev echo '@deno/foo' +@deno/foo diff --git a/tests/specs/task/filter/deno_recursive_no_pkg.out b/tests/specs/task/filter/deno_recursive_no_pkg.out new file mode 100644 index 00000000000000..592d4640cd1e25 --- /dev/null +++ b/tests/specs/task/filter/deno_recursive_no_pkg.out @@ -0,0 +1,4 @@ +Task dev echo 'bar' +bar +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/deno_recursive_no_pkg/bar/deno.json b/tests/specs/task/filter/deno_recursive_no_pkg/bar/deno.json new file mode 100644 index 00000000000000..6a93295d979b2d --- /dev/null +++ b/tests/specs/task/filter/deno_recursive_no_pkg/bar/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "dev": "echo 'bar'" + } +} diff --git a/tests/specs/task/filter/deno_recursive_no_pkg/deno.json b/tests/specs/task/filter/deno_recursive_no_pkg/deno.json new file mode 100644 index 00000000000000..133ab666b4abd5 --- /dev/null +++ b/tests/specs/task/filter/deno_recursive_no_pkg/deno.json @@ -0,0 +1,6 @@ +{ + "workspace": [ + "./foo", + "./bar" + ] +} diff --git a/tests/specs/task/filter/deno_recursive_no_pkg/foo/deno.json b/tests/specs/task/filter/deno_recursive_no_pkg/foo/deno.json new file mode 100644 index 00000000000000..64a4cbccf01048 --- /dev/null +++ b/tests/specs/task/filter/deno_recursive_no_pkg/foo/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "dev": "echo 'foo'" + } +} diff --git a/tests/specs/task/filter/npm_filter_recursive.out b/tests/specs/task/filter/npm_filter_recursive.out new file mode 100644 index 00000000000000..f879b66df86830 --- /dev/null +++ b/tests/specs/task/filter/npm_filter_recursive.out @@ -0,0 +1,2 @@ +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/npm_recursive.out b/tests/specs/task/filter/npm_recursive.out new file mode 100644 index 00000000000000..592d4640cd1e25 --- /dev/null +++ b/tests/specs/task/filter/npm_recursive.out @@ -0,0 +1,4 @@ +Task dev echo 'bar' +bar +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/npm_recursive_no_pkg.out b/tests/specs/task/filter/npm_recursive_no_pkg.out new file mode 100644 index 00000000000000..592d4640cd1e25 --- /dev/null +++ b/tests/specs/task/filter/npm_recursive_no_pkg.out @@ -0,0 +1,4 @@ +Task dev echo 'bar' +bar +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/npm_recursive_no_pkg/bar/package.json b/tests/specs/task/filter/npm_recursive_no_pkg/bar/package.json new file mode 100644 index 00000000000000..cc1907fab4d3d4 --- /dev/null +++ b/tests/specs/task/filter/npm_recursive_no_pkg/bar/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "dev": "echo 'bar'" + } +} diff --git a/tests/specs/task/filter/npm_recursive_no_pkg/foo/package.json b/tests/specs/task/filter/npm_recursive_no_pkg/foo/package.json new file mode 100644 index 00000000000000..636dcd13bd3cbb --- /dev/null +++ b/tests/specs/task/filter/npm_recursive_no_pkg/foo/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "dev": "echo 'foo'" + } +} diff --git a/tests/specs/task/filter/npm_recursive_no_pkg/package.json b/tests/specs/task/filter/npm_recursive_no_pkg/package.json new file mode 100644 index 00000000000000..2d70009f2ca46b --- /dev/null +++ b/tests/specs/task/filter/npm_recursive_no_pkg/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./foo", "./bar"] +}