From cac28b52621975137b86d4fd6efc32cecc10d682 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 2 Oct 2024 21:17:39 +0100 Subject: feat(byonm): support `deno run npm:` when package is not in package.json (#25981) Closes https://github.com/denoland/deno/issues/25905 --- cli/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cli/main.rs') diff --git a/cli/main.rs b/cli/main.rs index 31bebc882..93bd97e2a 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -37,6 +37,7 @@ use crate::util::v8::get_v8_flags_from_env; use crate::util::v8::init_v8_flags; use args::TaskFlags; +use deno_resolver::npm::ByonmResolvePkgFolderFromDenoReqError; use deno_runtime::WorkerExecutionMode; pub use deno_runtime::UNSTABLE_GRANULAR_FLAGS; @@ -51,6 +52,7 @@ use deno_runtime::fmt_errors::FixSuggestion; use deno_runtime::tokio_util::create_and_run_current_thread_with_maybe_metrics; use deno_terminal::colors; use factory::CliFactory; +use npm::ResolvePkgFolderFromDenoReqError; use standalone::MODULE_NOT_FOUND; use standalone::UNSUPPORTED_SCHEME; use std::env; @@ -182,6 +184,21 @@ async fn run_subcommand(flags: Arc) -> Result { match result { Ok(v) => Ok(v), Err(script_err) => { + if let Some(ResolvePkgFolderFromDenoReqError::Byonm(ByonmResolvePkgFolderFromDenoReqError::UnmatchedReq(_))) = script_err.downcast_ref::() { + if flags.node_modules_dir.is_none() { + let mut flags = flags.deref().clone(); + let watch = match &flags.subcommand { + DenoSubcommand::Run(run_flags) => run_flags.watch.clone(), + _ => unreachable!(), + }; + flags.node_modules_dir = Some(deno_config::deno_json::NodeModulesDirMode::None); + // use the current lockfile, but don't write it out + if flags.frozen_lockfile.is_none() { + flags.internal.lockfile_skip_write = true; + } + return tools::run::run_script(WorkerExecutionMode::Run, Arc::new(flags), watch).await; + } + } 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 { -- cgit v1.2.3