Skip to content

Commit f0b245c

Browse files
marvinhagemeisterbartlomiejunathanwhitdsherret
authored
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 #24991 --------- Signed-off-by: Bartek Iwańczuk <[email protected]> Signed-off-by: David Sherret <[email protected]> Co-authored-by: Bartek Iwańczuk <[email protected]> Co-authored-by: Nathan Whitaker <[email protected]> Co-authored-by: David Sherret <[email protected]> Co-authored-by: David Sherret <[email protected]>
1 parent b729bf0 commit f0b245c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+541
-78
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ deno_ast = { version = "=0.43.3", features = ["transpiling"] }
4949
deno_core = { version = "0.321.0" }
5050

5151
deno_bench_util = { version = "0.171.0", path = "./bench_util" }
52-
deno_config = { version = "=0.39.1", features = ["workspace", "sync"] }
52+
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }
5353
deno_lockfile = "=0.23.1"
5454
deno_media_type = { version = "0.2.0", features = ["module_specifier"] }
5555
deno_npm = "=0.25.4"

cli/args/flags.rs

+96-1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ pub struct TaskFlags {
380380
pub cwd: Option<String>,
381381
pub task: Option<String>,
382382
pub is_run: bool,
383+
pub recursive: bool,
384+
pub filter: Option<String>,
383385
pub eval: bool,
384386
}
385387

@@ -3046,13 +3048,27 @@ Evaluate a task from string
30463048
.help("Specify the directory to run the task in")
30473049
.value_hint(ValueHint::DirPath),
30483050
)
3051+
.arg(
3052+
Arg::new("recursive")
3053+
.long("recursive")
3054+
.short('r')
3055+
.help("Run the task in all projects in the workspace")
3056+
.action(ArgAction::SetTrue),
3057+
)
3058+
.arg(
3059+
Arg::new("filter")
3060+
.long("filter")
3061+
.short('f')
3062+
.help("Filter members of the workspace by name - should be used with --recursive")
3063+
.value_parser(value_parser!(String)),
3064+
)
30493065
.arg(
30503066
Arg::new("eval")
30513067
.long("eval")
30523068
.help(
30533069
"Evaluate the passed value as if, it was a task in a configuration file",
30543070
).action(ArgAction::SetTrue)
3055-
)
3071+
)
30563072
.arg(node_modules_dir_arg())
30573073
})
30583074
}
@@ -5212,10 +5228,15 @@ fn task_parse(
52125228
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime);
52135229
node_modules_arg_parse(flags, matches);
52145230

5231+
let filter = matches.remove_one::<String>("filter");
5232+
let recursive = matches.get_flag("recursive") || filter.is_some();
5233+
52155234
let mut task_flags = TaskFlags {
52165235
cwd: matches.remove_one::<String>("cwd"),
52175236
task: None,
52185237
is_run: false,
5238+
recursive,
5239+
filter,
52195240
eval: matches.get_flag("eval"),
52205241
};
52215242

@@ -10418,6 +10439,8 @@ mod tests {
1041810439
cwd: None,
1041910440
task: Some("build".to_string()),
1042010441
is_run: false,
10442+
recursive: false,
10443+
filter: None,
1042110444
eval: false,
1042210445
}),
1042310446
argv: svec!["hello", "world"],
@@ -10433,6 +10456,8 @@ mod tests {
1043310456
cwd: None,
1043410457
task: Some("build".to_string()),
1043510458
is_run: false,
10459+
recursive: false,
10460+
filter: None,
1043610461
eval: false,
1043710462
}),
1043810463
..Flags::default()
@@ -10447,6 +10472,56 @@ mod tests {
1044710472
cwd: Some("foo".to_string()),
1044810473
task: Some("build".to_string()),
1044910474
is_run: false,
10475+
recursive: false,
10476+
filter: None,
10477+
eval: false,
10478+
}),
10479+
..Flags::default()
10480+
}
10481+
);
10482+
10483+
let r = flags_from_vec(svec!["deno", "task", "--filter", "*", "build"]);
10484+
assert_eq!(
10485+
r.unwrap(),
10486+
Flags {
10487+
subcommand: DenoSubcommand::Task(TaskFlags {
10488+
cwd: None,
10489+
task: Some("build".to_string()),
10490+
is_run: false,
10491+
recursive: true,
10492+
filter: Some("*".to_string()),
10493+
eval: false,
10494+
}),
10495+
..Flags::default()
10496+
}
10497+
);
10498+
10499+
let r = flags_from_vec(svec!["deno", "task", "--recursive", "build"]);
10500+
assert_eq!(
10501+
r.unwrap(),
10502+
Flags {
10503+
subcommand: DenoSubcommand::Task(TaskFlags {
10504+
cwd: None,
10505+
task: Some("build".to_string()),
10506+
is_run: false,
10507+
recursive: true,
10508+
filter: None,
10509+
eval: false,
10510+
}),
10511+
..Flags::default()
10512+
}
10513+
);
10514+
10515+
let r = flags_from_vec(svec!["deno", "task", "-r", "build"]);
10516+
assert_eq!(
10517+
r.unwrap(),
10518+
Flags {
10519+
subcommand: DenoSubcommand::Task(TaskFlags {
10520+
cwd: None,
10521+
task: Some("build".to_string()),
10522+
is_run: false,
10523+
recursive: true,
10524+
filter: None,
1045010525
eval: false,
1045110526
}),
1045210527
..Flags::default()
@@ -10461,6 +10536,8 @@ mod tests {
1046110536
cwd: None,
1046210537
task: Some("echo 1".to_string()),
1046310538
is_run: false,
10539+
recursive: false,
10540+
filter: None,
1046410541
eval: true,
1046510542
}),
1046610543
..Flags::default()
@@ -10490,6 +10567,8 @@ mod tests {
1049010567
cwd: None,
1049110568
task: Some("build".to_string()),
1049210569
is_run: false,
10570+
recursive: false,
10571+
filter: None,
1049310572
eval: false,
1049410573
}),
1049510574
argv: svec!["--", "hello", "world"],
@@ -10508,6 +10587,8 @@ mod tests {
1050810587
cwd: Some("foo".to_string()),
1050910588
task: Some("build".to_string()),
1051010589
is_run: false,
10590+
recursive: false,
10591+
filter: None,
1051110592
eval: false,
1051210593
}),
1051310594
argv: svec!["--", "hello", "world"],
@@ -10527,6 +10608,8 @@ mod tests {
1052710608
cwd: None,
1052810609
task: Some("build".to_string()),
1052910610
is_run: false,
10611+
recursive: false,
10612+
filter: None,
1053010613
eval: false,
1053110614
}),
1053210615
argv: svec!["--"],
@@ -10545,6 +10628,8 @@ mod tests {
1054510628
cwd: None,
1054610629
task: Some("build".to_string()),
1054710630
is_run: false,
10631+
recursive: false,
10632+
filter: None,
1054810633
eval: false,
1054910634
}),
1055010635
argv: svec!["-1", "--test"],
@@ -10563,6 +10648,8 @@ mod tests {
1056310648
cwd: None,
1056410649
task: Some("build".to_string()),
1056510650
is_run: false,
10651+
recursive: false,
10652+
filter: None,
1056610653
eval: false,
1056710654
}),
1056810655
argv: svec!["--test"],
@@ -10582,6 +10669,8 @@ mod tests {
1058210669
cwd: None,
1058310670
task: Some("build".to_string()),
1058410671
is_run: false,
10672+
recursive: false,
10673+
filter: None,
1058510674
eval: false,
1058610675
}),
1058710676
log_level: Some(log::Level::Error),
@@ -10600,6 +10689,8 @@ mod tests {
1060010689
cwd: None,
1060110690
task: None,
1060210691
is_run: false,
10692+
recursive: false,
10693+
filter: None,
1060310694
eval: false,
1060410695
}),
1060510696
..Flags::default()
@@ -10617,6 +10708,8 @@ mod tests {
1061710708
cwd: None,
1061810709
task: None,
1061910710
is_run: false,
10711+
recursive: false,
10712+
filter: None,
1062010713
eval: false,
1062110714
}),
1062210715
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
@@ -10635,6 +10728,8 @@ mod tests {
1063510728
cwd: None,
1063610729
task: None,
1063710730
is_run: false,
10731+
recursive: false,
10732+
filter: None,
1063810733
eval: false,
1063910734
}),
1064010735
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),

cli/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
243243
cwd: None,
244244
task: Some(run_flags.script.clone()),
245245
is_run: true,
246+
recursive: false,
247+
filter: None,
246248
eval: false,
247249
};
248250
new_flags.subcommand = DenoSubcommand::Task(task_flags.clone());

0 commit comments

Comments
 (0)