From 452df99222911c772657c39491469bd97935f23a Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 23 Aug 2022 22:01:21 -0400 Subject: feat(npm): support packages with multiple command names (#15565) --- cli/node/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cli/node') diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 385c6cfa2..e9bf04d60 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -106,6 +106,27 @@ pub async fn initialize_runtime( Ok(()) } +pub async fn initialize_binary_command( + js_runtime: &mut JsRuntime, + binary_name: &str, +) -> Result<(), AnyError> { + // overwrite what's done in deno_std in order to set the binary arg name + let source_code = &format!( + r#"(async function initializeBinaryCommand(binaryName) {{ + const process = Deno[Deno.internal].node.globalThis.process; + Object.defineProperty(process.argv, "0", {{ + get: () => binaryName, + }}); + }})('{}');"#, + binary_name, + ); + + let value = + js_runtime.execute_script(&located_script_name!(), source_code)?; + js_runtime.resolve_value(value).await?; + Ok(()) +} + /// This function is an implementation of `defaultResolve` in /// `lib/internal/modules/esm/resolve.js` from Node. pub fn node_resolve( -- cgit v1.2.3