diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-08-23 22:01:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 22:01:21 -0400 |
commit | 452df99222911c772657c39491469bd97935f23a (patch) | |
tree | 49e7989e60762534e4e477dbefd66c042293f57f /cli/worker.rs | |
parent | 4ef08a58dfbcf893f25fd59917aa946f455e85f2 (diff) |
feat(npm): support packages with multiple command names (#15565)
Diffstat (limited to 'cli/worker.rs')
-rw-r--r-- | cli/worker.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index 2069690e0..d7c185fd9 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -21,6 +21,7 @@ use deno_runtime::worker::MainWorker; use deno_runtime::worker::WorkerOptions; use deno_runtime::BootstrapOptions; +use crate::args::DenoSubcommand; use crate::checksum; use crate::compat; use crate::errors; @@ -103,7 +104,7 @@ impl CliMainWorker { )?; } } else if self.is_main_cjs { - node::initialize_runtime(&mut self.worker.js_runtime).await?; + self.initialize_main_module_for_node().await?; node::load_cjs_module_from_ext_node( &mut self.worker.js_runtime, &self.main_module.to_file_path().unwrap().to_string_lossy(), @@ -422,11 +423,31 @@ impl CliMainWorker { id: ModuleId, ) -> Result<(), AnyError> { if self.ps.npm_resolver.has_packages() { - node::initialize_runtime(&mut self.worker.js_runtime).await?; + self.initialize_main_module_for_node().await?; } self.worker.evaluate_module(id).await } + async fn initialize_main_module_for_node(&mut self) -> Result<(), AnyError> { + node::initialize_runtime(&mut self.worker.js_runtime).await?; + if let DenoSubcommand::Run(flags) = self.ps.options.sub_command() { + if let Ok(pkg_ref) = NpmPackageReference::from_str(&flags.script) { + // if the user ran a binary command, we'll need to set process.argv[0] + // to be the name of the binary command instead of deno + let binary_name = pkg_ref + .sub_path + .as_deref() + .unwrap_or(pkg_ref.req.name.as_str()); + node::initialize_binary_command( + &mut self.worker.js_runtime, + binary_name, + ) + .await?; + } + } + Ok(()) + } + async fn maybe_setup_coverage_collector( &mut self, ) -> Result<Option<CoverageCollector>, AnyError> { |