Skip to content

Conversation

m-allanson
Copy link
Contributor

@m-allanson m-allanson commented Sep 27, 2018

Gatsby v1 includes postcss-next which uses an older version of browserslist. This means the default browserslist query ["> 0.25%", "not dead"] won't work in Gatsby v1. This causes an error when you have gatsby-cli v2 installed and you're working on a Gatsby v1 site.

Fixes #8575
Refs #8560
Refs #7144

@m-allanson m-allanson requested a review from a team September 27, 2018 10:01
@m-allanson m-allanson changed the title Use old browserslist query for Gatsby v1 Compat fix for gatsby-cli v2 with gatsby v1 Sep 27, 2018
let majorVersion
try {
let packagePath = require.resolve(
path.join(process.cwd(), `node_modules`, `gatsby`, `package.json`)
Copy link
Contributor Author

@m-allanson m-allanson Sep 27, 2018

Choose a reason for hiding this comment

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

Not sure how reliable this is... it will at least fail silently.

const DEFAULT_BROWSERS =
installedGatsbyVersion() === 1
? [`> 1%`, `last 2 versions`, `IE >= 9`]
: [`>0.25%`, `not dead`]
Copy link
Contributor Author

@m-allanson m-allanson Sep 27, 2018

Choose a reason for hiding this comment

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

This defaults to the Gatsby v2 query unless we definitely know this is a v1 site.

let packagePath = require.resolve(
path.join(process.cwd(), `node_modules`, `gatsby`, `package.json`)
)
const packageInfo = JSON.parse(fs.readFileSync(packagePath))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do require(`gatsby/package.json`) like in here I think:

const { version: gatsbyVersion } = require(`gatsby/package.json`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, straight up require. Thanks 😅

I think this still needs to use process.cwd() to provide an absolute path - otherwise the require doesn't resolve the local node_modules directory from a globally installed gatsby-cli. Maybe there's a neater way?

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Thanks @m-allanson!

@pieh pieh merged commit 279ea76 into master Sep 27, 2018
@pieh pieh deleted the cli-v1-v2-compat branch September 27, 2018 11:10
lipis added a commit to lipis/gatsby that referenced this pull request Sep 27, 2018
* 'master' of github.com:gatsbyjs/gatsby:
  Add blog post on v2 reach router (gatsbyjs#8508)
  feat: add self to community page (gatsbyjs#8572)
  feat: update sites.yml (gatsbyjs#8589)
  Add an example to the sourceNodes docs (gatsbyjs#8585)
  chore(release): Publish
  fix: add compat fix for gatsby-cli v2 with gatsby v1 (gatsbyjs#8581)
  fix: fix unhandled rejection when no browser found when running with --open flag (gatsbyjs#8507)
  Fix writing out new page information (so new pages hot reload) during development (gatsbyjs#8570)
  Run coverage at the end of jest and configure thresholds (gatsbyjs#8371)
  chore(release): Publish
  chore: update gatsby-source-drupal version in using-drupal example (gatsbyjs#8497)
  Typo fix in gatsby-source-graphql/README.md (gatsbyjs#8562)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants