| 108 | } |
| 109 | |
| 110 | function checkIfOnline(useYarn) { |
| 111 | if (!useYarn) { |
| 112 | // Don't ping the Yarn registry. |
| 113 | // We'll just assume the best case. |
| 114 | return Promise.resolve(true); |
| 115 | } |
| 116 | |
| 117 | return new Promise((resolve) => { |
| 118 | dns.lookup('registry.yarnpkg.com', (err) => { |
| 119 | let proxy; |
| 120 | if (err != null && (proxy = getProxy())) { |
| 121 | // If a proxy is defined, we likely can't resolve external hostnames. |
| 122 | // Try to resolve the proxy name as an indication of a connection. |
| 123 | dns.lookup(url.parse(proxy).hostname, (proxyErr) => { |
| 124 | resolve(proxyErr == null); |
| 125 | }); |
| 126 | } else { |
| 127 | resolve(err == null); |
| 128 | } |
| 129 | }); |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | module.exports = { |
| 134 | toCamelCase, |