babel/packages/babel-compat-data/scripts/build-modules-support.js
Huáng Jùnliàng b54a946048 chore: map mobile browser data to their desktop version (#10814)
* chore: map mobile browser data to their desktop version

* chore: skip android until upstream support is resolved

* Revert "chore: skip android until upstream support is resolved"

This reverts commit 436e9af8297b284a426b5a3240e2a550a20fca86.

* Update fixtures

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-01-24 22:40:11 +01:00

41 lines
1.2 KiB
JavaScript

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 browserNameMap = {
and_chr: "chrome",
and_ff: "firefox",
android: "chrome", // map to chrome here as Android WebView 61 is Chromium-based
op_mob: "opera",
};
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];
}
});
const dataPath = path.join(__dirname, "../data/built-in-modules.json");
const data = {
"es6.module": allowedBrowsers,
};
fs.writeFileSync(dataPath, `${JSON.stringify(data, null, 2)}\n`);