-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): correctly pick up browserslist overrides (#9669)
* fix: start ironing out browserslist issues * chore: make linter happy * chore: change to expected shape * refactor: move browserslist functionality into gatsby core
- Loading branch information
Showing
8 changed files
with
97 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
jest.mock(`browserslist/node`, () => { | ||
return { | ||
findConfig: jest.fn(), | ||
} | ||
}) | ||
const path = require(`path`) | ||
const getBrowsersList = require(`../browserslist`) | ||
const { findConfig: mockedFindConfig } = require(`browserslist/node`) | ||
|
||
const BASE = path.resolve(`.`) | ||
|
||
describe(`browserslist`, () => { | ||
it(`prefers returned browserslist results`, () => { | ||
const defaults = [`IE 11`] | ||
mockedFindConfig.mockReturnValueOnce({ | ||
defaults, | ||
}) | ||
|
||
const list = getBrowsersList(BASE) | ||
|
||
expect(list).toEqual(defaults) | ||
}) | ||
|
||
it(`falls back to defaults`, () => { | ||
mockedFindConfig.mockReturnValueOnce(undefined) | ||
|
||
const list = getBrowsersList(BASE) | ||
|
||
expect(list).toEqual([`>0.25%`, `not dead`]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const path = require(`path`) | ||
const browserslist = require(`browserslist/node`) | ||
|
||
function installedGatsbyVersion(directory) { | ||
try { | ||
const { version } = require(path.join( | ||
directory, | ||
`node_modules`, | ||
`gatsby`, | ||
`package.json` | ||
)) | ||
return parseInt(version.split(`.`)[0], 10) | ||
} catch (e) { | ||
return undefined | ||
} | ||
} | ||
|
||
module.exports = function getBrowsersList(directory) { | ||
const fallback = | ||
installedGatsbyVersion(directory) === 1 | ||
? [`>1%`, `last 2 versions`, `IE >= 9`] | ||
: [`>0.25%`, `not dead`] | ||
|
||
const config = browserslist.findConfig(directory) | ||
|
||
if (config && config.defaults) { | ||
return config.defaults | ||
} | ||
|
||
return fallback | ||
} |