Skip to content

Commit

Permalink
feat(task): workspace support with --filter and --recursive (#26949)
Browse files Browse the repository at this point in the history
This commit adds workspace support to "deno taks".

Two new flags were added:
- "--recursive" - allows to run a specified task in workspace members,
eg. "deno task --recursive dev"
- "--filter" - allows to run a specified task only in specific workspace members,
eg. "deno task --recursive --filter 'client/*' dev"

"--filter" flag implies "--recursive" flag.

Closes #24991

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Signed-off-by: David Sherret <dsherret@users.noreply.github.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
Co-authored-by: David Sherret <dsherret@gmail.com>
  • Loading branch information
5 people authored Nov 20, 2024
1 parent b729bf0 commit f0b245c
Show file tree
Hide file tree
Showing 43 changed files with 541 additions and 78 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ deno_ast = { version = "=0.43.3", features = ["transpiling"] }
deno_core = { version = "0.321.0" }

deno_bench_util = { version = "0.171.0", path = "./bench_util" }
deno_config = { version = "=0.39.1", features = ["workspace", "sync"] }
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }
deno_lockfile = "=0.23.1"
deno_media_type = { version = "0.2.0", features = ["module_specifier"] }
deno_npm = "=0.25.4"
Expand Down
97 changes: 96 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ pub struct TaskFlags {
pub cwd: Option<String>,
pub task: Option<String>,
pub is_run: bool,
pub recursive: bool,
pub filter: Option<String>,
pub eval: bool,
}

Expand Down Expand Up @@ -3046,13 +3048,27 @@ Evaluate a task from string
.help("Specify the directory to run the task in")
.value_hint(ValueHint::DirPath),
)
.arg(
Arg::new("recursive")
.long("recursive")
.short('r')
.help("Run the task in all projects in the workspace")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("filter")
.long("filter")
.short('f')
.help("Filter members of the workspace by name - should be used with --recursive")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("eval")
.long("eval")
.help(
"Evaluate the passed value as if, it was a task in a configuration file",
).action(ArgAction::SetTrue)
)
)
.arg(node_modules_dir_arg())
})
}
Expand Down Expand Up @@ -5212,10 +5228,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 task_flags = TaskFlags {
cwd: matches.remove_one::<String>("cwd"),
task: None,
is_run: false,
recursive,
filter,
eval: matches.get_flag("eval"),
};

Expand Down Expand Up @@ -10418,6 +10439,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["hello", "world"],
Expand All @@ -10433,6 +10456,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
..Flags::default()
Expand All @@ -10447,6 +10472,56 @@ mod tests {
cwd: Some("foo".to_string()),
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
..Flags::default()
}
);

let r = flags_from_vec(svec!["deno", "task", "--filter", "*", "build"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Task(TaskFlags {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: true,
filter: Some("*".to_string()),
eval: false,
}),
..Flags::default()
}
);

let r = flags_from_vec(svec!["deno", "task", "--recursive", "build"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Task(TaskFlags {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: true,
filter: None,
eval: false,
}),
..Flags::default()
}
);

let r = flags_from_vec(svec!["deno", "task", "-r", "build"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Task(TaskFlags {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: true,
filter: None,
eval: false,
}),
..Flags::default()
Expand All @@ -10461,6 +10536,8 @@ mod tests {
cwd: None,
task: Some("echo 1".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: true,
}),
..Flags::default()
Expand Down Expand Up @@ -10490,6 +10567,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["--", "hello", "world"],
Expand All @@ -10508,6 +10587,8 @@ mod tests {
cwd: Some("foo".to_string()),
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["--", "hello", "world"],
Expand All @@ -10527,6 +10608,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["--"],
Expand All @@ -10545,6 +10628,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["-1", "--test"],
Expand All @@ -10563,6 +10648,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
argv: svec!["--test"],
Expand All @@ -10582,6 +10669,8 @@ mod tests {
cwd: None,
task: Some("build".to_string()),
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
log_level: Some(log::Level::Error),
Expand All @@ -10600,6 +10689,8 @@ mod tests {
cwd: None,
task: None,
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
..Flags::default()
Expand All @@ -10617,6 +10708,8 @@ mod tests {
cwd: None,
task: None,
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
Expand All @@ -10635,6 +10728,8 @@ mod tests {
cwd: None,
task: None,
is_run: false,
recursive: false,
filter: None,
eval: false,
}),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
Expand Down
2 changes: 2 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
cwd: None,
task: Some(run_flags.script.clone()),
is_run: true,
recursive: false,
filter: None,
eval: false,
};
new_flags.subcommand = DenoSubcommand::Task(task_flags.clone());
Expand Down
Loading

0 comments on commit f0b245c

Please sign in to comment.