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
- Loading branch information
Showing
7 changed files
with
108 additions
and
95 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,15 @@ | ||
{ | ||
"es6.module": { | ||
"chrome": "61", | ||
"and_chr": "61", | ||
"edge": "16", | ||
"firefox": "60", | ||
"chrome": "61", | ||
"and_ff": "60", | ||
"node": "13.2.0", | ||
"opera": "47", | ||
"op_mob": "44", | ||
"safari": "10.1", | ||
"opera": "48", | ||
"ios_saf": "10.3", | ||
"android": "61", | ||
"op_mob": "48", | ||
"and_chr": "61", | ||
"and_ff": "60", | ||
"samsung": "8.2" | ||
} | ||
} |
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
69 changes: 41 additions & 28 deletions
69
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,53 @@ | ||
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 = { | ||
webview_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 | ||
} | ||
}); | ||
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`); |
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
Oops, something went wrong.