mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -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)
|
(module downloads, fetch)
|
||||||
HTTPS_PROXY Proxy address for HTTPS requests
|
HTTPS_PROXY Proxy address for HTTPS requests
|
||||||
(module downloads, fetch)
|
(module downloads, fetch)
|
||||||
|
NPM_CONFIG_REGISTRY URL to use for the npm registry.
|
||||||
NO_COLOR Set to disable color
|
NO_COLOR Set to disable color
|
||||||
NO_PROXY Comma-separated list of hosts which do not use a proxy
|
NO_PROXY Comma-separated list of hosts which do not use a proxy
|
||||||
(module downloads, fetch)"#;
|
(module downloads, fetch)"#;
|
||||||
|
|
|
@ -228,22 +228,37 @@ pub struct RealNpmRegistryApi(Arc<RealNpmRegistryApiInner>);
|
||||||
|
|
||||||
impl RealNpmRegistryApi {
|
impl RealNpmRegistryApi {
|
||||||
pub fn default_url() -> Url {
|
pub fn default_url() -> Url {
|
||||||
let env_var_name = "DENO_NPM_REGISTRY";
|
// todo(dsherret): remove DENO_NPM_REGISTRY in the future (maybe May 2023)
|
||||||
if let Ok(registry_url) = std::env::var(env_var_name) {
|
let env_var_names = ["NPM_CONFIG_REGISTRY", "DENO_NPM_REGISTRY"];
|
||||||
// ensure there is a trailing slash for the directory
|
for env_var_name in env_var_names {
|
||||||
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
|
if let Ok(registry_url) = std::env::var(env_var_name) {
|
||||||
match Url::parse(®istry_url) {
|
// ensure there is a trailing slash for the directory
|
||||||
Ok(url) => url,
|
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
|
||||||
Err(err) => {
|
match Url::parse(®istry_url) {
|
||||||
eprintln!("{}: Invalid {} environment variable. Please provide a valid url.\n\n{:#}",
|
Ok(url) => {
|
||||||
colors::red_bold("error"),
|
if env_var_name == "DENO_NPM_REGISTRY" {
|
||||||
env_var_name, err);
|
log::warn!(
|
||||||
std::process::exit(1);
|
"{}",
|
||||||
|
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(
|
pub fn new(
|
||||||
|
|
|
@ -97,7 +97,7 @@ lazy_static! {
|
||||||
pub fn env_vars_for_npm_tests_no_sync_download() -> Vec<(String, String)> {
|
pub fn env_vars_for_npm_tests_no_sync_download() -> Vec<(String, String)> {
|
||||||
vec![
|
vec![
|
||||||
("DENO_NODE_COMPAT_URL".to_string(), std_file_url()),
|
("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()),
|
("NO_COLOR".to_string(), "1".to_string()),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,7 @@ impl LspClient {
|
||||||
command
|
command
|
||||||
.env("DENO_DIR", deno_dir.path())
|
.env("DENO_DIR", deno_dir.path())
|
||||||
.env("DENO_NODE_COMPAT_URL", std_file_url())
|
.env("DENO_NODE_COMPAT_URL", std_file_url())
|
||||||
.env("DENO_NPM_REGISTRY", npm_registry_url())
|
.env("NPM_CONFIG_REGISTRY", npm_registry_url())
|
||||||
.arg("lsp")
|
.arg("lsp")
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped());
|
.stdout(Stdio::piped());
|
||||||
|
|
Loading…
Reference in a new issue