From 7e68cce8159d55fd597f0da3e00f794200b9928f Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 27 Aug 2024 11:27:10 +0200 Subject: [PATCH] fix(task): support tasks with colons in name in `deno run` (#25233) Fix task names containing a colon not being found with `deno run`. We were only checking for a `module not found` error message, but strings containing a colon throw a different error. Fixes https://github.com/denoland/deno/issues/25232 --- cli/main.rs | 4 +++- cli/standalone/mod.rs | 1 + tests/specs/run/run_task/__test__.jsonc | 4 ++++ tests/specs/run/run_task/deno.json | 3 ++- tests/specs/run/run_task/main_foo.out | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/specs/run/run_task/main_foo.out diff --git a/cli/main.rs b/cli/main.rs index 290eee120d..ee2bd79cc2 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -53,6 +53,7 @@ use deno_runtime::tokio_util::create_and_run_current_thread_with_maybe_metrics; use deno_terminal::colors; use factory::CliFactory; use standalone::MODULE_NOT_FOUND; +use standalone::UNSUPPORTED_SCHEME; use std::env; use std::future::Future; use std::ops::Deref; @@ -196,7 +197,8 @@ async fn run_subcommand(flags: Arc) -> Result { match result { Ok(v) => Ok(v), Err(script_err) => { - if script_err.to_string().starts_with(MODULE_NOT_FOUND) { + let script_err_msg = script_err.to_string(); + if script_err_msg.starts_with(MODULE_NOT_FOUND) || script_err_msg.starts_with(UNSUPPORTED_SCHEME) { if run_flags.bare { let mut cmd = args::clap_root(); cmd.build(); diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 68e1334762..90b2b8a28a 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -133,6 +133,7 @@ struct EmbeddedModuleLoader { } pub const MODULE_NOT_FOUND: &str = "Module not found"; +pub const UNSUPPORTED_SCHEME: &str = "Unsupported scheme"; impl ModuleLoader for EmbeddedModuleLoader { fn resolve( diff --git a/tests/specs/run/run_task/__test__.jsonc b/tests/specs/run/run_task/__test__.jsonc index 0d1c82efdd..b53cca6579 100644 --- a/tests/specs/run/run_task/__test__.jsonc +++ b/tests/specs/run/run_task/__test__.jsonc @@ -8,6 +8,10 @@ "args": "run not_found", "output": "not_found.out", "exitCode": 1 + }, + "deno_run_task_colon": { + "args": "run main:foo", + "output": "main_foo.out" } } } diff --git a/tests/specs/run/run_task/deno.json b/tests/specs/run/run_task/deno.json index 54772504e8..3597b5b47f 100644 --- a/tests/specs/run/run_task/deno.json +++ b/tests/specs/run/run_task/deno.json @@ -1,5 +1,6 @@ { "tasks": { - "main": "deno run main.ts" + "main": "deno run main.ts", + "main:foo": "deno run main.ts" } } diff --git a/tests/specs/run/run_task/main_foo.out b/tests/specs/run/run_task/main_foo.out new file mode 100644 index 0000000000..7e5f826328 --- /dev/null +++ b/tests/specs/run/run_task/main_foo.out @@ -0,0 +1,2 @@ +Task main:foo deno run main.ts +main