Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getProxy #3320

Merged
merged 3 commits into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,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;
Expand Down Expand Up @@ -688,10 +703,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 {
Expand Down