feat: deno run <task> (#24891)

This PR updates `deno run` to fallback to executing tasks when there is
no script with the specified name. If there are both script and a task
with the same name then `deno run` will prioritise executing the script.
This commit is contained in:
Satya Rohith 2024-08-06 20:35:30 +05:30 committed by GitHub
parent 897159dc6e
commit b3f1f3ba04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 60 additions and 5 deletions

View file

@ -12,6 +12,7 @@ use deno_config::deno_json::Task;
use deno_config::workspace::TaskOrScript;
use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceTasksConfig;
use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
@ -28,6 +29,7 @@ use std::sync::Arc;
pub async fn execute_script(
flags: Arc<Flags>,
task_flags: TaskFlags,
using_run: bool,
) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags);
let cli_options = factory.cli_options()?;
@ -140,7 +142,10 @@ pub async fn execute_script(
}
},
None => {
log::error!("Task not found: {task_name}");
if using_run {
return Err(anyhow!("Task not found: {}", task_name));
}
log::error!("Task not found: {}", task_name);
if log::log_enabled!(log::Level::Error) {
print_available_tasks(
&mut std::io::stderr(),