-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Adjust the checkIfOnline
check if in a corporate proxy environment
#2884
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@@ -606,7 +606,7 @@ function isSafeToCreateProjectIn(root, name) { | |||
} | |||
|
|||
function checkIfOnline(useYarn) { | |||
if (!useYarn) { | |||
if (!useYarn || process.env.https_proxy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if skipping this check when proxy is defined is the best course of action -- can we try to resolve the URL through the proxy instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first thought too. However, to test whether yarn has access vs the node process has access are quite different things and one doesn't necessarily prove the other.
Similarly, being able to resolve the address in DNS doesn't prove yarn will work either, which made me consider the purpose of this check. My conclusion was that this is an aid to make a best effort if there isn't an internet connection.
My thinking from there was that in its current state, you can't use create-react-app if you need a proxy, regardless of settings. With this change at worst you'll get a different error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about extracting the hostname from https_proxy
and looking that up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable, I'll make the change this morning.
Thinking out loud: What if the proxy is specified by IP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Seems fine:
> dns.lookup('127.0.0.1', console.log)
{}
> null '127.0.0.1' 4
> dns.lookup('10.5.3.2', console.log)
{}
> null '10.5.3.2' 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for checking. I'll update in a couple of hours.
If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes facebook#2832.
checkIfOnline
check if in a corporate proxy environmentcheckIfOnline
check if in a corporate proxy environment
if (process.env.https_proxy) { | ||
host = url.parse(process.env.https_proxy).hostname; | ||
} | ||
dns.lookup(host, err => { | ||
resolve(err === null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here, this strict equality in this case makes me uncomfortable -- can we do == null
?
Neat, thanks for fixing that so quick! Does this fix it for you when running it locally with the patch installed by hand? |
Yes. I tested by calling the script directly, rather than the globally installed version. |
Hmm, I wonder if we should always test What do you think? |
I agree with the caution. Proxies and people's configurations are always troublesome. |
@@ -614,7 +615,15 @@ function checkIfOnline(useYarn) { | |||
|
|||
return new Promise(resolve => { | |||
dns.lookup('registry.yarnpkg.com', err => { | |||
resolve(err === null); | |||
if (err && process.env.https_proxy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this to be err != null
.
Great, thanks so much for this! |
Hi there! This change is out in |
Great. I'll update first thing tomorrow. |
Well, I guess in this case |
…(#2884) * Adjust the `checkIfOnline` check if in a corporate proxy environment If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes #2832. * Adjust to check yarnpkg.com first, then check the proxy address only if that failed
* commit 'bfaee410c502a95076a6bd89721c76ca08e15f7b': (39 commits) Publish Prepare for 1.0.11 release (facebook#2924) Update dev deps (facebook#2923) Update README.md Use env variable to disable source maps (facebook#2818) Make formatWebpackMessages return all messages (facebook#2834) Adjust the `checkIfOnline` check if in a corporate proxy environment (facebook#2884) Fix the order of arguments in spawned child proc (facebook#2913) Feature/webpack 3 4 (facebook#2875) Allow importing package.json (facebook#2468) Re-enable flowtype warning (facebook#2718) Format UglifyJs error (facebook#2650) Unstage yarn.lock pre-commit (facebook#2700) Update README.md Update README.md Add Electrode to alternatives (facebook#2728) Fix parsing HTML/JSX tags to real elements (facebook#2796) Update webpack version note (facebook#2798) Use modern syntax feature (facebook#2873) Allow use of scoped packages with a pinned version (facebook#2853) ... # Conflicts: # packages/react-scripts/config/webpack.config.dev.js # packages/react-scripts/config/webpack.config.prod.js # packages/react-scripts/package.json
…react-app * 'master' of https://github.com/facebookincubator/create-react-app: (36 commits) Publish Changelog for 1.0.12 (facebook#3016) Relax React dep requirements Default Favicon lossless optimisation (facebook#2917) update babel-runtime dependency in react-error-overlay and react-scripts (facebook#2991) Convert react-error-overlay to React (facebook#2515) Bump react-dev-utils Fix module function name in error overlay (facebook#3012) Docs: debugging in WebStorm (facebook#2986) Fix docs for `printFileSizesAfterBuild` (facebook#2942) Remove Modulus from user guide (facebook#2948) Remove superfluous lodash usage (facebook#2938) Update README.md (facebook#2927) Publish Prepare for 1.0.11 release (facebook#2924) Update dev deps (facebook#2923) Update README.md Use env variable to disable source maps (facebook#2818) Make formatWebpackMessages return all messages (facebook#2834) Adjust the `checkIfOnline` check if in a corporate proxy environment (facebook#2884) ...
…(#2884) * Adjust the `checkIfOnline` check if in a corporate proxy environment If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes #2832. * Adjust to check yarnpkg.com first, then check the proxy address only if that failed
…acebook#2884) * Adjust the `checkIfOnline` check if in a corporate proxy environment If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes facebook#2832. * Adjust to check yarnpkg.com first, then check the proxy address only if that failed
…(#2884) * Adjust the `checkIfOnline` check if in a corporate proxy environment If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes #2832. * Adjust to check yarnpkg.com first, then check the proxy address only if that failed
This is insufficient in some corp environments, where they run an internal registry with no direct access to the Internet even via a proxy (and thus the check should be against whatever URL yarn's That said, I don't understand why this offline check code exists in the first place - yarn will already use its local cache if the network is unavailable so you shouldn't need to add the |
Adjust the
checkIfOnline
check if in a corporate proxy environmentIf the environment variable
https_proxy
is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'.Testing on a corporate network where proxies are required. Prior to change, installation fails as per #2832, post change installation works happily.
Before:
After with proxy set & required:
After with proxy not set, but required:
After with proxy set incorrectly: