Skip to content

Commit

Permalink
fix(task): support tasks with colons in name in deno run (#25233)
Browse files Browse the repository at this point in the history
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 #25232
  • Loading branch information
marvinhagemeister authored Aug 27, 2024
1 parent b6dbe1e commit 7e68cce
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +197,8 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
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();
Expand Down
1 change: 1 addition & 0 deletions cli/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tests/specs/run/run_task/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
3 changes: 2 additions & 1 deletion tests/specs/run/run_task/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tasks": {
"main": "deno run main.ts"
"main": "deno run main.ts",
"main:foo": "deno run main.ts"
}
}
2 changes: 2 additions & 0 deletions tests/specs/run/run_task/main_foo.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task main:foo deno run main.ts
main

0 comments on commit 7e68cce

Please sign in to comment.