From 638f2dc47e6f756e00ace366142bb0131cc19817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 16 Oct 2024 15:32:39 +0200 Subject: [PATCH] fix: set 'npm_config_user_agent' env var when installing or running npm deps --- cli/tools/run/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs index 152e2650bd7a69..725f2789476352 100644 --- a/cli/tools/run/mod.rs +++ b/cli/tools/run/mod.rs @@ -178,7 +178,19 @@ pub async fn eval_command( Ok(exit_code) } +fn get_npm_config_user_agent() -> String { + format!( + "deno/{} npm/? deno/{} {} {}", + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_VERSION"), + std::env::consts::OS, + std::env::consts::ARCH + ) +} + pub async fn maybe_npm_install(factory: &CliFactory) -> Result<(), AnyError> { + std::env::set_var("npm_config_user_agent", get_npm_config_user_agent()); + // ensure an "npm install" is done if the user has explicitly // opted into using a managed node_modules directory if factory.cli_options()?.node_modules_dir()?