forked from babel/babel
/
build-bugfixes-targets.js
78 lines (62 loc) 路 2.07 KB
/
build-bugfixes-targets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
// NOTE: This script must be run _after_ build-data.js
const path = require("path");
const { addElectronSupportFromChromium } = require("./chromium-to-electron");
const {
getLowestImplementedVersion,
environments,
writeFile,
} = require("./utils-build-data");
const data = require("./data/plugin-bugfixes");
const pluginFeatures = require("./data/plugin-features");
const generatedTargets = {};
const overlappingPlugins = {};
const allReplacedFeatures = {};
const has = Function.call.bind(Object.hasOwnProperty);
for (const [plugin, { replaces, features }] of Object.entries(data)) {
if (!has(overlappingPlugins, replaces)) {
overlappingPlugins[replaces] = [];
generatedTargets[replaces] = {};
allReplacedFeatures[replaces] = [];
}
generatedTargets[plugin] = {};
allReplacedFeatures[replaces].push(...features);
overlappingPlugins[replaces].push(plugin);
for (const env of environments) {
const supportedWithBugfix = getLowestImplementedVersion({ features }, env);
if (supportedWithBugfix) {
generatedTargets[plugin][env] = supportedWithBugfix;
}
}
addElectronSupportFromChromium(generatedTargets[plugin]);
}
for (const [replaced, features] of Object.entries(allReplacedFeatures)) {
let replacedFeatures = pluginFeatures[replaced];
if (
typeof replacedFeatures === "object" &&
!Array.isArray(replacedFeatures)
) {
replacedFeatures = replacedFeatures.features;
}
for (const env of environments) {
const stillNotSupported = getLowestImplementedVersion(
{ features: replacedFeatures },
env,
name => features.some(feat => name.includes(feat))
);
if (stillNotSupported) {
generatedTargets[replaced][env] = stillNotSupported;
}
}
addElectronSupportFromChromium(generatedTargets[replaced]);
}
for (const [filename, data] of [
["plugin-bugfixes", generatedTargets],
["overlapping-plugins", overlappingPlugins],
]) {
const dataPath = path.join(__dirname, `../data/${filename}.json`);
if (!writeFile(data, dataPath, filename)) {
process.exitCode = 1;
break;
}
}