mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(task): support tasks without commands (#27191)
Support running tasks that have no command and only dependencies. This is useful for when you want to group tasks only.
This commit is contained in:
parent
074444ab6c
commit
351e79642a
10 changed files with 62 additions and 14 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1463,9 +1463,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_config"
|
||||
version = "0.39.3"
|
||||
version = "0.40.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce717af3fe6788dae63965d58d5637fd62be8fe4f345f189137ffc06c51837d2"
|
||||
checksum = "459b0bf193d2f9a177d18064a4888062ba0716312f56dbda8f1319444a8b2544"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"deno_package_json",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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())?,
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -446,7 +446,6 @@
|
|||
},
|
||||
"command": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The task to execute"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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
|
||||
|
|
|
@ -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
tests/specs/task/dependencies/no_command.out
Normal file
5
tests/specs/task/dependencies/no_command.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
Task b echo 'b'
|
||||
b
|
||||
Task c echo 'c'
|
||||
c
|
||||
Task a (no command)
|
13
tests/specs/task/dependencies/no_command/deno.json
Normal file
13
tests/specs/task/dependencies/no_command/deno.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"tasks": {
|
||||
"a": {
|
||||
"dependencies": ["b", "c"]
|
||||
},
|
||||
"b": {
|
||||
"command": "echo 'b'"
|
||||
},
|
||||
"c": {
|
||||
"command": "echo 'c'"
|
||||
}
|
||||
}
|
||||
}
|
7
tests/specs/task/dependencies/no_command_list.out
Normal file
7
tests/specs/task/dependencies/no_command_list.out
Normal file
|
@ -0,0 +1,7 @@
|
|||
Available tasks:
|
||||
- a
|
||||
depends on: b, c
|
||||
- b
|
||||
echo 'b'
|
||||
- c
|
||||
echo 'c'
|
Loading…
Reference in a new issue