From ecba2b20d2f9997a1f166c5ce97af47d4dfbf190 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 5 Dec 2024 14:55:57 +0100 Subject: [PATCH] fix: recursive handling --- cli/args/flags.rs | 21 ++++++++++++++++++- cli/main.rs | 1 + cli/tools/task.rs | 10 +++++++-- tests/specs/task/filter/__test__.jsonc | 10 +++++++++ .../task/filter/deno_recursive_no_pkg.out | 4 ++++ .../deno_recursive_no_pkg/bar/deno.json | 5 +++++ .../filter/deno_recursive_no_pkg/deno.json | 6 ++++++ .../deno_recursive_no_pkg/foo/deno.json | 5 +++++ .../task/filter/npm_recursive_no_pkg.out | 4 ++++ .../npm_recursive_no_pkg/bar/package.json | 5 +++++ .../npm_recursive_no_pkg/foo/package.json | 5 +++++ .../filter/npm_recursive_no_pkg/package.json | 3 +++ 12 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 tests/specs/task/filter/deno_recursive_no_pkg.out create mode 100644 tests/specs/task/filter/deno_recursive_no_pkg/bar/deno.json create mode 100644 tests/specs/task/filter/deno_recursive_no_pkg/deno.json create mode 100644 tests/specs/task/filter/deno_recursive_no_pkg/foo/deno.json create mode 100644 tests/specs/task/filter/npm_recursive_no_pkg.out create mode 100644 tests/specs/task/filter/npm_recursive_no_pkg/bar/package.json create mode 100644 tests/specs/task/filter/npm_recursive_no_pkg/foo/package.json create mode 100644 tests/specs/task/filter/npm_recursive_no_pkg/package.json diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 95441cd032c613..aed402b25f0667 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -383,6 +383,7 @@ pub struct TaskFlags { pub task: Option, pub is_run: bool, pub filter: Option, + pub recursive: bool, pub eval: bool, } @@ -5276,9 +5277,10 @@ fn task_parse( unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime); node_modules_arg_parse(flags, matches); + let recursive = matches.get_flag("recursive"); let filter = if let Some(filter) = matches.remove_one::("filter") { Some(filter) - } else if matches.get_flag("recursive") { + } else if recursive { Some("*".to_string()) } else { None @@ -5289,6 +5291,7 @@ fn task_parse( task: None, is_run: false, filter, + recursive, eval: matches.get_flag("eval"), }; @@ -10493,6 +10496,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["hello", "world"], @@ -10509,6 +10513,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), ..Flags::default() @@ -10524,6 +10529,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), ..Flags::default() @@ -10539,6 +10545,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: Some("*".to_string()), + recursive: false, eval: false, }), ..Flags::default() @@ -10554,6 +10561,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: Some("*".to_string()), + recursive: true, eval: false, }), ..Flags::default() @@ -10569,6 +10577,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: Some("*".to_string()), + recursive: true, eval: false, }), ..Flags::default() @@ -10584,6 +10593,7 @@ mod tests { task: Some("echo 1".to_string()), is_run: false, filter: None, + recursive: false, eval: true, }), ..Flags::default() @@ -10614,6 +10624,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["--", "hello", "world"], @@ -10633,6 +10644,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["--", "hello", "world"], @@ -10653,6 +10665,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["--"], @@ -10672,6 +10685,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["-1", "--test"], @@ -10691,6 +10705,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), argv: svec!["--test"], @@ -10711,6 +10726,7 @@ mod tests { task: Some("build".to_string()), is_run: false, filter: None, + recursive: false, eval: false, }), log_level: Some(log::Level::Error), @@ -10730,6 +10746,7 @@ mod tests { task: None, is_run: false, filter: None, + recursive: false, eval: false, }), ..Flags::default() @@ -10748,6 +10765,7 @@ mod tests { task: None, is_run: false, filter: None, + recursive: false, eval: false, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), @@ -10767,6 +10785,7 @@ mod tests { task: None, is_run: false, filter: None, + recursive: false, eval: false, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), diff --git a/cli/main.rs b/cli/main.rs index 66d21df5e1d608..6c9b6d2223fd46 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -242,6 +242,7 @@ async fn run_subcommand(flags: Arc) -> Result { task: Some(run_flags.script.clone()), is_run: true, filter: None, + recursive: false, eval: false, }; new_flags.subcommand = DenoSubcommand::Task(task_flags.clone()); 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 9723490b76c4fa..7a0fef51a625d1 100644 --- a/tests/specs/task/filter/__test__.jsonc +++ b/tests/specs/task/filter/__test__.jsonc @@ -45,6 +45,11 @@ "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" + }, "deno_all": { "cwd": "./deno", "args": "task --filter * dev", @@ -84,6 +89,11 @@ "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" } } } 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_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"] +}