Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Fill data with electron as a target. #229

Merged
merged 11 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 160 additions & 80 deletions data/built-ins.json

Large diffs are not rendered by default.

66 changes: 44 additions & 22 deletions data/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 34
"opera": 34,
"electron": 0.36
},
"transform-es2015-block-scoped-functions": {
"chrome": 41,
Expand All @@ -16,7 +17,8 @@
"node": 4,
"ie": 11,
"ios": 10,
"opera": 28
"opera": 28,
"electron": 0.24
},
"transform-es2015-block-scoping": {
"chrome": 49,
Expand All @@ -25,7 +27,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
"opera": 36,
"electron": 1
},
"transform-es2015-classes": {
"chrome": 46,
Expand All @@ -34,7 +37,8 @@
"safari": 10,
"node": 5,
"ios": 10,
"opera": 33
"opera": 33,
"electron": 0.36
},
"transform-es2015-computed-properties": {
"chrome": 44,
Expand All @@ -43,7 +47,8 @@
"safari": 8,
"node": 4,
"ios": 8,
"opera": 31
"opera": 31,
"electron": 0.31
},
"check-es2015-constants": {
"chrome": 49,
Expand All @@ -52,7 +57,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
"opera": 36,
"electron": 1
},
"transform-es2015-destructuring": {
"chrome": 51,
Expand All @@ -61,7 +67,8 @@
"safari": 10,
"node": 6.5,
"ios": 10,
"opera": 38
"opera": 38,
"electron": 1.2
},
"transform-es2015-duplicate-keys": {
"chrome": 42,
Expand All @@ -70,7 +77,8 @@
"safari": 9,
"node": 4,
"ios": 9,
"opera": 29
"opera": 29,
"electron": 0.27
},
"transform-es2015-for-of": {
"chrome": 51,
Expand All @@ -79,15 +87,17 @@
"safari": 10,
"node": 6.5,
"ios": 10,
"opera": 38
"opera": 38,
"electron": 1.2
},
"transform-es2015-function-name": {
"chrome": 51,
"firefox": 53,
"safari": 10,
"node": 6.5,
"ios": 10,
"opera": 38
"opera": 38,
"electron": 1.2
},
"transform-es2015-literals": {
"chrome": 44,
Expand All @@ -96,7 +106,8 @@
"safari": 9,
"node": 4,
"ios": 9,
"opera": 31
"opera": 31,
"electron": 0.31
},
"transform-es2015-object-super": {
"chrome": 46,
Expand All @@ -105,7 +116,8 @@
"safari": 10,
"node": 5,
"ios": 10,
"opera": 33
"opera": 33,
"electron": 0.36
},
"transform-es2015-parameters": {
"chrome": 49,
Expand All @@ -114,7 +126,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
"opera": 36,
"electron": 1
},
"transform-es2015-shorthand-properties": {
"chrome": 43,
Expand All @@ -123,7 +136,8 @@
"safari": 9,
"node": 4,
"ios": 9,
"opera": 30
"opera": 30,
"electron": 0.29
},
"transform-es2015-spread": {
"chrome": 46,
Expand All @@ -132,7 +146,8 @@
"safari": 10,
"node": 5,
"ios": 10,
"opera": 33
"opera": 33,
"electron": 0.36
},
"transform-es2015-sticky-regex": {
"chrome": 49,
Expand All @@ -141,7 +156,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
"opera": 36,
"electron": 1
},
"transform-es2015-template-literals": {
"chrome": 41,
Expand All @@ -150,7 +166,8 @@
"safari": 9,
"node": 4,
"ios": 9,
"opera": 28
"opera": 28,
"electron": 0.24
},
"transform-es2015-typeof-symbol": {
"chrome": 38,
Expand All @@ -160,7 +177,8 @@
"node": 0.12,
"android": 5.1,
"ios": 9,
"opera": 25
"opera": 25,
"electron": 0.2
},
"transform-es2015-unicode-regex": {
"chrome": 50,
Expand All @@ -169,7 +187,8 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 37
"opera": 37,
"electron": 1.1
},
"transform-regenerator": {
"chrome": 50,
Expand All @@ -178,22 +197,25 @@
"safari": 10,
"node": 6,
"ios": 10,
"opera": 37
"opera": 37,
"electron": 1.1
},
"transform-exponentiation-operator": {
"chrome": 52,
"edge": 14,
"firefox": 52,
"safari": 10.1,
"node": 7,
"opera": 39
"opera": 39,
"electron": 1.3
},
"transform-async-to-generator": {
"chrome": 55,
"firefox": 52,
"safari": 10.1,
"node": 7.6,
"opera": 42
"opera": 42,
"electron": 1.6
},
"syntax-trailing-function-commas": {
"chrome": 58,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"babel-plugin-transform-exponentiation-operator": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"browserslist": "^1.4.0",
"electron-to-chromium": "^1.2.6",
"invariant": "^2.2.2"
},
"devDependencies": {
Expand All @@ -71,6 +70,7 @@
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"nyc": "^10.1.2",
"electron-to-chromium": "^1.2.8",
"rimraf": "^2.6.1"
},
"babel": {
Expand Down
29 changes: 29 additions & 0 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,34 @@ const flatten = require("lodash/flatten");
const flattenDeep = require("lodash/flattenDeep");
const mapValues = require("lodash/mapValues");
const pickBy = require("lodash/pickBy");
const electronToChromiumVersions = require("electron-to-chromium").versions;
const pluginFeatures = require("../data/plugin-features");
const builtInFeatures = require("../data/built-in-features");

const electronToChromiumKeys = Object.keys(electronToChromiumVersions).reverse();

const chromiumToElectronMap = electronToChromiumKeys.reduce(
(all, electron) => {
all[electronToChromiumVersions[electron]] = +electron;
return all;
}
, {});
const chromiumToElectronVersions = Object.keys(chromiumToElectronMap);

const findClosestElectronVersion = (targetVersion) => {
const chromiumVersionsLength = chromiumToElectronVersions.length;
const maxChromium = +chromiumToElectronVersions[chromiumVersionsLength - 1];
if (targetVersion > maxChromium) return null;

const closestChrome = chromiumToElectronVersions.find(
(version) => targetVersion <= version
);
return chromiumToElectronMap[closestChrome];
};

const chromiumToElectron = (chromium) =>
chromiumToElectronMap[chromium] || findClosestElectronVersion(chromium);

const renameTests = (tests, getName) =>
tests.map((test) => Object.assign({}, test, { name: getName(test.name) }));

Expand Down Expand Up @@ -219,6 +244,10 @@ const generateData = (environments, features) => {
} else if (plugin.chrome === 5) {
plugin.opera = 12;
}
const electronVersion = chromiumToElectron(plugin.chrome);
if (electronVersion) {
plugin.electron = electronVersion;
}
}

