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

Adjust the checkIfOnline check if in a corporate proxy environment #2884

Merged
merged 2 commits into from
Aug 9, 2017

Conversation

bsyk
Copy link
Contributor

@bsyk bsyk commented Aug 1, 2017

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'.

Testing on a corporate network where proxies are required. Prior to change, installation fails as per #2832, post change installation works happily.

Before:
screen shot 2017-08-01 at 11 20 11 am

After with proxy set & required:
screen shot 2017-08-01 at 11 19 32 am

After with proxy not set, but required:
screen shot 2017-08-02 at 9 38 04 am

After with proxy set incorrectly:
screen shot 2017-08-02 at 9 38 18 am

@facebook-github-bot
Copy link

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 cla@fb.com. Thanks!

@facebook-github-bot
Copy link

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

@bsyk bsyk Aug 2, 2017

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.
@bsyk bsyk changed the title Bypass the checkIfOnline check if in a corporate proxy environment Adjust the checkIfOnline check if in a corporate proxy environment Aug 2, 2017
if (process.env.https_proxy) {
host = url.parse(process.env.https_proxy).hostname;
}
dns.lookup(host, err => {
resolve(err === null);
Copy link
Contributor

@Timer Timer Aug 6, 2017

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?

@Timer
Copy link
Contributor

Timer commented Aug 6, 2017

Neat, thanks for fixing that so quick!

Does this fix it for you when running it locally with the patch installed by hand?

@Timer Timer added this to the 1.0.11 milestone Aug 6, 2017
@bsyk
Copy link
Contributor Author

bsyk commented Aug 6, 2017

Yes. I tested by calling the script directly, rather than the globally installed version.
Screenshots are in the first PR comment.

@Timer
Copy link
Contributor

Timer commented Aug 6, 2017

Hmm, I wonder if we should always test registry.yarnpkg.com first, followed by proxy if set.
I'm not sure of edge cases we might want to account for, and I like to be careful with the global CLI.

What do you think?

@bsyk
Copy link
Contributor Author

bsyk commented Aug 6, 2017

I agree with the caution. Proxies and people's configurations are always troublesome.
Seems like a decent approach to try yarn first, then if that fails and a proxy is set to try the proxy.

@@ -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) {
Copy link
Contributor

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.

@Timer
Copy link
Contributor

Timer commented Aug 9, 2017

Great, thanks so much for this!

@Timer Timer merged commit d009a99 into facebook:master Aug 9, 2017
@Timer
Copy link
Contributor

Timer commented Aug 9, 2017

Hi there! This change is out in react-scripts@1.0.11; please give it a go! Thanks.

@bsyk
Copy link
Contributor Author

bsyk commented Aug 9, 2017

Great. I'll update first thing tomorrow.
Thanks for your thoughts on this.

@Timer
Copy link
Contributor

Timer commented Aug 9, 2017

Well, I guess in this case create-react-app@1.4.0. 😄

JohnNilsson referenced this pull request in JohnNilsson/create-react-app-typescript Aug 9, 2017
…(#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
zangrafx added a commit to absolvent/create-react-app that referenced this pull request Aug 13, 2017
* 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
matart15 pushed a commit to matart15/create-react-app that referenced this pull request Aug 29, 2017
…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)
  ...
JohnNilsson referenced this pull request in JohnNilsson/create-react-app-typescript Sep 9, 2017
…(#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
kasperpeulen pushed a commit to kasperpeulen/create-react-app that referenced this pull request Sep 24, 2017
…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
swengorschewski referenced this pull request in swengorschewski/cra-typescript-electron Oct 16, 2017
…(#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
@herebebeasties
Copy link

herebebeasties commented Dec 22, 2017

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 registry config value is set to, which can be picked up from a large number of places, but which you could obviously parse via yarn config get registry).

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 --offline flag or have to do this check at all?

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants