Skip to content

Commit

Permalink
fix(gatsby): Remove default support for non ESM browsers (#36522)
Browse files Browse the repository at this point in the history
Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
marvinjude and wardpeet committed Sep 7, 2022
1 parent fab2db2 commit 8b59183
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/gatsby/src/utils/__tests__/browserslist.js
Expand Up @@ -28,7 +28,14 @@ describe(`browserslist`, () => {

const list = getBrowsersList(BASE)

expect(list).toEqual([`>0.25%`, `not dead`])
if (_CFLAGS_.GATSBY_MAJOR === `5`) {
expect(list).toEqual([
`>0.25% and supports es6-module`,
`not dead and supports es6-module`,
])
} else {
expect(list).toEqual([`>0.25%`, `not dead`])
}
})

it(`hasES6ModuleSupport returns true if all browsers support es6 modules`, () => {
Expand Down
13 changes: 10 additions & 3 deletions packages/gatsby/src/utils/browserslist.ts
Expand Up @@ -18,10 +18,17 @@ const installedGatsbyVersion = (directory: string): number | undefined => {
}

export const getBrowsersList = (directory: string): Array<string> => {
const fallbackV1 = [`>1%`, `last 2 versions`, `IE >= 9`]
let fallbackOthers = [`>0.25%`, `not dead`]

if (_CFLAGS_.GATSBY_MAJOR === `5`) {
fallbackOthers = fallbackOthers.map(
fallback => fallback + ` and supports es6-module`
)
}

const fallback =
installedGatsbyVersion(directory) === 1
? [`>1%`, `last 2 versions`, `IE >= 9`]
: [`>0.25%`, `not dead`]
installedGatsbyVersion(directory) === 1 ? fallbackV1 : fallbackOthers

const config = browserslist.findConfig(directory)

Expand Down

0 comments on commit 8b59183

Please sign in to comment.