-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Compat fix for gatsby-cli v2 with gatsby v1 #8581
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
Conversation
let majorVersion | ||
try { | ||
let packagePath = require.resolve( | ||
path.join(process.cwd(), `node_modules`, `gatsby`, `package.json`) |
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.
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`] |
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.
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)) |
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.
You can do require(`gatsby/package.json`)
like in here I think:
const { version: gatsbyVersion } = require(`gatsby/package.json`) |
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.
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?
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.
Thanks @m-allanson!
* '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)
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 havegatsby-cli
v2 installed and you're working on a Gatsby v1 site.Fixes #8575
Refs #8560
Refs #7144