diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-08-23 10:39:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 10:39:19 -0400 |
commit | e7367044d933ee3518ae583a43876a0ddab5b17e (patch) | |
tree | e557e3ea4faad632bcfafa6539f3bd0115dc6426 /cli/main.rs | |
parent | 362af63c6f45e98948536d08d2d6195af87f729c (diff) |
feat: binary npm commands (#15542)
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/cli/main.rs b/cli/main.rs index d38403384..b784ed3d5 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -91,6 +91,7 @@ use deno_runtime::permissions::Permissions; use deno_runtime::tokio_util::run_local; use log::debug; use log::info; +use npm::NpmPackageReference; use std::env; use std::io::Read; use std::io::Write; @@ -323,7 +324,8 @@ async fn install_command( permissions, vec![], Default::default(), - ); + ) + .await?; // First, fetch and compile the module; this step ensures that the module exists. worker.preload_main_module().await?; tools::installer::install(flags, install_flags)?; @@ -412,7 +414,8 @@ async fn eval_command( permissions, vec![], Default::default(), - ); + ) + .await?; // Create a dummy source file. let source_code = if eval_flags.print { format!("console.log({})", eval_flags.code) @@ -694,7 +697,8 @@ async fn repl_command( Permissions::from_options(&ps.options.permissions_options())?, vec![], Default::default(), - ); + ) + .await?; worker.setup_repl().await?; tools::repl::run( &ps, @@ -714,7 +718,8 @@ async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { Permissions::from_options(&ps.options.permissions_options())?, vec![], Default::default(), - ); + ) + .await?; let mut source = Vec::new(); std::io::stdin().read_to_end(&mut source)?; @@ -758,7 +763,8 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<i32, AnyError> { permissions, vec![], Default::default(), - ); + ) + .await?; worker.run_for_watcher().await?; Ok(()) @@ -797,8 +803,13 @@ async fn run_command( // TODO(bartlomieju): actually I think it will also fail if there's an import // map specified and bare specifier is used on the command line - this should // probably call `ProcState::resolve` instead - let main_module = resolve_url_or_path(&run_flags.script)?; let ps = ProcState::build(flags).await?; + let main_module = if NpmPackageReference::from_str(&run_flags.script).is_ok() + { + ModuleSpecifier::parse(&run_flags.script)? + } else { + resolve_url_or_path(&run_flags.script)? + }; let permissions = Permissions::from_options(&ps.options.permissions_options())?; let mut worker = create_main_worker( @@ -807,7 +818,8 @@ async fn run_command( permissions, vec![], Default::default(), - ); + ) + .await?; let exit_code = worker.run().await?; Ok(exit_code) |