From af9537749b926351deddd539b900f6f34408169c Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 2 Dec 2024 11:47:10 +0100 Subject: [PATCH 1/4] feat: support tasks without commands --- Cargo.lock | 2 -- Cargo.toml | 3 ++ cli/lsp/language_server.rs | 2 +- cli/lsp/lsp_custom.rs | 2 +- cli/tools/task.rs | 28 +++++++++++++------ tests/specs/task/dependencies/__test__.jsonc | 6 ++++ tests/specs/task/dependencies/no_command.out | 5 ++++ .../task/dependencies/no_command/deno.json | 13 +++++++++ 8 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 tests/specs/task/dependencies/no_command.out create mode 100644 tests/specs/task/dependencies/no_command/deno.json diff --git a/Cargo.lock b/Cargo.lock index 77dc2cb4c4a0ee..a0e282b138f87e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1431,8 +1431,6 @@ dependencies = [ [[package]] name = "deno_config" version = "0.39.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce717af3fe6788dae63965d58d5637fd62be8fe4f345f189137ffc06c51837d2" dependencies = [ "anyhow", "deno_package_json", diff --git a/Cargo.toml b/Cargo.toml index f6606b54c37e6b..033bb862d57a29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -336,3 +336,6 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 + +[patch.crates-io] +deno_config = { path = "../deno_config" } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 0caaa941072bb6..01acbb69c8621e 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -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())?, }); diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs index 74c6aca88b5b5a..8df4ba1d07c768 100644 --- a/cli/lsp/lsp_custom.rs +++ b/cli/lsp/lsp_custom.rs @@ -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, pub source_uri: lsp::Uri, } diff --git a/cli/tools/task.rs b/cli/tools/task.rs index a2f76aaf1f9dd8..2eb86d4cf0393b 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -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, }, @@ -430,6 +430,16 @@ impl<'a> TaskRunner<'a> { definition: &TaskDefinition, kill_signal: KillSignal, ) -> Result { + 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")?, @@ -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, @@ -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, }, @@ -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 diff --git a/tests/specs/task/dependencies/__test__.jsonc b/tests/specs/task/dependencies/__test__.jsonc index 38d085d796cc2f..1f03c56d41fd6b 100644 --- a/tests/specs/task/dependencies/__test__.jsonc +++ b/tests/specs/task/dependencies/__test__.jsonc @@ -56,6 +56,12 @@ "args": "task a", "output": "./cycle_2.out", "exitCode": 1 + }, + "no_command": { + "cwd": "no_command", + "args": "task a", + "output": "./no_command.out", + "exitCode": 0 } } } diff --git a/tests/specs/task/dependencies/no_command.out b/tests/specs/task/dependencies/no_command.out new file mode 100644 index 00000000000000..521b3541df0a62 --- /dev/null +++ b/tests/specs/task/dependencies/no_command.out @@ -0,0 +1,5 @@ +Task b echo 'b' +b +Task c echo 'c' +c +Task a (no command) diff --git a/tests/specs/task/dependencies/no_command/deno.json b/tests/specs/task/dependencies/no_command/deno.json new file mode 100644 index 00000000000000..5588365a92dae8 --- /dev/null +++ b/tests/specs/task/dependencies/no_command/deno.json @@ -0,0 +1,13 @@ +{ + "tasks": { + "a": { + "dependencies": ["b", "c"] + }, + "b": { + "command": "echo 'b'" + }, + "c": { + "command": "echo 'c'" + } + } +} From 61cc60fd1db99804b2f28d02f06ecf761a338ba6 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 2 Dec 2024 17:21:49 +0100 Subject: [PATCH 2/4] chore: update deno_core --- Cargo.lock | 4 +++- Cargo.toml | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0e282b138f87e..685099d6835b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1430,7 +1430,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 = "459b0bf193d2f9a177d18064a4888062ba0716312f56dbda8f1319444a8b2544" dependencies = [ "anyhow", "deno_package_json", diff --git a/Cargo.toml b/Cargo.toml index 033bb862d57a29..13d1f4a9cde653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -336,6 +336,3 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 - -[patch.crates-io] -deno_config = { path = "../deno_config" } From b4fe03efbf60c76f35cb2cb2acac69f042117542 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 2 Dec 2024 17:21:59 +0100 Subject: [PATCH 3/4] fix: schema mark command as optional --- cli/schemas/config-file.v1.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index a64cb2ff655d42..e495898c7211db 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -446,7 +446,6 @@ }, "command": { "type": "string", - "required": true, "description": "The task to execute" }, "dependencies": { From e8f245680f5fdccd0ae80d6acad9f04f0a3852f3 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 2 Dec 2024 17:28:15 +0100 Subject: [PATCH 4/4] fix: list tasks without command --- tests/specs/task/dependencies/__test__.jsonc | 6 ++++++ tests/specs/task/dependencies/no_command_list.out | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/specs/task/dependencies/no_command_list.out diff --git a/tests/specs/task/dependencies/__test__.jsonc b/tests/specs/task/dependencies/__test__.jsonc index 1f03c56d41fd6b..9a13574eebe838 100644 --- a/tests/specs/task/dependencies/__test__.jsonc +++ b/tests/specs/task/dependencies/__test__.jsonc @@ -62,6 +62,12 @@ "args": "task a", "output": "./no_command.out", "exitCode": 0 + }, + "no_command_list": { + "cwd": "no_command", + "args": "task", + "output": "./no_command_list.out", + "exitCode": 0 } } } diff --git a/tests/specs/task/dependencies/no_command_list.out b/tests/specs/task/dependencies/no_command_list.out new file mode 100644 index 00000000000000..3d58c1cb06025d --- /dev/null +++ b/tests/specs/task/dependencies/no_command_list.out @@ -0,0 +1,7 @@ +Available tasks: +- a + depends on: b, c +- b + echo 'b' +- c + echo 'c'