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);
|
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime);
|
||||||
node_modules_arg_parse(flags, matches);
|
node_modules_arg_parse(flags, matches);
|
||||||
|
|
||||||
let filter = matches.remove_one::<String>("filter");
|
let mut recursive = matches.get_flag("recursive");
|
||||||
let recursive = matches.get_flag("recursive") || filter.is_some();
|
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 {
|
let mut task_flags = TaskFlags {
|
||||||
cwd: matches.remove_one::<String>("cwd"),
|
cwd: matches.remove_one::<String>("cwd"),
|
||||||
|
@ -10538,7 +10545,7 @@ mod tests {
|
||||||
cwd: None,
|
cwd: None,
|
||||||
task: Some("build".to_string()),
|
task: Some("build".to_string()),
|
||||||
is_run: false,
|
is_run: false,
|
||||||
recursive: true,
|
recursive: false,
|
||||||
filter: Some("*".to_string()),
|
filter: Some("*".to_string()),
|
||||||
eval: false,
|
eval: false,
|
||||||
}),
|
}),
|
||||||
|
@ -10555,7 +10562,7 @@ mod tests {
|
||||||
task: Some("build".to_string()),
|
task: Some("build".to_string()),
|
||||||
is_run: false,
|
is_run: false,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
filter: None,
|
filter: Some("*".to_string()),
|
||||||
eval: false,
|
eval: false,
|
||||||
}),
|
}),
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
|
@ -10571,7 +10578,7 @@ mod tests {
|
||||||
task: Some("build".to_string()),
|
task: Some("build".to_string()),
|
||||||
is_run: false,
|
is_run: false,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
filter: None,
|
filter: Some("*".to_string()),
|
||||||
eval: false,
|
eval: false,
|
||||||
}),
|
}),
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
|
|
|
@ -88,6 +88,7 @@ pub async fn execute_script(
|
||||||
&package_regex,
|
&package_regex,
|
||||||
filter,
|
filter,
|
||||||
force_use_pkg_json,
|
force_use_pkg_json,
|
||||||
|
task_flags.recursive,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
|
@ -97,7 +98,9 @@ pub async fn execute_script(
|
||||||
let mut packages_task_info: Vec<PackageTaskInfo> = vec![];
|
let mut packages_task_info: Vec<PackageTaskInfo> = vec![];
|
||||||
|
|
||||||
for folder in workspace.config_folders() {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,12 +703,15 @@ fn print_available_tasks_workspace(
|
||||||
package_regex: &Regex,
|
package_regex: &Regex,
|
||||||
filter: &str,
|
filter: &str,
|
||||||
force_use_pkg_json: bool,
|
force_use_pkg_json: bool,
|
||||||
|
recursive: bool,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let workspace = cli_options.workspace();
|
let workspace = cli_options.workspace();
|
||||||
|
|
||||||
let mut matched = false;
|
let mut matched = false;
|
||||||
for folder in workspace.config_folders() {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
matched = true;
|
matched = true;
|
||||||
|
|
|
@ -40,6 +40,21 @@
|
||||||
"args": "task --filter *",
|
"args": "task --filter *",
|
||||||
"output": "npm_filter_no_task.out"
|
"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": {
|
"deno_all": {
|
||||||
"cwd": "./deno",
|
"cwd": "./deno",
|
||||||
"args": "task --filter * dev",
|
"args": "task --filter * dev",
|
||||||
|
@ -74,6 +89,21 @@
|
||||||
"cwd": "./deno",
|
"cwd": "./deno",
|
||||||
"args": "task --filter *",
|
"args": "task --filter *",
|
||||||
"output": "deno_filter_no_task.out"
|
"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