return plugin;
Expand Down
13 changes: 1 addition & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import browserslist from "browserslist";
import builtInsList from "../data/built-ins.json";
import { defaultWebIncludes } from "./default-includes";
import moduleTransformations from "./module-transformations";
import normalizeOptions, { getElectronChromeVersion } from "./normalize-options.js";
import normalizeOptions from "./normalize-options.js";
import pluginList from "../data/plugins.json";
import transformPolyfillRequirePlugin from "./transform-polyfill-require-plugin";

Expand Down Expand Up @@ -104,17 +104,6 @@ export const getTargets = (targets = {}) => {
delete targetOpts.uglify;
}

// Replace Electron target with its Chrome equivalent
if (targetOpts.electron) {
const electronChromeVersion = getElectronChromeVersion(targetOpts.electron);

targetOpts.chrome = targetOpts.chrome
? Math.min(targetOpts.chrome, electronChromeVersion)
: electronChromeVersion;

delete targetOpts.electron;
}

const browserOpts = targetOpts.browsers;
if (isBrowsersQueryValid(browserOpts)) {
const queryBrowsers = getLowestVersions(browserslist(browserOpts));
Expand Down
12 changes: 0 additions & 12 deletions src/normalize-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import invariant from "invariant";
import { electronToChromium } from "electron-to-chromium";
import builtInsList from "../data/built-ins.json";
import { defaultWebIncludes } from "./default-includes";
import moduleTransformations from "./module-transformations";
Expand Down Expand Up @@ -70,17 +69,6 @@ export const validateModulesOption = (modulesOpt = "commonjs") => {
return modulesOpt;
};

export const getElectronChromeVersion = (electronVersion) => {
const electronChromeVersion = parseInt(electronToChromium(electronVersion), 10);

invariant(
!!electronChromeVersion,
`Electron version ${electronVersion} is either too old or too new`
);

return electronChromeVersion;
};

export default function normalizeOptions(opts) {
// TODO: remove whitelist in favor of include in next major
if (opts.whitelist && !hasBeenWarned) {
Expand Down
11 changes: 11 additions & 0 deletions test/debug-fixtures/electron/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
["../../lib", {
"debug": true,
"targets": {
"electron": 0.36
},
"useBuiltIns": true
}]
]
}
Loading