Skip to content

Commit

Permalink
Merge pull request #1142 from zloirock/compat-data-targets
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 8, 2022
2 parents 9550b06 + 3c7873c commit d732ad5
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 98 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
- Added Samsung Internet 19.0 compat data mapping
- Added Oculus Quest Browser 24.0 compat data mapping
- Fixed the first version in the Chromium-based Edge compat data mapping
- [Compat data targets](/packages/core-js-compat#targets-option) improvements:
- [React Native from 0.70 shipped with Hermes as the default engine.](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) However, bundled Hermes versions differ from standalone Hermes releases. So added **`react-native`** target for React Native with bundled Hermes.
- [According to the documentation](https://developer.oculus.com/documentation/web/browser-intro/), Oculus Browser was renamed to Meta Quest Browser, so `oculus` target was renamed to **`quest`**.
- `opera_mobile` target name is confusing since it contains data for the Chromium-based Android version, but iOS Opera is Safari-based. So `opera_mobile` target was renamed to **`opera-android`**.
- `android` target name is also confusing for someone - that means Android WebView, some think thinks that it's Chrome for Android, but they have some differences. For avoiding confusion, added **`chrome-android`** target.
- For consistency with two previous cases, added **`firefox-android`** target.
- For avoiding breaking changes, the `oculus` and `opera_mobile` fields are available in the compat data till the next major release.

##### [3.26.1 - 2022.11.14](https://github.com/zloirock/core-js/releases/tag/v3.26.1)
- Disabled forced replacing of `Array.fromAsync` since it's on Stage 3
Expand Down
47 changes: 25 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,39 @@ For updating `core-js-compat` data:

- If you want to add a new data for a browser, run in this browser `tests/compat/index.html` (tests and results for the actual release are available at [`http://zloirock.github.io/core-js/compat/`](http://zloirock.github.io/core-js/compat/)) and you will see what `core-js` modules are required for this browser.

![compat-table](https://user-images.githubusercontent.com/2213682/180694428-856bcd0f-cab3-446f-be1a-2f669614dcc0.png)
![compat-table](https://user-images.githubusercontent.com/2213682/202867481-69d28cd6-9e1a-453b-8875-39a5bf92eac3.png)

- If you want to add new data for NodeJS, run `npm run compat-node` with the installed required NodeJS version and you will see the results in the console. Use `npm run compat-node json` if you want to get the result as JSON.
- If you want to add new data for Deno, run `npm run compat-deno` with the installed required Deno version and you will see the results in the console. Use `npm run compat-deno json` if you want to get the result as JSON.
- If you want to add new data for Bun, run `npm run compat-bun` with the installed required Bun version and you will see the results in the console.
- If you want to add new data for Rhino, set the required Rhino version in `compat-rhino` NPM script in [`package.json`](./package.json), run `npm run compat-rhino` and you will see the results in the console.
- If you want to add new data for Hermes, run `npm run compat-hermes YOR_PATH_TO_HERMES` and you will see the results in the console.
- If you want to add new data for Hermes (incl. shipped with React Native), run `npm run compat-hermes YOR_PATH_TO_HERMES` and you will see the results in the console.
- After getting this data, add it to [`packages/core-js-compat/src/data.mjs`](./packages/core-js-compat/src/data.mjs).
- If you want to add new mapping (for example, to add a new iOS Safari version based on Safari or NodeJS based on Chrome), add it to [`packages/core-js-compat/src/mapping.mjs`](./packages/core-js-compat/src/mapping.mjs).

engine | how to run tests | base data inherits from | mandatory check | mapping for a new version
--- | --- | --- | --- | ---
`android` | browser runner | `chrome` | |
`bun` | bun runner | `safari` (only ES) | required |
`chrome` | browser runner | | required |
`deno` | deno runner | `chrome` (only ES) | non-ES features | required
`edge` | browser runner | `ie`, `chrome` | required |
`electron` | browser runner | `chrome` | | required
`firefox` | browser runner | | required |
`hermes` | hermes runner | | required |
`ie` | browser runner | | required |
`ios` | browser runner | `safari` | | if inconsistent (!= safari)
`node` | node runner | `chrome` (only ES) | non-ES features | required
`oculus` | browser runner | `android` (-> `chrome`) | | required
`opera` | browser runner | `chrome` | | if inconsistent (!= chrome - 14)
`opera_mobile` | browser runner | `opera`, `chrome` | | required
`phantom` | browser runner | `safari` | |
`rhino` | rhino runner | | required |
`safari` | browser runner | | required |
`samsung` | browser runner | `chrome` | | required
engine | how to run tests | base data inherits from | mandatory check | mapping for a new version
--- | --- | --- | --- | ---
`android` | browser runner | `chrome`, `chrome-android` | |
`bun` | bun runner | `safari` (only ES) | required |
`chrome` | browser runner | | required |
`chrome-android` | browser runner | `chrome` | |
`deno` | deno runner | `chrome` (only ES) | non-ES features | required
`edge` | browser runner | `ie`, `chrome` | required (<= 18) |
`electron` | browser runner | `chrome` | | required
`firefox` | browser runner | | required |
`firefox-android` | browser runner | `firefox` | |
`hermes` | hermes runner | | required |
`ie` | browser runner | | required |
`ios` | browser runner | `safari` | | if inconsistent (!= `safari`)
`node` | node runner | `chrome` (only ES) | non-ES features | required
`opera` | browser runner | `chrome` | | if inconsistent (!= `chrome` - 14)
`opera-android` | browser runner | `opera`, `chrome-android` | | required
`phantom` | browser runner | `safari` | |
`quest` | browser runner | `chrome-android` | | required
`react-native` | hermes runner | `hermes` | required |
`rhino` | rhino runner | | required |
`safari` | browser runner | | required |
`samsung` | browser runner | `chrome-android` | | required

If you have no access to all required browsers / versions of browsers, use [Sauce Labs](https://saucelabs.com/), [BrowserStack](https://www.browserstack.com/) or [Cloud Browser](https://ieonchrome.com/).

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ However, I have no possibility to test `core-js` absolutely everywhere - for exa

`core-js` project provides (as [`core-js-compat`](/packages/core-js-compat) package) all required data about the necessity of `core-js` modules, entry points, and tools for work with it - it's useful for integration with tools like `babel` or `swc`. If you wanna help, you could take a look at the related section of [`CONTRIBUTING.md`](/CONTRIBUTING.md#how-to-update-core-js-compat-data). The visualization of compatibility data and the browser tests runner is available [here](http://zloirock.github.io/core-js/compat/), the example:

![compat-table](https://user-images.githubusercontent.com/2213682/180694428-856bcd0f-cab3-446f-be1a-2f669614dcc0.png)
![compat-table](https://user-images.githubusercontent.com/2213682/202867481-69d28cd6-9e1a-453b-8875-39a5bf92eac3.png)

## Features:[](#index)
[*CommonJS entry points:*](#commonjs-api)
Expand Down
47 changes: 25 additions & 22 deletions packages/core-js-compat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,31 @@ console.log(targets);
```js
// browserslist query:
'defaults, not IE 11, maintained node versions'
// object:
// object (sure, all those fields optional):
{
android: '4.0', // Android WebView version
bun: '0.1.2', // Bun version
chrome: '38', // Chrome version
deno: '1.12', // Deno version
edge: '13', // Edge version
electron: '5.0', // Electron framework version
firefox: '15', // Firefox version
hermes: '0.11', // Hermes version
ie: '8', // Internet Explorer version
ios: '13.0', // iOS Safari version
node: 'current', // NodeJS version, you can use 'current' for set it to currently used
oculus: '5.0', // Oculus Browser version
opera: '12', // Opera version
opera_mobile: '7', // Opera Mobile version
phantom: '1.9', // PhantomJS headless browser version
rhino: '1.7.13', // Rhino engine version
safari: '14.0', // Safari version
samsung: '14.0', // Samsung Internet version
esmodules: true, // That option set target to minimum supporting ES Modules versions of all browsers
browsers: '> 0.25%', // Browserslist query or object with target browsers
android: '4.0', // Android WebView version
bun: '0.1.2', // Bun version
chrome: '38', // Chrome version
'chrome-android': '18', // Chrome for Android version
deno: '1.12', // Deno version
edge: '13', // Edge version
electron: '5.0', // Electron framework version
firefox: '15', // Firefox version
'firefox-android': '4', // Firefox for Android version
hermes: '0.11', // Hermes version
ie: '8', // Internet Explorer version
ios: '13.0', // iOS Safari version
node: 'current', // NodeJS version, you can use 'current' for set it to currently used
opera: '12', // Opera version
'opera-android': '7', // Opera for Android version
phantom: '1.9', // PhantomJS headless browser version
quest: '5.0', // Meta Quest Browser version
'react-native': '0.70', // React Native version (default Hermes engine)
rhino: '1.7.13', // Rhino engine version
safari: '14.0', // Safari version
samsung: '14.0', // Samsung Internet version
esmodules: true, // That option set target to minimum supporting ES Modules versions of all browsers
browsers: '> 0.25%', // Browserslist query or object with target browsers
}
```

Expand Down Expand Up @@ -126,4 +129,4 @@ require('core-js-compat').getModulesListForTargetVersion('3.26'); // => Array<Mo

If you wanna help to improve this data, you could take a look at the related section of [`CONTRIBUTING.md`](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md#how-to-update-core-js-compat-data). The visualization of compatibility data and the browser tests runner is available [here](http://zloirock.github.io/core-js/compat/), the example:

![compat-table](https://user-images.githubusercontent.com/2213682/173199354-1f3aeb83-7231-46b2-8a14-a9d47ce3ae45.png)
![compat-table](https://user-images.githubusercontent.com/2213682/202867481-69d28cd6-9e1a-453b-8875-39a5bf92eac3.png)
48 changes: 33 additions & 15 deletions packages/core-js-compat/src/mapping.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,30 @@ export default {
[106, '21.0'],
[108, '22.0'],
],
// https://github.com/mdn/browser-compat-data/blob/main/browsers/opera.json
ChromeToOpera(chrome) {
return chrome <= 28 ? 15
: chrome <= 82 ? chrome - 13
: chrome - 14;
},
ChromeToAndroid: [
[9, '3.0'],
[12, '4.0'],
[30, '4.4'],
[33, '4.4.3'],
],
// https://github.com/mdn/browser-compat-data/blob/main/browsers/chrome_android.json
// https://github.com/mdn/browser-compat-data/blob/main/docs/matching-browser-releases/index.md#version-numbers-for-chrome-for-android
ChromeToChromeAndroid(chrome) {
return chrome <= 18 ? 18
: chrome <= 25 ? 25
: chrome;
},
// https://medium.com/samsung-internet-dev
// https://github.com/mdn/browser-compat-data/blob/main/browsers/samsunginternet_android.json
// https://en.wikipedia.org/wiki/Samsung_Internet#History
ChromeToSamsung: [
// https://github.com/mdn/browser-compat-data/blob/main/docs/matching-browser-releases/index.md#samsung-internet
ChromeAndroidToSamsung: [
[18, '1.0'],
[28, '1.5'],
[34, '2.0'],
Expand All @@ -156,14 +176,8 @@ export default {
[99, '18.0'],
[102, '19.0'],
],
// https://github.com/mdn/browser-compat-data/blob/main/browsers/opera.json
ChromeToOpera(chrome) {
return chrome <= 28 ? 15
: chrome <= 82 ? chrome - 13
: chrome - 14;
},
// https://github.com/mdn/browser-compat-data/blob/main/browsers/opera_android.json
ChromeToOperaMobile: [
ChromeAndroidToOperaAndroid: [
[59, 43],
[60, 44],
[61, 45],
Expand Down Expand Up @@ -195,16 +209,11 @@ export default {
[104, 71],
[106, 72],
],
ChromeToAndroid: [
[9, '3.0'],
[12, '4.0'],
[30, '4.4'],
[33, '4.4.3'],
],
// https://developer.oculus.com/documentation/web/browser-release-notes/
// Need to find another data source since release notes are not available for new versions.
// https://github.com/mdn/browser-compat-data/blob/main/browsers/oculus.json
AndroidToOculus: [
// https://whatmyuseragent.com/browser/oc/oculus-browser
ChromeAndroidToQuest: [
[57, '3.0'],
[61, '4.0'],
[66, '5.0'],
Expand All @@ -228,6 +237,10 @@ export default {
[104, '23.0'],
[106, '24.0'],
],
// https://github.com/mdn/browser-compat-data/blob/main/browsers/opera.json
FirefoxToFirefoxAndroid(firefox) {
return firefox <= 4 ? 4 : firefox;
},
// This is the base data. Since it have no direct Safari equals by the
// WebKit / JavaScriptCore version, don't use mapping for future releases.
// https://github.com/oven-sh/bun/issues/396
Expand Down Expand Up @@ -263,4 +276,9 @@ export default {
['4.1', '1.9'],
['6.0', '2.0'],
],
// This is the base data. Since it have no direct Hermes version equals,
// don't use mapping for future releases.
HermesToReactNative: [
['0.11', '0.69'],
],
};
18 changes: 13 additions & 5 deletions packages/core-js-compat/targets-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,37 @@ const { compare, has } = require('./helpers');
const external = require('./external');

const aliases = new Map([
['and_chr', 'chrome'],
['and_ff', 'firefox'],
['and_chr', 'chrome-android'],
['and_ff', 'firefox-android'],
['ie_mob', 'ie'],
['ios_saf', 'ios'],
['op_mob', 'opera_mobile'],
['oculus', 'quest'],
['op_mob', 'opera-android'],
// TODO: Remove from `core-js@4`
['opera_mobile', 'opera-android'],
['react', 'react-native'],
['reactnative', 'react-native'],
]);

const validTargets = new Set([
'android',
'bun',
'chrome',
'chrome-android',
'deno',
'edge',
'electron',
'firefox',
'firefox-android',
'hermes',
'ie',
'ios',
'node',
'oculus',
'opera',
'opera_mobile',
'opera-android',
'phantom',
'quest',
'react-native',
'rhino',
'safari',
'samsung',
Expand Down
42 changes: 26 additions & 16 deletions scripts/build-compat/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for (const scope of [data, external]) {

function map(mappingKey) {
const [engine, targetKey] = mappingKey.split('To')
.map(it => it.replace(/([a-z])([A-Z])/, (_, a, b) => `${ a }_${ b }`).toLowerCase());
.map(it => it.replace(/([a-z])([A-Z])/, (_, a, b) => `${ a }-${ b }`).toLowerCase());
const version = module[engine];
if (!version || has(module, targetKey)) return;
const mapping = mappings[mappingKey];
Expand All @@ -27,15 +27,9 @@ for (const scope of [data, external]) {
}
}

map('ChromeToAndroid');
if (!has(module, 'android') && chrome) {
module.android = String(Math.max(chrome, 37));
}
if (key.startsWith('es')) {
if (/^(?:es|esnext)\./.test(key)) {
map('ChromeToDeno');
}
if (/^(?:es|esnext|web)\./.test(key)) {
map('ChromeToElectron');
map('ChromeToNode');
}
if (!has(module, 'edge')) {
if (ie && !key.includes('immediate')) {
Expand All @@ -44,25 +38,41 @@ for (const scope of [data, external]) {
module.edge = String(Math.max(chrome, 79));
}
}
if (key.startsWith('es')) {
map('ChromeToNode');
if (/^(?:es|esnext|web)\./.test(key)) {
map('ChromeToElectron');
}
map('ChromeToOpera');
if (!has(module, 'opera_mobile') && module.opera <= 42) {
module.opera_mobile = module.opera;
map('ChromeToChromeAndroid');
map('ChromeToAndroid');
if (!has(module, 'android') && module['chrome-android']) {
// https://github.com/mdn/browser-compat-data/blob/main/docs/matching-browser-releases/index.md#version-numbers-for-features-in-android-webview
module.android = String(Math.max(module['chrome-android'], 37));
}
if (!has(module, 'opera-android') && module.opera <= 42) {
module['opera-android'] = module.opera;
} else {
map('ChromeToOperaMobile');
map('ChromeAndroidToOperaAndroid');
}
// TODO: Remove from `core-js@4`
if (has(module, 'opera-android')) {
module.opera_mobile = module['opera-android'];
}
map('ChromeAndroidToQuest');
// TODO: Remove from `core-js@4`
if (has(module, 'quest')) {
module.oculus = module.quest;
}
map('ChromeToSamsung');
map('AndroidToOculus');
map('ChromeAndroidToSamsung');
if (/^(?:es|esnext)\./.test(key)) {
map('SafariToBun');
}
map('FirefoxToFirefoxAndroid');
map('SafariToIOS');
if (!has(module, 'ios') && has(module, 'safari') && semver(module.safari).major >= 15) {
module.ios = module.safari;
}
map('SafariToPhantom');
map('HermesToReactNative');

for (const [engine, version] of Object.entries(module)) {
if (!version) delete module[engine];
Expand Down
8 changes: 4 additions & 4 deletions scripts/check-compat-data-mapping.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const [
deno,
oculus,
opera,
operaMobile,
operaAndroid,
safari,
ios,
samsung,
Expand All @@ -66,10 +66,10 @@ const [
assert(modernV8ToChrome(v8) <= latest(mapping.ChromeToNode)[0], 'NodeJS');
assert(latest(Object.entries(electron))[0] <= latest(mapping.ChromeToElectron)[0], 'Electron');
assert(modernV8ToChrome(deno.engine) <= latest(mapping.ChromeToDeno)[0], 'Deno');
assert(oculus.engine <= latest(mapping.AndroidToOculus)[0], 'Oculus');
assert(oculus.engine <= latest(mapping.ChromeAndroidToQuest)[0], 'Meta Quest');
assert(opera.version == mapping.ChromeToOpera(opera.engine), 'Opera');
assert(operaMobile.engine <= latest(mapping.ChromeToOperaMobile)[0], 'Opera Mobile');
assert(operaAndroid.engine <= latest(mapping.ChromeAndroidToOperaAndroid)[0], 'Opera for Android');
assert(ios.version === Object.entries(safari).find(([, { engine_version: engine }]) => engine === ios.engine)[0], 'iOS Safari');
assert(samsung.engine <= latest(mapping.ChromeToSamsung)[0], 'Samsung Internet');
assert(samsung.engine <= latest(mapping.ChromeAndroidToSamsung)[0], 'Samsung Internet');

if (updated) echo(chalk.green('updates of compat data mapping not required'));
Loading

0 comments on commit d732ad5

Please sign in to comment.