Skip to content

Commit

Permalink
🧭 Default Safari TP to latest Safari version, close #8
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Jan 3, 2024
1 parent 37dbc51 commit 2dd955c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ function browserslistToEsbuild(browserslistConfig) {
browserslist(browserslistConfig)
// filter out the unsupported ones
.filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u)))
// replaces safari TP with latest safari version
.map((b) => {
if (b === 'safari TP') {
return browserslist('last 1 safari version')[0]
}

return b
})
// transform into ['chrome', '88']
.map((b) => b.split(separator))
// replace the similar browser
Expand All @@ -63,7 +71,10 @@ function browserslistToEsbuild(browserslistConfig) {

return b
})
// only get the ones supported by esbuild
// removes invalid versions that will break esbuild
// https://github.com/evanw/esbuild/blob/35c0d65b9d4f29a26176404d2890d1b499634e9f/compat-table/src/caniuse.ts#L119-L122
.filter((b) => /^\d+(\.\d+)*$/.test(b[1]))
// only get the targets supported by esbuild
.filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0]))
// only get the oldest version, assuming that the older version
// is last in the array
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ test('no support for android 4', (t) => {

t.deepEqual(target, ['chrome120'])
})

test('safari TP defaults to latest safari', (t) => {
const target = browserslistToEsbuild('safari TP')

t.deepEqual(target, ['safari17.2'])
})

0 comments on commit 2dd955c

Please sign in to comment.