Make env preset build-data scripts reproducible (#8299)

This commit is contained in:
Ryan Tsao 2018-07-10 18:43:45 -07:00 committed by Brian Ng
parent 301db1b921
commit f2fd9e982e
2 changed files with 26 additions and 66 deletions

View File

@ -60,8 +60,8 @@
"@babel/core": "7.0.0-beta.52",
"@babel/helper-fixtures": "7.0.0-beta.52",
"@babel/helper-plugin-test-runner": "7.0.0-beta.52",
"caniuse-db": "1.0.30000851",
"compat-table": "kangax/compat-table#90d02e486227d179d2ce9b850dbb3f9846443cab",
"electron-to-chromium": "^1.3.27",
"request": "^2.83.0"
"electron-to-chromium": "1.3.48"
}
}

View File

@ -1,77 +1,37 @@
const path = require("path");
const fs = require("fs");
const request = require("request");
// This mapping represents browsers who have shipped ES Modules Support.
// For more information, checkout the specifications:
// * https://www.ecma-international.org/ecma-262/6.0/#sec-modules
// * https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type
const lastKnown = {
chrome: 61,
safari: 10.1,
ios_saf: 10.3,
edge: 16,
};
const moduleSupport = require("caniuse-db/features-json/es6-module.json");
const acceptedWithCaveats = {
safari: true,
ios_saf: true,
};
function input() {
return new Promise(function(resolve, reject) {
request(
"https://raw.githubusercontent.com/Fyrd/caniuse/master/features-json/es6-module.json",
function(error, response, body) {
if (error || response.statusCode !== 200) {
return reject(
new Error(
`Error retrieving es6-module.json. ${
error ? error : `statusCode=${response.statusCode}`
}`
)
);
}
const { stats } = moduleSupport;
try {
const { stats } = JSON.parse(body);
const allowedBrowsers = {};
const allowedBrowsers = {};
Object.keys(stats).forEach(browser => {
if (browser !== "and_chr") {
const browserVersions = stats[browser];
const allowedVersions = Object.keys(browserVersions)
.filter(value => {
return acceptedWithCaveats[browser]
? browserVersions[value][0] === "a"
: browserVersions[value] === "y";
})
.sort((a, b) => a - b);
Object.keys(stats).forEach(browser => {
if (browser !== "and_chr") {
const browserVersions = stats[browser];
const allowedVersions = Object.keys(browserVersions)
.filter(value => {
return acceptedWithCaveats[browser]
? browserVersions[value][0] === "a"
: browserVersions[value] === "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];
}
}
});
if (allowedVersions[0] !== undefined) {
// Handle cases where caniuse specifies version as: "11.0-11.2"
allowedBrowsers[browser] = allowedVersions[0].split("-")[0];
}
}
});
resolve(allowedBrowsers);
} catch (error) {
return reject(new Error(`Error parsing es6-module.json.`));
}
}
);
});
}
function output(minVersions) {
const dataPath = path.join(__dirname, "../data/built-in-modules.json");
const data = {
"es6.module": minVersions,
};
fs.writeFileSync(dataPath, `${JSON.stringify(data, null, 2)}\n`);
}
Promise.resolve(input())
.then(minVersions => output(minVersions))
.catch(output(lastKnown));
const dataPath = path.join(__dirname, "../data/built-in-modules.json");
const data = {
"es6.module": allowedBrowsers,
};
fs.writeFileSync(dataPath, `${JSON.stringify(data, null, 2)}\n`);