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/node/mod.rs | |
parent | 4ef08a58dfbcf893f25fd59917aa946f455e85f2 (diff) |
feat(npm): support packages with multiple command names (#15565)
Diffstat (limited to 'cli/node/mod.rs')
-rw-r--r-- | cli/node/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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( |