Skip to content

Commit

Permalink
fix(task): --recursive option not working (#27183)
Browse files Browse the repository at this point in the history
We didn't handle the `--recursive` option properly in `deno task`. This
PR addresses that.

Fixes #27174
  • Loading branch information
marvinhagemeister authored and bartlomieju committed Dec 5, 2024
1 parent 65d0126 commit 5e809f9
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 7 deletions.
17 changes: 12 additions & 5 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>("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::<String>("filter") {
recursive = false;
Some(filter)
} else if recursive {
Some("*".to_string())
} else {
None
};

let mut task_flags = TaskFlags {
cwd: matches.remove_one::<String>("cwd"),
Expand Down Expand Up @@ -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,
}),
Expand All @@ -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()
Expand All @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions cli/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub async fn execute_script(
&package_regex,
filter,
force_use_pkg_json,
task_flags.recursive,
)?;

return Ok(0);
Expand All @@ -97,7 +98,9 @@ pub async fn execute_script(
let mut packages_task_info: Vec<PackageTaskInfo> = 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;
}

Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions tests/specs/task/filter/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
}
2 changes: 2 additions & 0 deletions tests/specs/task/filter/deno_filter_recursive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task dev echo '@deno/foo'
@deno/foo
4 changes: 4 additions & 0 deletions tests/specs/task/filter/deno_recursive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Task dev echo '@deno/bar'
@deno/bar
Task dev echo '@deno/foo'
@deno/foo
4 changes: 4 additions & 0 deletions tests/specs/task/filter/deno_recursive_no_pkg.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Task dev echo 'bar'
bar
Task dev echo 'foo'
foo
5 changes: 5 additions & 0 deletions tests/specs/task/filter/deno_recursive_no_pkg/bar/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"dev": "echo 'bar'"
}
}
6 changes: 6 additions & 0 deletions tests/specs/task/filter/deno_recursive_no_pkg/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"workspace": [
"./foo",
"./bar"
]
}
5 changes: 5 additions & 0 deletions tests/specs/task/filter/deno_recursive_no_pkg/foo/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"dev": "echo 'foo'"
}
}
2 changes: 2 additions & 0 deletions tests/specs/task/filter/npm_filter_recursive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task dev echo 'foo'
foo
4 changes: 4 additions & 0 deletions tests/specs/task/filter/npm_recursive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Task dev echo 'bar'
bar
Task dev echo 'foo'
foo
4 changes: 4 additions & 0 deletions tests/specs/task/filter/npm_recursive_no_pkg.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Task dev echo 'bar'
bar
Task dev echo 'foo'
foo
5 changes: 5 additions & 0 deletions tests/specs/task/filter/npm_recursive_no_pkg/bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"dev": "echo 'bar'"
}
}
5 changes: 5 additions & 0 deletions tests/specs/task/filter/npm_recursive_no_pkg/foo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"dev": "echo 'foo'"
}
}
3 changes: 3 additions & 0 deletions tests/specs/task/filter/npm_recursive_no_pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"workspaces": ["./foo", "./bar"]
}

0 comments on commit 5e809f9

Please sign in to comment.