From 912f838317220ee8cbfecc383a0059f8a52624c2 Mon Sep 17 00:00:00 2001 From: mdogadailo Date: Tue, 24 Oct 2017 17:11:28 +0200 Subject: [PATCH 1/2] added getProxy getProxy checks proxy settings from process.env.https_proxy or Yarn (NPM) config (.npmrc) --- packages/create-react-app/createReactApp.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 161beab50e8..4640848059f 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -606,6 +606,22 @@ 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('yarn config get https-proxy') + .toString() + .trim(); + return httpsProxy !== 'undefined' ? httpsProxy : undefined; + } catch (e) { + return; + } + } +} + function checkIfOnline(useYarn) { if (!useYarn) { // Don't ping the Yarn registry. @@ -615,10 +631,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 { From f4eaea09476318a1abac70c9a5a8b0f86d5de832 Mon Sep 17 00:00:00 2001 From: Maksym Dogadailo Date: Sun, 29 Oct 2017 08:48:05 +0100 Subject: [PATCH 2/2] changed yarn for npm to get https-proxy default value for https-proxy is null, not undefined like in yarn --- packages/create-react-app/createReactApp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 4640848059f..9dd70440091 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -612,10 +612,10 @@ function getProxy() { } else { try { // Trying to read https-proxy from .npmrc - let httpsProxy = execSync('yarn config get https-proxy') + let httpsProxy = execSync('npm config get https-proxy') .toString() .trim(); - return httpsProxy !== 'undefined' ? httpsProxy : undefined; + return httpsProxy !== 'null' ? httpsProxy : undefined; } catch (e) { return; }