diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 7a4416cf50..f1acbf48dc 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -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)"#; diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 9ba5653662..749a047ab1 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -228,22 +228,37 @@ pub struct RealNpmRegistryApi(Arc); 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(®istry_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(®istry_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( diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index b1b14c0040..588b72bbe2 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -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()), ] } diff --git a/test_util/src/lsp.rs b/test_util/src/lsp.rs index b2c28268e0..c1e4c875aa 100644 --- a/test_util/src/lsp.rs +++ b/test_util/src/lsp.rs @@ -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());