mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
fix(task): --recursive
option not working (#27183)
We didn't handle the `--recursive` option properly in `deno task`. This PR addresses that. Fixes https://github.com/denoland/deno/issues/27174
This commit is contained in:
parent
ab4568a03d
commit
f098dd02f7
15 changed files with 99 additions and 7 deletions
|
@ -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"),
|
||||
|
@ -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()
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
tests/specs/task/filter/deno_filter_recursive.out
Normal file
2
tests/specs/task/filter/deno_filter_recursive.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo '@deno/foo'
|
||||
@deno/foo
|
4
tests/specs/task/filter/deno_recursive.out
Normal file
4
tests/specs/task/filter/deno_recursive.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@deno/bar'
|
||||
@deno/bar
|
||||
Task dev echo '@deno/foo'
|
||||
@deno/foo
|
4
tests/specs/task/filter/deno_recursive_no_pkg.out
Normal file
4
tests/specs/task/filter/deno_recursive_no_pkg.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo 'bar'
|
||||
bar
|
||||
Task dev echo 'foo'
|
||||
foo
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"tasks": {
|
||||
"dev": "echo 'bar'"
|
||||
}
|
||||
}
|
6
tests/specs/task/filter/deno_recursive_no_pkg/deno.json
Normal file
6
tests/specs/task/filter/deno_recursive_no_pkg/deno.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"workspace": [
|
||||
"./foo",
|
||||
"./bar"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"tasks": {
|
||||
"dev": "echo 'foo'"
|
||||
}
|
||||
}
|
2
tests/specs/task/filter/npm_filter_recursive.out
Normal file
2
tests/specs/task/filter/npm_filter_recursive.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo 'foo'
|
||||
foo
|
4
tests/specs/task/filter/npm_recursive.out
Normal file
4
tests/specs/task/filter/npm_recursive.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo 'bar'
|
||||
bar
|
||||
Task dev echo 'foo'
|
||||
foo
|
4
tests/specs/task/filter/npm_recursive_no_pkg.out
Normal file
4
tests/specs/task/filter/npm_recursive_no_pkg.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo 'bar'
|
||||
bar
|
||||
Task dev echo 'foo'
|
||||
foo
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"scripts": {
|
||||
"dev": "echo 'bar'"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"scripts": {
|
||||
"dev": "echo 'foo'"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaces": ["./foo", "./bar"]
|
||||
}
|
Loading…
Add table
Reference in a new issue