Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support tasks without commands #27191

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -50,7 +50,7 @@ deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.323.0" }

deno_bench_util = { version = "0.174.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.25.5"
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 @@ -3787,7 +3787,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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the description to mention that this field is required unless there's "dependencies" field specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required though? Having a task like this is valid in the string form:

{
  "tasks": {
    "foo": ""
  }
}

And I guess the same is also fine for the object notation:

{
  "tasks": {
    "foo":  {}
  }
}

That's just a task that does nothing.

},
"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 @@ -236,7 +236,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 @@ -430,6 +430,16 @@ impl<'a> TaskRunner<'a> {
definition: &TaskDefinition,
kill_signal: KillSignal,
) -> 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);
};

let cwd = match &self.task_flags.cwd {
Some(path) => canonicalize_path(&PathBuf::from(path))
.context("failed canonicalizing --cwd")?,
Expand All @@ -443,7 +453,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 @@ -719,7 +729,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 @@ -755,11 +765,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 @@ -56,6 +56,18 @@
"args": "task a",
"output": "./cycle_2.out",
"exitCode": 1
},
"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'
Loading