cli: Fix dns in NODE_OPTIONS (#928)
This commit is contained in:
parent
0f86dc8dd5
commit
d10413fc70
|
@ -11,6 +11,10 @@ incremented for features.
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixes
|
||||
|
||||
* cli: fix dns in NODE_OPTIONS ([#928](https://github.com/project-serum/anchor/pull/928)).
|
||||
|
||||
## [0.18.0] - 2021-10-24
|
||||
|
||||
### Features
|
||||
|
|
|
@ -150,6 +150,7 @@ dependencies = [
|
|||
"pathdiff",
|
||||
"rand 0.7.3",
|
||||
"reqwest",
|
||||
"semver 1.0.4",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serum-common",
|
||||
|
@ -2635,6 +2636,12 @@ dependencies = [
|
|||
"semver-parser 0.10.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
|
|
|
@ -22,6 +22,7 @@ anchor-syn = { path = "../lang/syn", features = ["idl"] }
|
|||
serde_json = "1.0"
|
||||
shellexpand = "2.1.0"
|
||||
toml = "0.5.8"
|
||||
semver = "1.0.4"
|
||||
serde = { version = "1.0.122", features = ["derive"] }
|
||||
solana-sdk = "1.8.0"
|
||||
solana-program = "1.8.0"
|
||||
|
|
|
@ -16,6 +16,7 @@ use heck::SnakeCase;
|
|||
use rand::rngs::OsRng;
|
||||
use reqwest::blocking::multipart::{Form, Part};
|
||||
use reqwest::blocking::Client;
|
||||
use semver::{Version, VersionReq};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
use solana_client::rpc_config::RpcSendTransactionConfig;
|
||||
|
@ -1478,13 +1479,14 @@ fn test(
|
|||
let url = cluster_url(cfg);
|
||||
|
||||
let node_options = format!(
|
||||
"{} --dns-result-order=ipv4first",
|
||||
"{} {}",
|
||||
match std::env::var_os("NODE_OPTIONS") {
|
||||
Some(value) => value
|
||||
.into_string()
|
||||
.map_err(std::env::VarError::NotUnicode)?,
|
||||
None => "".to_owned(),
|
||||
}
|
||||
},
|
||||
get_node_dns_option()?,
|
||||
);
|
||||
|
||||
// Setup log reader.
|
||||
|
@ -2514,3 +2516,26 @@ fn is_hidden(entry: &walkdir::DirEntry) -> bool {
|
|||
.map(|s| s == "." || s.starts_with('.') || s == "target")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn get_node_version() -> Result<Version> {
|
||||
let node_version = std::process::Command::new("node")
|
||||
.arg("--version")
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.map_err(|e| anyhow::format_err!("node failed: {}", e.to_string()))?;
|
||||
let output = std::str::from_utf8(&node_version.stdout)?
|
||||
.strip_prefix('v')
|
||||
.unwrap()
|
||||
.trim();
|
||||
Version::parse(output).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn get_node_dns_option() -> Result<&'static str> {
|
||||
let version = get_node_version()?;
|
||||
let req = VersionReq::parse(">=16.4.0").unwrap();
|
||||
let option = match req.matches(&version) {
|
||||
true => "--dns-result-order=ipv4first",
|
||||
false => "",
|
||||
};
|
||||
Ok(option)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue