Skip to content

Commit 3a0b836

Browse files
mdogadailogaearon
authored andcommitted
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
1 parent 887fd10 commit 3a0b836

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/create-react-app/createReactApp.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,21 @@ function isSafeToCreateProjectIn(root, name) {
639639
return false;
640640
}
641641

642+
function getProxy() {
643+
if (process.env.https_proxy) {
644+
return process.env.https_proxy;
645+
} else {
646+
try {
647+
// Trying to read https-proxy from .npmrc
648+
let httpsProxy = execSync('npm config get https-proxy')
649+
.toString()
650+
.trim();
651+
return httpsProxy !== 'null' ? httpsProxy : undefined;
652+
} catch (e) {
653+
return;
654+
}
655+
}
656+
}
642657
function checkThatNpmCanReadCwd() {
643658
const cwd = process.cwd();
644659
let childOutput = null;
@@ -709,10 +724,11 @@ function checkIfOnline(useYarn) {
709724

710725
return new Promise(resolve => {
711726
dns.lookup('registry.yarnpkg.com', err => {
712-
if (err != null && process.env.https_proxy) {
727+
let proxy;
728+
if (err != null && (proxy = getProxy())) {
713729
// If a proxy is defined, we likely can't resolve external hostnames.
714730
// Try to resolve the proxy name as an indication of a connection.
715-
dns.lookup(url.parse(process.env.https_proxy).hostname, proxyErr => {
731+
dns.lookup(url.parse(proxy).hostname, proxyErr => {
716732
resolve(proxyErr == null);
717733
});
718734
} else {

0 commit comments

Comments
 (0)