mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
feat(npm): add support for NPM_CONFIG_REGISTRY
(#16980)
This commit is contained in:
parent
1a472ad06b
commit
f8bcf6be28
4 changed files with 31 additions and 15 deletions
|
@ -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)"#;
|
||||
|
|
|
@ -228,23 +228,38 @@ pub struct RealNpmRegistryApi(Arc<RealNpmRegistryApiInner>);
|
|||
|
||||
impl RealNpmRegistryApi {
|
||||
pub fn default_url() -> Url {
|
||||
let env_var_name = "DENO_NPM_REGISTRY";
|
||||
// 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) => 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) => {
|
||||
eprintln!("{}: Invalid {} environment variable. Please provide a valid url.\n\n{:#}",
|
||||
colors::red_bold("error"),
|
||||
env_var_name, err);
|
||||
std::process::exit(1);
|
||||
log::debug!(
|
||||
"Invalid {} environment variable: {:#}",
|
||||
env_var_name,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
Url::parse("https://registry.npmjs.org").unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
base_url: Url,
|
||||
|
|
|
@ -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()),
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue