mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 05:42:25 -05:00
feat(task): workspace support with --filter and --recursive (#26949)
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 https://github.com/denoland/deno/issues/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>
This commit is contained in:
parent
b729bf0ad9
commit
f0b245c8ee
43 changed files with 541 additions and 78 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1435,9 +1435,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_config"
|
||||
version = "0.39.1"
|
||||
version = "0.39.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a91aa99751ebe305a7edad12a3ad751f3b3b9f5ecddbfe4a0459e3cdc8493b6"
|
||||
checksum = "38fb809500238be2b10eee42944a47b3ac38974e1edbb47f73afcfca7df143bf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"deno_package_json",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
})
|
||||
}
|
||||
|
@ -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"),
|
||||
};
|
||||
|
||||
|
@ -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"],
|
||||
|
@ -10433,6 +10456,8 @@ mod tests {
|
|||
cwd: None,
|
||||
task: Some("build".to_string()),
|
||||
is_run: false,
|
||||
recursive: false,
|
||||
filter: None,
|
||||
eval: false,
|
||||
}),
|
||||
..Flags::default()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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"],
|
||||
|
@ -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"],
|
||||
|
@ -10527,6 +10608,8 @@ mod tests {
|
|||
cwd: None,
|
||||
task: Some("build".to_string()),
|
||||
is_run: false,
|
||||
recursive: false,
|
||||
filter: None,
|
||||
eval: false,
|
||||
}),
|
||||
argv: svec!["--"],
|
||||
|
@ -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"],
|
||||
|
@ -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"],
|
||||
|
@ -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),
|
||||
|
@ -10600,6 +10689,8 @@ mod tests {
|
|||
cwd: None,
|
||||
task: None,
|
||||
is_run: false,
|
||||
recursive: false,
|
||||
filter: None,
|
||||
eval: false,
|
||||
}),
|
||||
..Flags::default()
|
||||
|
@ -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()),
|
||||
|
@ -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()),
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::path::PathBuf;
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_config::workspace::FolderConfigs;
|
||||
use deno_config::workspace::TaskDefinition;
|
||||
use deno_config::workspace::TaskOrScript;
|
||||
use deno_config::workspace::WorkspaceDirectory;
|
||||
|
@ -25,6 +26,7 @@ use deno_path_util::normalize_path;
|
|||
use deno_runtime::deno_node::NodeResolver;
|
||||
use deno_task_shell::ShellCommand;
|
||||
use indexmap::IndexMap;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::args::CliOptions;
|
||||
use crate::args::Flags;
|
||||
|
@ -35,6 +37,12 @@ use crate::npm::CliNpmResolver;
|
|||
use crate::task_runner;
|
||||
use crate::util::fs::canonicalize_path;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PackageTaskInfo {
|
||||
matched_tasks: Vec<String>,
|
||||
tasks_config: WorkspaceTasksConfig,
|
||||
}
|
||||
|
||||
pub async fn execute_script(
|
||||
flags: Arc<Flags>,
|
||||
task_flags: TaskFlags,
|
||||
|
@ -55,18 +63,145 @@ pub async fn execute_script(
|
|||
v == "1"
|
||||
})
|
||||
.unwrap_or(false);
|
||||
let mut tasks_config = start_dir.to_tasks_config()?;
|
||||
if force_use_pkg_json {
|
||||
tasks_config = tasks_config.with_only_pkg_json()
|
||||
|
||||
fn arg_to_regex(input: &str) -> Result<regex::Regex, regex::Error> {
|
||||
let mut regex_str = regex::escape(input);
|
||||
regex_str = regex_str.replace("\\*", ".*");
|
||||
|
||||
Regex::new(®ex_str)
|
||||
}
|
||||
|
||||
let Some(task_name) = &task_flags.task else {
|
||||
print_available_tasks(
|
||||
&mut std::io::stdout(),
|
||||
&cli_options.start_dir,
|
||||
&tasks_config,
|
||||
)?;
|
||||
return Ok(0);
|
||||
let packages_task_configs: Vec<PackageTaskInfo> = if let Some(filter) =
|
||||
&task_flags.filter
|
||||
{
|
||||
let task_name = task_flags.task.as_ref().unwrap();
|
||||
|
||||
// Filter based on package name
|
||||
let package_regex = arg_to_regex(filter)?;
|
||||
let task_regex = arg_to_regex(task_name)?;
|
||||
|
||||
let mut packages_task_info: Vec<PackageTaskInfo> = vec![];
|
||||
|
||||
fn matches_package(
|
||||
config: &FolderConfigs,
|
||||
force_use_pkg_json: bool,
|
||||
regex: &Regex,
|
||||
) -> bool {
|
||||
if !force_use_pkg_json {
|
||||
if let Some(deno_json) = &config.deno_json {
|
||||
if let Some(name) = &deno_json.json.name {
|
||||
if regex.is_match(name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(package_json) = &config.pkg_json {
|
||||
if let Some(name) = &package_json.name {
|
||||
if regex.is_match(name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
let workspace = cli_options.workspace();
|
||||
for folder in workspace.config_folders() {
|
||||
if !matches_package(folder.1, force_use_pkg_json, &package_regex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let member_dir = workspace.resolve_member_dir(folder.0);
|
||||
let mut tasks_config = member_dir.to_tasks_config()?;
|
||||
if force_use_pkg_json {
|
||||
tasks_config = tasks_config.with_only_pkg_json();
|
||||
}
|
||||
|
||||
// Any of the matched tasks could be a child task of another matched
|
||||
// one. Therefore we need to filter these out to ensure that every
|
||||
// task is only run once.
|
||||
let mut matched: HashSet<String> = HashSet::new();
|
||||
let mut visited: HashSet<String> = HashSet::new();
|
||||
|
||||
fn visit_task(
|
||||
tasks_config: &WorkspaceTasksConfig,
|
||||
visited: &mut HashSet<String>,
|
||||
name: &str,
|
||||
) {
|
||||
if visited.contains(name) {
|
||||
return;
|
||||
}
|
||||
|
||||
visited.insert(name.to_string());
|
||||
|
||||
if let Some((_, TaskOrScript::Task(_, task))) = &tasks_config.task(name)
|
||||
{
|
||||
for dep in &task.dependencies {
|
||||
visit_task(tasks_config, visited, dep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Match tasks in deno.json
|
||||
for name in tasks_config.task_names() {
|
||||
if task_regex.is_match(name) && !visited.contains(name) {
|
||||
matched.insert(name.to_string());
|
||||
visit_task(&tasks_config, &mut visited, name);
|
||||
}
|
||||
}
|
||||
|
||||
packages_task_info.push(PackageTaskInfo {
|
||||
matched_tasks: matched
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<_>>(),
|
||||
tasks_config,
|
||||
});
|
||||
}
|
||||
|
||||
// Logging every task definition would be too spammy. Pnpm only
|
||||
// logs a simple message too.
|
||||
if packages_task_info
|
||||
.iter()
|
||||
.all(|config| config.matched_tasks.is_empty())
|
||||
{
|
||||
log::warn!(
|
||||
"{}",
|
||||
colors::red(format!(
|
||||
"No matching task or script '{}' found in selected packages.",
|
||||
task_name
|
||||
))
|
||||
);
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
// FIXME: Sort packages topologically
|
||||
//
|
||||
|
||||
packages_task_info
|
||||
} else {
|
||||
let mut tasks_config = start_dir.to_tasks_config()?;
|
||||
|
||||
if force_use_pkg_json {
|
||||
tasks_config = tasks_config.with_only_pkg_json()
|
||||
}
|
||||
|
||||
let Some(task_name) = &task_flags.task else {
|
||||
print_available_tasks(
|
||||
&mut std::io::stdout(),
|
||||
&cli_options.start_dir,
|
||||
&tasks_config,
|
||||
)?;
|
||||
return Ok(0);
|
||||
};
|
||||
|
||||
vec![PackageTaskInfo {
|
||||
tasks_config,
|
||||
matched_tasks: vec![task_name.to_string()],
|
||||
}]
|
||||
};
|
||||
|
||||
let npm_resolver = factory.npm_resolver().await?;
|
||||
|
@ -81,7 +216,6 @@ pub async fn execute_script(
|
|||
.unwrap_or_else(|| NonZeroUsize::new(2).unwrap());
|
||||
|
||||
let task_runner = TaskRunner {
|
||||
tasks_config,
|
||||
task_flags: &task_flags,
|
||||
npm_resolver: npm_resolver.as_ref(),
|
||||
node_resolver: node_resolver.as_ref(),
|
||||
|
@ -94,7 +228,7 @@ pub async fn execute_script(
|
|||
return task_runner
|
||||
.run_deno_task(
|
||||
&Url::from_directory_path(cli_options.initial_cwd()).unwrap(),
|
||||
&"".to_string(),
|
||||
"",
|
||||
&TaskDefinition {
|
||||
command: task_flags.task.as_ref().unwrap().to_string(),
|
||||
dependencies: vec![],
|
||||
|
@ -103,7 +237,15 @@ pub async fn execute_script(
|
|||
)
|
||||
.await;
|
||||
}
|
||||
task_runner.run_task(task_name).await
|
||||
|
||||
for task_config in &packages_task_configs {
|
||||
let exit_code = task_runner.run_tasks(task_config).await?;
|
||||
if exit_code > 0 {
|
||||
return Ok(exit_code);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
struct RunSingleOptions<'a> {
|
||||
|
@ -114,7 +256,6 @@ struct RunSingleOptions<'a> {
|
|||
}
|
||||
|
||||
struct TaskRunner<'a> {
|
||||
tasks_config: WorkspaceTasksConfig,
|
||||
task_flags: &'a TaskFlags,
|
||||
npm_resolver: &'a dyn CliNpmResolver,
|
||||
node_resolver: &'a NodeResolver,
|
||||
|
@ -124,12 +265,16 @@ struct TaskRunner<'a> {
|
|||
}
|
||||
|
||||
impl<'a> TaskRunner<'a> {
|
||||
pub async fn run_task(
|
||||
pub async fn run_tasks(
|
||||
&self,
|
||||
task_name: &str,
|
||||
pkg_tasks_config: &PackageTaskInfo,
|
||||
) -> Result<i32, deno_core::anyhow::Error> {
|
||||
match sort_tasks_topo(task_name, &self.tasks_config) {
|
||||
Ok(sorted) => self.run_tasks_in_parallel(sorted).await,
|
||||
match sort_tasks_topo(pkg_tasks_config) {
|
||||
Ok(sorted) => {
|
||||
self
|
||||
.run_tasks_in_parallel(&pkg_tasks_config.tasks_config, sorted)
|
||||
.await
|
||||
}
|
||||
Err(err) => match err {
|
||||
TaskError::NotFound(name) => {
|
||||
if self.task_flags.is_run {
|
||||
|
@ -138,7 +283,7 @@ impl<'a> TaskRunner<'a> {
|
|||
|
||||
log::error!("Task not found: {}", name);
|
||||
if log::log_enabled!(log::Level::Error) {
|
||||
self.print_available_tasks()?;
|
||||
self.print_available_tasks(&pkg_tasks_config.tasks_config)?;
|
||||
}
|
||||
Ok(1)
|
||||
}
|
||||
|
@ -150,16 +295,20 @@ impl<'a> TaskRunner<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn print_available_tasks(&self) -> Result<(), std::io::Error> {
|
||||
pub fn print_available_tasks(
|
||||
&self,
|
||||
tasks_config: &WorkspaceTasksConfig,
|
||||
) -> Result<(), std::io::Error> {
|
||||
print_available_tasks(
|
||||
&mut std::io::stderr(),
|
||||
&self.cli_options.start_dir,
|
||||
&self.tasks_config,
|
||||
tasks_config,
|
||||
)
|
||||
}
|
||||
|
||||
async fn run_tasks_in_parallel(
|
||||
&self,
|
||||
tasks_config: &WorkspaceTasksConfig,
|
||||
task_names: Vec<String>,
|
||||
) -> Result<i32, deno_core::anyhow::Error> {
|
||||
struct PendingTasksContext {
|
||||
|
@ -181,22 +330,23 @@ impl<'a> TaskRunner<'a> {
|
|||
fn get_next_task<'a>(
|
||||
&mut self,
|
||||
runner: &'a TaskRunner<'a>,
|
||||
tasks_config: &'a WorkspaceTasksConfig,
|
||||
) -> Option<LocalBoxFuture<'a, Result<(i32, String), AnyError>>> {
|
||||
for name in &self.task_names {
|
||||
if self.completed.contains(name) || self.running.contains(name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let should_run = if let Ok((_, def)) = runner.get_task(name) {
|
||||
match def {
|
||||
TaskOrScript::Task(_, def) => def
|
||||
.dependencies
|
||||
.iter()
|
||||
.all(|dep| self.completed.contains(dep)),
|
||||
TaskOrScript::Script(_, _) => true,
|
||||
}
|
||||
} else {
|
||||
false
|
||||
let Some((folder_url, task_or_script)) = tasks_config.task(name)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let should_run = match task_or_script {
|
||||
TaskOrScript::Task(_, def) => def
|
||||
.dependencies
|
||||
.iter()
|
||||
.all(|dep| self.completed.contains(dep)),
|
||||
TaskOrScript::Script(_, _) => true,
|
||||
};
|
||||
|
||||
if !should_run {
|
||||
|
@ -207,10 +357,15 @@ impl<'a> TaskRunner<'a> {
|
|||
let name = name.clone();
|
||||
return Some(
|
||||
async move {
|
||||
runner
|
||||
.run_task_no_dependencies(&name)
|
||||
.await
|
||||
.map(|exit_code| (exit_code, name))
|
||||
match task_or_script {
|
||||
TaskOrScript::Task(_, def) => {
|
||||
runner.run_deno_task(folder_url, &name, def).await
|
||||
}
|
||||
TaskOrScript::Script(scripts, _) => {
|
||||
runner.run_npm_script(folder_url, &name, scripts).await
|
||||
}
|
||||
}
|
||||
.map(|exit_code| (exit_code, name))
|
||||
}
|
||||
.boxed_local(),
|
||||
);
|
||||
|
@ -229,7 +384,7 @@ impl<'a> TaskRunner<'a> {
|
|||
|
||||
while context.has_remaining_tasks() {
|
||||
while queue.len() < self.concurrency {
|
||||
if let Some(task) = context.get_next_task(self) {
|
||||
if let Some(task) = context.get_next_task(self, tasks_config) {
|
||||
queue.push(task);
|
||||
} else {
|
||||
break;
|
||||
|
@ -253,37 +408,10 @@ impl<'a> TaskRunner<'a> {
|
|||
Ok(0)
|
||||
}
|
||||
|
||||
fn get_task(
|
||||
&self,
|
||||
task_name: &str,
|
||||
) -> Result<(&Url, TaskOrScript), TaskError> {
|
||||
let Some(result) = self.tasks_config.task(task_name) else {
|
||||
return Err(TaskError::NotFound(task_name.to_string()));
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
async fn run_task_no_dependencies(
|
||||
&self,
|
||||
task_name: &String,
|
||||
) -> Result<i32, deno_core::anyhow::Error> {
|
||||
let (dir_url, task_or_script) = self.get_task(task_name.as_str()).unwrap();
|
||||
|
||||
match task_or_script {
|
||||
TaskOrScript::Task(_tasks, definition) => {
|
||||
self.run_deno_task(dir_url, task_name, definition).await
|
||||
}
|
||||
TaskOrScript::Script(scripts, _script) => {
|
||||
self.run_npm_script(dir_url, task_name, scripts).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_deno_task(
|
||||
pub async fn run_deno_task(
|
||||
&self,
|
||||
dir_url: &Url,
|
||||
task_name: &String,
|
||||
task_name: &str,
|
||||
definition: &TaskDefinition,
|
||||
) -> Result<i32, deno_core::anyhow::Error> {
|
||||
let cwd = match &self.task_flags.cwd {
|
||||
|
@ -306,10 +434,10 @@ impl<'a> TaskRunner<'a> {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn run_npm_script(
|
||||
pub async fn run_npm_script(
|
||||
&self,
|
||||
dir_url: &Url,
|
||||
task_name: &String,
|
||||
task_name: &str,
|
||||
scripts: &IndexMap<String, String>,
|
||||
) -> Result<i32, deno_core::anyhow::Error> {
|
||||
// ensure the npm packages are installed if using a managed resolver
|
||||
|
@ -327,7 +455,7 @@ impl<'a> TaskRunner<'a> {
|
|||
// dealing with package.json here and not deno.json
|
||||
let task_names = vec![
|
||||
format!("pre{}", task_name),
|
||||
task_name.clone(),
|
||||
task_name.to_string(),
|
||||
format!("post{}", task_name),
|
||||
];
|
||||
let custom_commands = task_runner::resolve_custom_commands(
|
||||
|
@ -394,8 +522,7 @@ enum TaskError {
|
|||
}
|
||||
|
||||
fn sort_tasks_topo(
|
||||
name: &str,
|
||||
task_config: &WorkspaceTasksConfig,
|
||||
pkg_task_config: &PackageTaskInfo,
|
||||
) -> Result<Vec<String>, TaskError> {
|
||||
fn sort_visit<'a>(
|
||||
name: &'a str,
|
||||
|
@ -416,12 +543,12 @@ fn sort_tasks_topo(
|
|||
});
|
||||
}
|
||||
|
||||
let Some(def) = tasks_config.task(name) else {
|
||||
let Some((_, task_or_script)) = tasks_config.task(name) else {
|
||||
return Err(TaskError::NotFound(name.to_string()));
|
||||
};
|
||||
|
||||
if let TaskOrScript::Task(_, actual_def) = def.1 {
|
||||
for dep in &actual_def.dependencies {
|
||||
if let TaskOrScript::Task(_, task) = task_or_script {
|
||||
for dep in &task.dependencies {
|
||||
let mut path = path.clone();
|
||||
path.push(name);
|
||||
sort_visit(dep, sorted, path, tasks_config)?
|
||||
|
@ -435,7 +562,9 @@ fn sort_tasks_topo(
|
|||
|
||||
let mut sorted: Vec<String> = vec![];
|
||||
|
||||
sort_visit(name, &mut sorted, Vec::new(), task_config)?;
|
||||
for name in &pkg_task_config.matched_tasks {
|
||||
sort_visit(name, &mut sorted, Vec::new(), &pkg_task_config.tasks_config)?;
|
||||
}
|
||||
|
||||
Ok(sorted)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"args": "task test",
|
||||
"output": "bin.out",
|
||||
"exitCode": 0
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Task test echo 'test'
|
||||
test
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"task": {
|
||||
// should not execute this one because it's in a deno.json
|
||||
// and not in the package.json
|
||||
"pretest": "echo 'should not be in output'"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"scripts": {
|
||||
"test": "echo 'test'"
|
||||
}
|
||||
}
|
59
tests/specs/task/filter/__test__.jsonc
Normal file
59
tests/specs/task/filter/__test__.jsonc
Normal file
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"tests": {
|
||||
"npm_all": {
|
||||
"cwd": "./npm",
|
||||
"args": "task --filter * dev",
|
||||
"output": "npm_all.out"
|
||||
},
|
||||
"npm_exact": {
|
||||
"cwd": "./npm",
|
||||
"args": "task --filter foo dev",
|
||||
"output": "npm_exact.out"
|
||||
},
|
||||
"npm_multi": {
|
||||
"cwd": "./npm_multi",
|
||||
"args": "task --filter multi-* dev",
|
||||
"output": "npm_multi.out"
|
||||
},
|
||||
"npm_scoped_exact": {
|
||||
"cwd": "./npm_scoped",
|
||||
"args": "task --filter @foo/bar dev",
|
||||
"output": "npm_scoped_exact.out"
|
||||
},
|
||||
"npm_scoped_multi": {
|
||||
"cwd": "./npm_scoped",
|
||||
"args": "task --filter @foo/* dev",
|
||||
"output": "npm_scoped_multi.out"
|
||||
},
|
||||
"npm_workspace_order": {
|
||||
"cwd": "./npm_workspace_order",
|
||||
"args": "task --filter @foo/* dev",
|
||||
"output": "npm_workspace_order.out"
|
||||
},
|
||||
"deno_all": {
|
||||
"cwd": "./deno",
|
||||
"args": "task --filter * dev",
|
||||
"output": "deno_all.out"
|
||||
},
|
||||
"deno_exact": {
|
||||
"cwd": "./deno",
|
||||
"args": "task --filter foo dev",
|
||||
"output": "deno_exact.out"
|
||||
},
|
||||
"deno_scoped_exact": {
|
||||
"cwd": "./deno_scoped",
|
||||
"args": "task --filter @foo/bar dev",
|
||||
"output": "deno_scoped_exact.out"
|
||||
},
|
||||
"deno_scoped_multi": {
|
||||
"cwd": "./deno_scoped",
|
||||
"args": "task --filter @foo/* dev",
|
||||
"output": "deno_scoped_multi.out"
|
||||
},
|
||||
"deno_workspace_order": {
|
||||
"cwd": "./deno_workspace_order",
|
||||
"args": "task --filter @foo/* dev",
|
||||
"output": "deno_workspace_order.out"
|
||||
}
|
||||
}
|
||||
}
|
7
tests/specs/task/filter/deno/bar/deno.json
Normal file
7
tests/specs/task/filter/deno/bar/deno.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@deno/bar",
|
||||
"tasks": {
|
||||
"dev": "echo '@deno/bar'"
|
||||
},
|
||||
"exports": {}
|
||||
}
|
6
tests/specs/task/filter/deno/deno.json
Normal file
6
tests/specs/task/filter/deno/deno.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"workspace": [
|
||||
"./foo",
|
||||
"./bar"
|
||||
]
|
||||
}
|
7
tests/specs/task/filter/deno/foo/deno.json
Normal file
7
tests/specs/task/filter/deno/foo/deno.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@deno/foo",
|
||||
"tasks": {
|
||||
"dev": "echo '@deno/foo'"
|
||||
},
|
||||
"exports": {}
|
||||
}
|
4
tests/specs/task/filter/deno_all.out
Normal file
4
tests/specs/task/filter/deno_all.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@deno/bar'
|
||||
@deno/bar
|
||||
Task dev echo '@deno/foo'
|
||||
@deno/foo
|
2
tests/specs/task/filter/deno_exact.out
Normal file
2
tests/specs/task/filter/deno_exact.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo '@deno/foo'
|
||||
@deno/foo
|
0
tests/specs/task/filter/deno_multi.out
Normal file
0
tests/specs/task/filter/deno_multi.out
Normal file
3
tests/specs/task/filter/deno_scoped/deno.json
Normal file
3
tests/specs/task/filter/deno_scoped/deno.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspace": ["./foo_bar", "./foo_baz"]
|
||||
}
|
7
tests/specs/task/filter/deno_scoped/foo_bar/deno.json
Normal file
7
tests/specs/task/filter/deno_scoped/foo_bar/deno.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"exports": {},
|
||||
"tasks": {
|
||||
"dev": "echo '@foo/bar'"
|
||||
}
|
||||
}
|
7
tests/specs/task/filter/deno_scoped/foo_baz/deno.json
Normal file
7
tests/specs/task/filter/deno_scoped/foo_baz/deno.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@foo/baz",
|
||||
"exports": {},
|
||||
"tasks": {
|
||||
"dev": "echo '@foo/baz'"
|
||||
}
|
||||
}
|
2
tests/specs/task/filter/deno_scoped_exact.out
Normal file
2
tests/specs/task/filter/deno_scoped_exact.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
4
tests/specs/task/filter/deno_scoped_multi.out
Normal file
4
tests/specs/task/filter/deno_scoped_multi.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
||||
Task dev echo '@foo/baz'
|
||||
@foo/baz
|
4
tests/specs/task/filter/deno_workspace_order.out
Normal file
4
tests/specs/task/filter/deno_workspace_order.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
||||
Task dev echo '@foo/baz'
|
||||
@foo/baz
|
6
tests/specs/task/filter/deno_workspace_order/deno.json
Normal file
6
tests/specs/task/filter/deno_workspace_order/deno.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"workspace": [
|
||||
"./foo_bar",
|
||||
"./foo_baz"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"tasks": {
|
||||
"dev": "echo '@foo/bar'"
|
||||
},
|
||||
"exports": {}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@foo/baz",
|
||||
"tasks": {
|
||||
"dev": "echo '@foo/baz'"
|
||||
},
|
||||
"imports": {
|
||||
"@foo/bar": "jsr:@foo/bar"
|
||||
},
|
||||
"exports": {}
|
||||
}
|
6
tests/specs/task/filter/npm/bar/package.json
Normal file
6
tests/specs/task/filter/npm/bar/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "bar",
|
||||
"scripts": {
|
||||
"dev": "echo 'bar'"
|
||||
}
|
||||
}
|
6
tests/specs/task/filter/npm/foo/package.json
Normal file
6
tests/specs/task/filter/npm/foo/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "foo",
|
||||
"scripts": {
|
||||
"dev": "echo 'foo'"
|
||||
}
|
||||
}
|
3
tests/specs/task/filter/npm/package.json
Normal file
3
tests/specs/task/filter/npm/package.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaces": ["./foo", "./bar"]
|
||||
}
|
4
tests/specs/task/filter/npm_all.out
Normal file
4
tests/specs/task/filter/npm_all.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo 'bar'
|
||||
bar
|
||||
Task dev echo 'foo'
|
||||
foo
|
2
tests/specs/task/filter/npm_exact.out
Normal file
2
tests/specs/task/filter/npm_exact.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo 'foo'
|
||||
foo
|
4
tests/specs/task/filter/npm_multi.out
Normal file
4
tests/specs/task/filter/npm_multi.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo 'multi-a'
|
||||
multi-a
|
||||
Task dev echo 'multi-b'
|
||||
multi-b
|
6
tests/specs/task/filter/npm_multi/multi-a/package.json
Normal file
6
tests/specs/task/filter/npm_multi/multi-a/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "multi-a",
|
||||
"scripts": {
|
||||
"dev": "echo 'multi-a'"
|
||||
}
|
||||
}
|
6
tests/specs/task/filter/npm_multi/multi-b/package.json
Normal file
6
tests/specs/task/filter/npm_multi/multi-b/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "multi-b",
|
||||
"scripts": {
|
||||
"dev": "echo 'multi-b'"
|
||||
}
|
||||
}
|
3
tests/specs/task/filter/npm_multi/package.json
Normal file
3
tests/specs/task/filter/npm_multi/package.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaces": ["./multi-a", "./multi-b"]
|
||||
}
|
6
tests/specs/task/filter/npm_scoped/foo_bar/package.json
Normal file
6
tests/specs/task/filter/npm_scoped/foo_bar/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"scripts": {
|
||||
"dev": "echo '@foo/bar'"
|
||||
}
|
||||
}
|
6
tests/specs/task/filter/npm_scoped/foo_baz/package.json
Normal file
6
tests/specs/task/filter/npm_scoped/foo_baz/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "@foo/baz",
|
||||
"scripts": {
|
||||
"dev": "echo '@foo/baz'"
|
||||
}
|
||||
}
|
3
tests/specs/task/filter/npm_scoped/package.json
Normal file
3
tests/specs/task/filter/npm_scoped/package.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaces": ["./foo_bar", "./foo_baz"]
|
||||
}
|
2
tests/specs/task/filter/npm_scoped_exact.out
Normal file
2
tests/specs/task/filter/npm_scoped_exact.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
4
tests/specs/task/filter/npm_scoped_multi.out
Normal file
4
tests/specs/task/filter/npm_scoped_multi.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
||||
Task dev echo '@foo/baz'
|
||||
@foo/baz
|
4
tests/specs/task/filter/npm_workspace_order.out
Normal file
4
tests/specs/task/filter/npm_workspace_order.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Task dev echo '@foo/bar'
|
||||
@foo/bar
|
||||
Task dev echo '@foo/baz'
|
||||
@foo/baz
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"scripts": {
|
||||
"dev": "echo '@foo/bar'"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@foo/baz",
|
||||
"scripts": {
|
||||
"dev": "echo '@foo/baz'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@foo/bar": "workspace:*"
|
||||
}
|
||||
}
|
3
tests/specs/task/filter/npm_workspace_order/package.json
Normal file
3
tests/specs/task/filter/npm_workspace_order/package.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaces": ["./foo_bar", "./foo_baz"]
|
||||
}
|
Loading…
Reference in a new issue