Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set 'npm_config_user_agent' env var when installing or running npm deps #26311

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/tools/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really correct. I believe we want to set it every time we install npm packages, when executing deno run npm:<package_name> and when running deno task that calls a bin entry of a package.

Copy link
Member

@nathanwhit nathanwhit Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the deno run case, it feels like it might just be easiest to set it unconditionally, instead of trying to detect when an NPM package will run.

For the other two, setting it in task_runner.rs (in most of the ShellCommand impls) should do it I think. That would cover lifecycle scripts/deno install and deno task.


// 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()?
Expand Down