Skip to content
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

fix(gatsby): Remove default support for non ESM browsers #36522

Merged
merged 8 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/gatsby/src/utils/__tests__/browserslist.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ 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`])
marvinjude marked this conversation as resolved.
Show resolved Hide resolved
})

it(`hasES6ModuleSupport returns true if all browsers support es6 modules`, () => {
Expand Down
13 changes: 10 additions & 3 deletions packages/gatsby/src/utils/browserslist.ts
Original file line number Diff line number Diff line change
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