Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace caniuse-db by mdn-browser-compat-data (#11838)
* refactor: replace caniuse-db by mdn-browser-compat-data * fix broken test
- Loading branch information
Showing
9 changed files
with
145 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"es6.module": { | ||
"chrome": "61", | ||
"and_chr": "61", | ||
"edge": "16", | ||
"firefox": "60", | ||
"chrome": "61", | ||
"safari": "10.1", | ||
"and_ff": "60", | ||
"node": "13.2.0", | ||
"opera": "48", | ||
"ios_saf": "10.3", | ||
"android": "61", | ||
"op_mob": "48", | ||
"and_chr": "61", | ||
"and_ff": "60", | ||
"samsung": "8.2" | ||
"safari": "10.1", | ||
"ios_saf": "10.3", | ||
"samsung": "8.2", | ||
"android": "61" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 47 additions & 28 deletions
75
packages/babel-compat-data/scripts/build-modules-support.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
const moduleSupport = require("caniuse-db/features-json/es6-module.json"); | ||
|
||
const acceptedWithCaveats = new Set(["safari", "ios_saf"]); | ||
const compatData = require("mdn-browser-compat-data").javascript; | ||
|
||
// Map mdn-browser-compat-data to browserslist browser names | ||
const browserNameMap = { | ||
and_chr: "chrome", | ||
and_ff: "firefox", | ||
android: "chrome", // map to chrome here as Android WebView 61 is Chromium-based | ||
op_mob: "opera", | ||
chrome_android: "and_chr", | ||
firefox_android: "and_ff", | ||
safari_ios: "ios_saf", | ||
nodejs: "node", | ||
webview_android: "android", | ||
opera_android: "op_mob", | ||
samsunginternet_android: "samsung", | ||
}; | ||
|
||
const browserSupportMap = { | ||
android: "chrome_android", // map to chrome here as Android WebView 61 is Chromium-based | ||
}; | ||
const { stats } = moduleSupport; | ||
|
||
const allowedBrowsers = {}; | ||
|
||
Object.keys(stats).forEach(browser => { | ||
const browserName = browserNameMap[browser] || browser; | ||
const browserVersions = stats[browserName]; | ||
const allowedVersions = Object.keys(browserVersions) | ||
.filter(value => { | ||
// Edge 16/17 are marked as "y #6" | ||
return acceptedWithCaveats.has(browserName) | ||
? browserVersions[value][0] === "a" | ||
: browserVersions[value].startsWith("y"); | ||
}) | ||
.sort((a, b) => a - b); | ||
|
||
if (allowedVersions[0] !== undefined) { | ||
// Handle cases where caniuse specifies version as: "11.0-11.2" | ||
allowedBrowsers[browser] = allowedVersions[0].split("-")[0]; | ||
|
||
function browserVersion(browser, version_added) { | ||
if (browser === "samsunginternet_android" && version_added === "8.0") { | ||
return "8.2"; // samsung 8.0 is not defined in browserslist | ||
} | ||
}); | ||
// fixme: preset-env maps opera_android as opera, this is incorrect as they have different engine mappings | ||
// see https://github.com/mdn/browser-compat-data/blob/master/browsers/opera_android.json | ||
if (browser === "opera_android" && version_added === "45") { | ||
return "48"; | ||
} | ||
return version_added; | ||
} | ||
|
||
function process(source) { | ||
const stats = source.__compat.support; | ||
const allowedBrowsers = {}; | ||
|
||
Object.keys(stats).forEach(browser => { | ||
const browserName = browserNameMap[browser] ?? browser; | ||
let browserSupport = stats[browserSupportMap[browserName] ?? browser]; | ||
if (Array.isArray(browserSupport)) { | ||
browserSupport = browserSupport[0]; // The first item is the most progressive support | ||
} | ||
if (browserSupport.version_added && !browserSupport.flags) { | ||
allowedBrowsers[browserName] = browserVersion( | ||
browser, | ||
browserSupport.version_added | ||
); | ||
} | ||
}); | ||
|
||
return allowedBrowsers; | ||
} | ||
|
||
const dataPath = path.join(__dirname, "../data/native-modules.json"); | ||
const data = { | ||
"es6.module": allowedBrowsers, | ||
"es6.module": process(compatData.statements.export), | ||
}; | ||
fs.writeFileSync(dataPath, `${JSON.stringify(data, null, 2)}\n`); | ||
exports.process = process; |
59 changes: 59 additions & 0 deletions
59
packages/babel-helper-compilation-targets/test/__snapshots__/targets-parser.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getTargets esmodules returns browser supporting modules and keyed browser overrides 1`] = ` | ||
Object { | ||
"android": "61.0.0", | ||
"chrome": "61.0.0", | ||
"edge": "16.0.0", | ||
"firefox": "60.0.0", | ||
"ie": "11.0.0", | ||
"ios": "10.3.0", | ||
"node": "13.2.0", | ||
"opera": "48.0.0", | ||
"safari": "10.1.0", | ||
"samsung": "8.2.0", | ||
} | ||
`; | ||
|
||
exports[`getTargets esmodules returns browser supporting modules and keyed browser overrides, ignoring browsers field 1`] = ` | ||
Object { | ||
"android": "61.0.0", | ||
"chrome": "61.0.0", | ||
"edge": "16.0.0", | ||
"firefox": "60.0.0", | ||
"ie": "11.0.0", | ||
"ios": "10.3.0", | ||
"node": "13.2.0", | ||
"opera": "48.0.0", | ||
"safari": "10.1.0", | ||
"samsung": "8.2.0", | ||
} | ||
`; | ||
|
||
exports[`getTargets esmodules returns browsers supporting modules 1`] = ` | ||
Object { | ||
"android": "61.0.0", | ||
"chrome": "61.0.0", | ||
"edge": "16.0.0", | ||
"firefox": "60.0.0", | ||
"ios": "10.3.0", | ||
"node": "13.2.0", | ||
"opera": "48.0.0", | ||
"safari": "10.1.0", | ||
"samsung": "8.2.0", | ||
} | ||
`; | ||
|
||
exports[`getTargets esmodules returns browsers supporting modules, ignoring browsers key 1`] = ` | ||
Object { | ||
"android": "61.0.0", | ||
"chrome": "61.0.0", | ||
"edge": "16.0.0", | ||
"firefox": "60.0.0", | ||
"ios": "10.3.0", | ||
"node": "13.2.0", | ||
"opera": "48.0.0", | ||
"safari": "10.1.0", | ||
"samsung": "8.2.0", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters