Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 27 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}