Skip to content

Commit

Permalink
Manually map Safari versions in getMatchingBrowserVersion
Browse files Browse the repository at this point in the history
This is not ideal, but it fixes the problem now. Tests are in place to
ensure that if we fix it in some other way, there's no observable
difference.
  • Loading branch information
foolip committed Jul 13, 2022
1 parent 7f00d4c commit 773142d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/release/mirror.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ describe('mirror', () => {
['1.2', '1'],
['1.3', '1'],
['2', '1'],
['3', '2'], // wrong, should be 1
['3', '2'],
['3.1', '2'],
['4', '3.2'], // ambiguous
['4', '3.2'],
['5', '4.2'],
['5.1', '6'],
['6', '6'],
['7', '8'], // wrong, should be 7
['7', '7'],
['8', '8'],
['9', '9'],
['9.1', '9.3'],
Expand All @@ -85,7 +85,7 @@ describe('mirror', () => {
['13.1', '13.4'],
['14', '14'],
['14.1', '14.5'],
['15', '15.1'], // wrong, should be 15
['15', '15'],
['15.1', '15.1'],
['15.2', '15.2'],
['15.3', '15.3'],
Expand Down
41 changes: 41 additions & 0 deletions scripts/release/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ import compareVersions from 'compare-versions';
import bcd from '../../index.js';
const { browsers } = bcd;

/**
* @typedef {import('../types').Identifier} Identifier
* @typedef {import('../types').SupportStatement} SupportStatement
* @typedef {import('../types').ReleaseStatement} ReleaseStatement
*/

const matchingSafariVersions = new Map([
['≤4', '≤3'],
['1', '1'],
['1.1', '1'],
['1.2', '1'],
['1.3', '1'],
['2', '1'],
['3', '2'],
['3.1', '2'],
['4', '3.2'],
['5', '4.2'],
['5.1', '6'],
['9.1', '9.3'],
['10.1', '10.3'],
['11.1', '11.3'],
['12.1', '12.2'],
['13.1', '13.4'],
['14.1', '14.5'],
]);

/**
* @param {string} targetBrowser
* @param {string} sourceVersion
Expand All @@ -33,6 +59,21 @@ export const getMatchingBrowserVersion = (
}
/* c8 ignore stop */

if (targetBrowser === 'safari_ios') {
// The mapping between Safari macOS and iOS releases is complicated and
// cannot be entirely derived from the WebKit versions. After Safari 15
// the versions have been the same, so map earlier versions manually
// and then assume if the versions are identical it's also a match.
const v = matchingSafariVersions.get(sourceVersion);
if (v) {
return v;
}
if (sourceVersion in browserData.releases) {
return sourceVersion;
}
throw new Error(`Cannot find iOS version matching Safari ${sourceVersion}`);
}

const releaseKeys = Object.keys(browserData.releases);
releaseKeys.sort(compareVersions);

Expand Down

0 comments on commit 773142d

Please sign in to comment.