1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

feat(npm): add support for NPM_CONFIG_REGISTRY (#16980)

This commit is contained in:
David Sherret 2022-12-07 16:10:50 -05:00 committed by GitHub
parent 1a472ad06b
commit f8bcf6be28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 15 deletions

View file

@ -547,6 +547,7 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
(module downloads, fetch)
HTTPS_PROXY Proxy address for HTTPS requests
(module downloads, fetch)
NPM_CONFIG_REGISTRY URL to use for the npm registry.
NO_COLOR Set to disable color
NO_PROXY Comma-separated list of hosts which do not use a proxy
(module downloads, fetch)"#;

View file

@ -228,22 +228,37 @@ pub struct RealNpmRegistryApi(Arc<RealNpmRegistryApiInner>);
impl RealNpmRegistryApi {
pub fn default_url() -> Url {
let env_var_name = "DENO_NPM_REGISTRY";
if let Ok(registry_url) = std::env::var(env_var_name) {
// ensure there is a trailing slash for the directory
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
match Url::parse(&registry_url) {
Ok(url) => url,
Err(err) => {
eprintln!("{}: Invalid {} environment variable. Please provide a valid url.\n\n{:#}",
colors::red_bold("error"),
env_var_name, err);
std::process::exit(1);
// todo(dsherret): remove DENO_NPM_REGISTRY in the future (maybe May 2023)
let env_var_names = ["NPM_CONFIG_REGISTRY", "DENO_NPM_REGISTRY"];
for env_var_name in env_var_names {
if let Ok(registry_url) = std::env::var(env_var_name) {
// ensure there is a trailing slash for the directory
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
match Url::parse(&registry_url) {
Ok(url) => {
if env_var_name == "DENO_NPM_REGISTRY" {
log::warn!(
"{}",
colors::yellow(concat!(
"DENO_NPM_REGISTRY was intended for internal testing purposes only. ",
"Please update to NPM_CONFIG_REGISTRY instead.",
)),
);
}
return url;
}
Err(err) => {
log::debug!(
"Invalid {} environment variable: {:#}",
env_var_name,
err,
);
}
}
}
} else {
Url::parse("https://registry.npmjs.org").unwrap()
}
Url::parse("https://registry.npmjs.org").unwrap()
}
pub fn new(

View file

@ -97,7 +97,7 @@ lazy_static! {
pub fn env_vars_for_npm_tests_no_sync_download() -> Vec<(String, String)> {
vec![
("DENO_NODE_COMPAT_URL".to_string(), std_file_url()),
("DENO_NPM_REGISTRY".to_string(), npm_registry_url()),
("NPM_CONFIG_REGISTRY".to_string(), npm_registry_url()),
("NO_COLOR".to_string(), "1".to_string()),
]
}

View file

@ -234,7 +234,7 @@ impl LspClient {
command
.env("DENO_DIR", deno_dir.path())
.env("DENO_NODE_COMPAT_URL", std_file_url())
.env("DENO_NPM_REGISTRY", npm_registry_url())
.env("NPM_CONFIG_REGISTRY", npm_registry_url())
.arg("lsp")
.stdin(Stdio::piped())
.stdout(Stdio::piped());