Commit 3a0b836b authored by Maksym Dogadailo's avatar Maksym Dogadailo Committed by Dan Abramov
Browse files

added getProxy (#3320)

* added getProxy

getProxy checks proxy settings from process.env.https_proxy or Yarn (NPM) config (.npmrc)

* changed yarn for npm to get https-proxy 

default value for https-proxy is null, not undefined like in yarn
parent 887fd10e
Showing with 18 additions and 2 deletions
+18 -2
......@@ -639,6 +639,21 @@ function isSafeToCreateProjectIn(root, name) {
return false;
}
function getProxy() {
if (process.env.https_proxy) {
return process.env.https_proxy;
} else {
try {
// Trying to read https-proxy from .npmrc
let httpsProxy = execSync('npm config get https-proxy')
.toString()
.trim();
return httpsProxy !== 'null' ? httpsProxy : undefined;
} catch (e) {
return;
}
}
}
function checkThatNpmCanReadCwd() {
const cwd = process.cwd();
let childOutput = null;
......@@ -709,10 +724,11 @@ function checkIfOnline(useYarn) {
return new Promise(resolve => {
dns.lookup('registry.yarnpkg.com', err => {
if (err != null && process.env.https_proxy) {
let proxy;
if (err != null && (proxy = getProxy())) {
// If a proxy is defined, we likely can't resolve external hostnames.
// Try to resolve the proxy name as an indication of a connection.
dns.lookup(url.parse(process.env.https_proxy).hostname, proxyErr => {
dns.lookup(url.parse(proxy).hostname, proxyErr => {
resolve(proxyErr == null);
});
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment