Skip to content

Commit

Permalink
fix: add compat fix for gatsby-cli v2 with gatsby v1 (#8581)
Browse files Browse the repository at this point in the history
* Use old browserslist query for Gatsby v1

* Neater require

* Remove unused import
  • Loading branch information
m-allanson authored and pieh committed Sep 27, 2018
1 parent f497b74 commit 279ea76
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions packages/gatsby-cli/src/create-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const report = require(`./reporter`)
const envinfo = require(`envinfo`)
const existsSync = require(`fs-exists-cached`).sync

const DEFAULT_BROWSERS = [`>0.25%`, `not dead`]

const handlerP = fn => (...args) => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
Expand All @@ -18,6 +16,12 @@ function buildLocalCommands(cli, isLocalSite) {
const defaultHost = `localhost`
const directory = path.resolve(`.`)

// 'not dead' query not available in browserslist used in Gatsby v1
const DEFAULT_BROWSERS =
installedGatsbyVersion() === 1
? [`> 1%`, `last 2 versions`, `IE >= 9`]
: [`>0.25%`, `not dead`]

let siteInfo = { directory, browserslist: DEFAULT_BROWSERS }
const useYarn = existsSync(path.join(directory, `yarn.lock`))
if (isLocalSite) {
Expand All @@ -26,6 +30,23 @@ function buildLocalCommands(cli, isLocalSite) {
siteInfo.browserslist = json.browserslist || siteInfo.browserslist
}

function installedGatsbyVersion() {
let majorVersion
try {
const packageInfo = require(path.join(
process.cwd(),
`node_modules`,
`gatsby`,
`package.json`
))
majorVersion = parseInt(packageInfo.version.split(`.`)[0], 10)
} catch (err) {
/* ignore */
}

return majorVersion
}

function resolveLocalCommand(command) {
if (!isLocalSite) {
cli.showHelp()
Expand Down

0 comments on commit 279ea76

Please sign in to comment.