Skip to content

Commit

Permalink
fix: recursive handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Dec 5, 2024
1 parent d5dfb00 commit ecba2b2
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 3 deletions.
21 changes: 20 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ pub struct TaskFlags {
pub task: Option<String>,
pub is_run: bool,
pub filter: Option<String>,
pub recursive: bool,
pub eval: bool,
}

Expand Down Expand Up @@ -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::<String>("filter") {
Some(filter)
} else if matches.get_flag("recursive") {
} else if recursive {
Some("*".to_string())
} else {
None
Expand All @@ -5289,6 +5291,7 @@ fn task_parse(
task: None,
is_run: false,
filter,
recursive,
eval: matches.get_flag("eval"),
};

Expand Down Expand Up @@ -10493,6 +10496,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["hello", "world"],
Expand All @@ -10509,6 +10513,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
..Flags::default()
Expand All @@ -10524,6 +10529,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
..Flags::default()
Expand All @@ -10539,6 +10545,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: Some("*".to_string()),
recursive: false,
eval: false,
}),
..Flags::default()
Expand All @@ -10554,6 +10561,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: Some("*".to_string()),
recursive: true,
eval: false,
}),
..Flags::default()
Expand All @@ -10569,6 +10577,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: Some("*".to_string()),
recursive: true,
eval: false,
}),
..Flags::default()
Expand All @@ -10584,6 +10593,7 @@ mod tests {
task: Some("echo 1".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: true,
}),
..Flags::default()
Expand Down Expand Up @@ -10614,6 +10624,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["--", "hello", "world"],
Expand All @@ -10633,6 +10644,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["--", "hello", "world"],
Expand All @@ -10653,6 +10665,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["--"],
Expand All @@ -10672,6 +10685,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["-1", "--test"],
Expand All @@ -10691,6 +10705,7 @@ mod tests {
task: Some("build".to_string()),
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
argv: svec!["--test"],
Expand All @@ -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),
Expand All @@ -10730,6 +10746,7 @@ mod tests {
task: None,
is_run: false,
filter: None,
recursive: false,
eval: false,
}),
..Flags::default()
Expand All @@ -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()),
Expand All @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
task: Some(run_flags.script.clone()),
is_run: true,
filter: None,
recursive: false,
eval: false,
};
new_flags.subcommand = DenoSubcommand::Task(task_flags.clone());
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
10 changes: 10 additions & 0 deletions tests/specs/task/filter/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
}
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'"
}
}
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 ecba2b2

Please sign in to comment.