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

Add preflight check to guard against wrong versions of webpack/eslint/jest higher up the tree #3771

Merged
merged 6 commits into from
Jan 13, 2018

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Jan 13, 2018

It looks like this:

screen shot 2018-01-13 at 02 43 55

I thought about extracting it to gist but I kinda like that we can substitute the dep name right into the message. We might also want to do something similar for duplicate React.

There is an opt-out mechanism mentioned at the very end (cc @jlongster):

SKIP_PREFLIGHT_CHECK=true

in .env file.

"Fixes" #1795.

@gaearon gaearon changed the title Add preflight check to guard against webpack/eslint/jest higher up the tree Add preflight check to guard against wrong versions of webpack/eslint/jest higher up the tree Jan 13, 2018
@gaearon gaearon added this to the 2.0.0 milestone Jan 13, 2018
@gaearon gaearon requested a review from Timer January 13, 2018 02:46
fs.readFileSync(maybeDepPackageJson, 'utf8')
);
const expectedVersion = expectedVersionsByDep[dep];
if (depPackageJson.version !== expectedVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the package is found and the version matches, do we need to continue looking up the tree?
In this case, we could splice it out of the array.

Our dependencies should never be hoisted out of our project [except in the case of Yarn Workspaces] and this fails spectacularly currently.


I'm fine with this if we want to be cautious and support Yarn Workspaces in the future

Copy link
Contributor

@Timer Timer Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame we have to look multiple levels, because if we only needed the first occurrence we could be sly and use require (simplifying this logic):

depsToCheck.map(name => {
  try {
    const { version } = require(`${name}/package.json`)
    // ...
  } catch (e) {
    // ignored
  }
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to support YW so I think we shouldn’t stop.

What fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just one level doesn’t help. In my example we’ll still find “our own” webpack but the project above might have its copy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What fails?

react-scripts when used with Yarn Workspaces, not this PR (what #3435 is attempting to solve).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just one level doesn’t help. In my example we’ll still find “our own” webpack but the project above might have its copy.

You're right. This LGTM.

)} package (apart from the expected ${chalk.bold(
'react-scripts'
)}) installed ${chalk.bold(dep)}.\n\n` +
`If nothing else helps, add ${chalk.bold(
Copy link
Contributor

@Timer Timer Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention valid cases?

When not using YW or Lerna+Hoist, it's valid to nest like so:

/node_modules
  /[email protected]
/client
  /node_modules
    /[email protected]
    /[email protected]
      /[email protected] (hoisted)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to other wordings!

@gaearon gaearon merged commit 197028c into facebook:next Jan 13, 2018
gaearon added a commit that referenced this pull request Jan 13, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
@gaearon gaearon deleted the verify-pkg branch January 13, 2018 20:23
Timer pushed a commit that referenced this pull request Jan 14, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
gaearon added a commit that referenced this pull request Jan 14, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
gaearon added a commit that referenced this pull request Jan 14, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
gaearon added a commit that referenced this pull request Jan 14, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
gaearon added a commit that referenced this pull request Jan 14, 2018
…/jest higher up the tree (#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
Timer pushed a commit to Timer/create-react-app that referenced this pull request Jan 15, 2018
…/jest higher up the tree (facebook#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
akstuhl pushed a commit to akstuhl/create-react-app that referenced this pull request Mar 15, 2018
…/jest higher up the tree (facebook#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
zmitry pushed a commit to zmitry/create-react-app that referenced this pull request Sep 30, 2018
…/jest higher up the tree (facebook#3771)

* Run real scripts in local development

* Add preflight check warning

* I know what I am doing

* Move preflight check into individual scripts

This ensures we don't try to filter NODE_PATH twice, accidentally removing the now-absolute path.

* Slightly tweak the wording

* Fix lint
@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.

3 participants