Skip to content

Commit

Permalink
fix(task): support tasks without commands (#27191)
Browse files Browse the repository at this point in the history
Support running tasks that have no command and only dependencies. This
is useful for when you want to group tasks only.
  • Loading branch information
marvinhagemeister authored Dec 19, 2024
1 parent 074444a commit 351e796
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 14 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 @@ -51,7 +51,7 @@ deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.326.0" }

deno_bench_util = { version = "0.178.0", path = "./bench_util" }
deno_config = { version = "=0.39.3", features = ["workspace", "sync"] }
deno_config = { version = "=0.40.0", features = ["workspace", "sync"] }
deno_lockfile = "=0.23.2"
deno_media_type = { version = "0.2.0", features = ["module_specifier"] }
deno_npm = "=0.26.0"
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3793,7 +3793,7 @@ impl Inner {
for (name, command) in scripts {
result.push(TaskDefinition {
name: name.clone(),
command: command.clone(),
command: Some(command.clone()),
source_uri: url_to_uri(&package_json.specifier())
.map_err(|_| LspError::internal_error())?,
});
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/lsp_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const LATEST_DIAGNOSTIC_BATCH_INDEX: &str =
#[serde(rename_all = "camelCase")]
pub struct TaskDefinition {
pub name: String,
pub command: String,
pub command: Option<String>,
pub source_uri: lsp::Uri,
}

Expand Down
1 change: 0 additions & 1 deletion cli/schemas/config-file.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@
},
"command": {
"type": "string",
"required": true,
"description": "The task to execute"
},
"dependencies": {
Expand Down
28 changes: 20 additions & 8 deletions cli/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub async fn execute_script(
&Url::from_directory_path(cli_options.initial_cwd()).unwrap(),
"",
&TaskDefinition {
command: task_flags.task.as_ref().unwrap().to_string(),
command: Some(task_flags.task.as_ref().unwrap().to_string()),
dependencies: vec![],
description: None,
},
Expand Down Expand Up @@ -448,6 +448,16 @@ impl<'a> TaskRunner<'a> {
kill_signal: KillSignal,
argv: &'a [String],
) -> Result<i32, deno_core::anyhow::Error> {
let Some(command) = &definition.command else {
log::info!(
"{} {} {}",
colors::green("Task"),
colors::cyan(task_name),
colors::gray("(no command)")
);
return Ok(0);
};

if let Some(npm_resolver) = self.npm_resolver.as_managed() {
npm_resolver.ensure_top_level_package_json_install().await?;
npm_resolver
Expand All @@ -469,7 +479,7 @@ impl<'a> TaskRunner<'a> {
self
.run_single(RunSingleOptions {
task_name,
script: &definition.command,
script: command,
cwd: &cwd,
custom_commands,
kill_signal,
Expand Down Expand Up @@ -837,7 +847,7 @@ fn print_available_tasks(
is_deno: false,
name: name.to_string(),
task: deno_config::deno_json::TaskDefinition {
command: script.to_string(),
command: Some(script.to_string()),
dependencies: vec![],
description: None,
},
Expand Down Expand Up @@ -873,11 +883,13 @@ fn print_available_tasks(
)?;
}
}
writeln!(
writer,
" {}",
strip_ansi_codes_and_escape_control_chars(&desc.task.command)
)?;
if let Some(command) = &desc.task.command {
writeln!(
writer,
" {}",
strip_ansi_codes_and_escape_control_chars(command)
)?;
};
if !desc.task.dependencies.is_empty() {
let dependencies = desc
.task
Expand Down
12 changes: 12 additions & 0 deletions tests/specs/task/dependencies/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
"cwd": "arg_task_with_deps",
"args": "task a a",
"output": "./arg_task_with_deps.out"
},
"no_command": {
"cwd": "no_command",
"args": "task a",
"output": "./no_command.out",
"exitCode": 0
},
"no_command_list": {
"cwd": "no_command",
"args": "task",
"output": "./no_command_list.out",
"exitCode": 0
}
}
}
5 changes: 5 additions & 0 deletions tests/specs/task/dependencies/no_command.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Task b echo 'b'
b
Task c echo 'c'
c
Task a (no command)
13 changes: 13 additions & 0 deletions tests/specs/task/dependencies/no_command/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tasks": {
"a": {
"dependencies": ["b", "c"]
},
"b": {
"command": "echo 'b'"
},
"c": {
"command": "echo 'c'"
}
}
}
7 changes: 7 additions & 0 deletions tests/specs/task/dependencies/no_command_list.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Available tasks:
- a
depends on: b, c
- b
echo 'b'
- c
echo 'c'

0 comments on commit 351e796

Please sign in to comment.