From c6ebef444f2a455c13414aeb8c211ad24643eb69 Mon Sep 17 00:00:00 2001 From: kilian Date: Mon, 16 Jan 2017 22:52:44 +0100 Subject: [PATCH 1/7] Replace manual electron-to-chromium list and function with external library --- data/electron-to-chromium.js | 10 ---------- package.json | 3 ++- src/index.js | 28 +++++----------------------- 3 files changed, 7 insertions(+), 34 deletions(-) delete mode 100644 data/electron-to-chromium.js diff --git a/data/electron-to-chromium.js b/data/electron-to-chromium.js deleted file mode 100644 index 7e26adf3..00000000 --- a/data/electron-to-chromium.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - "1.5": 54, - "1.4": 53, - "1.3": 52, - "1.2": 51, - "1.1": 50, - "1.0": 50, - "0.37": 49, - "0.36": 47, -}; \ No newline at end of file diff --git a/package.json b/package.json index aaf02e4d..7d43418c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "babel-plugin-transform-exponentiation-operator": "^6.8.0", "babel-plugin-transform-regenerator": "^6.6.0", "browserslist": "^1.4.0", - "invariant": "^2.2.2" + "invariant": "^2.2.2", + "electron-to-chromium": "^1.1.0" }, "devDependencies": { "babel-cli": "^6.11.4", diff --git a/src/index.js b/src/index.js index 4a271b57..477acdda 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,7 @@ import browserslist from "browserslist"; - import builtInsList from "../data/built-ins.json"; import defaultInclude from "./default-includes"; -import electronToChromium from "../data/electron-to-chromium"; +import e2c from "electron-to-chromium"; import moduleTransformations from "./module-transformations"; import normalizeOptions from "./normalize-options.js"; import pluginList from "../data/plugins.json"; @@ -82,26 +81,6 @@ export const getCurrentNodeVersion = () => { return parseFloat(process.versions.node); }; -export const electronVersionToChromeVersion = (semverVer) => { - semverVer = String(semverVer); - - if (semverVer === "1") { - semverVer = "1.0"; - } - - const m = semverVer.match(/^(\d+\.\d+)/); - if (!m) { - throw new Error("Electron version must be a semver version"); - } - - const result = electronToChromium[m[1]]; - if (!result) { - throw new Error(`Electron version ${m[1]} is either too old or too new`); - } - - return result; -}; - const _extends = Object.assign || function (target) { for (let i = 1; i < arguments.length; i++) { const source = arguments[i]; @@ -124,7 +103,10 @@ export const getTargets = (targets = {}) => { // Rewrite Electron versions to their Chrome equivalents if (targetOps.electron) { - targetOps.chrome = electronVersionToChromeVersion(targetOps.electron); + targetOps.chrome = parseInt(e2c.electronToChromium(targetOps.electron), 10); + // if (!targetOps.chrome) { + // throw new Error(`Electron version ${targetOps.electron} is either too old or too new`); + // } delete targetOps.electron; } From 322f54c91b3542bad2dc7b4419696887c3e1a7b7 Mon Sep 17 00:00:00 2001 From: kilian Date: Mon, 16 Jan 2017 22:53:46 +0100 Subject: [PATCH 2/7] test fixtures for electron: Switch to electron 1.4, with known chrome version and update expected output --- test/fixtures/preset-options/electron/expected.js | 5 ++++- test/fixtures/preset-options/electron/options.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/fixtures/preset-options/electron/expected.js b/test/fixtures/preset-options/electron/expected.js index 102926c4..72f57862 100644 --- a/test/fixtures/preset-options/electron/expected.js +++ b/test/fixtures/preset-options/electron/expected.js @@ -1,3 +1,6 @@ +import "core-js/modules/es7.object.values"; +import "core-js/modules/es7.object.entries"; +import "core-js/modules/es7.object.get-own-property-descriptors"; import "core-js/modules/es7.string.pad-start"; import "core-js/modules/es7.string.pad-end"; import "core-js/modules/web.timers"; @@ -5,4 +8,4 @@ import "core-js/modules/web.immediate"; import "core-js/modules/web.dom.iterable"; -a ** b; \ No newline at end of file +a ** b; diff --git a/test/fixtures/preset-options/electron/options.json b/test/fixtures/preset-options/electron/options.json index 873cef11..26135107 100644 --- a/test/fixtures/preset-options/electron/options.json +++ b/test/fixtures/preset-options/electron/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "electron": 1.5 + "electron": "1.4" }, "modules": false, "useBuiltIns": true From 0f141a07a1599b3092baa9830966be90324c5498 Mon Sep 17 00:00:00 2001 From: kilian Date: Mon, 16 Jan 2017 22:54:12 +0100 Subject: [PATCH 3/7] update tests: electron 1.0 used chrome 49, not 50 --- test/index.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index c27e55dc..d53bd72e 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -2,7 +2,7 @@ const babelPresetEnv = require("../lib/index.js"); const assert = require("assert"); -const electronToChromiumData = require("../data/electron-to-chromium"); +const { versions: electronToChromiumData } = require("electron-to-chromium"); describe("babel-preset-env", () => { describe("getTargets", () => { @@ -26,7 +26,7 @@ describe("babel-preset-env", () => { assert.deepEqual(babelPresetEnv.getTargets({ electron: "1.0" }), { - chrome: 50 + chrome: 49 }); }); @@ -34,7 +34,7 @@ describe("babel-preset-env", () => { assert.deepEqual(babelPresetEnv.getTargets({ electron: 1.0 }), { - chrome: 50 + chrome: 49 }); }); From e4be555c915ce6c13634ac3eab846bd6a1d5722c Mon Sep 17 00:00:00 2001 From: kilian Date: Mon, 16 Jan 2017 23:01:38 +0100 Subject: [PATCH 4/7] import only the relevant function from electron-to-chromium --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 477acdda..a42c14f1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import browserslist from "browserslist"; import builtInsList from "../data/built-ins.json"; import defaultInclude from "./default-includes"; -import e2c from "electron-to-chromium"; +import { electronToChromium } from "electron-to-chromium"; import moduleTransformations from "./module-transformations"; import normalizeOptions from "./normalize-options.js"; import pluginList from "../data/plugins.json"; @@ -103,7 +103,7 @@ export const getTargets = (targets = {}) => { // Rewrite Electron versions to their Chrome equivalents if (targetOps.electron) { - targetOps.chrome = parseInt(e2c.electronToChromium(targetOps.electron), 10); + targetOps.chrome = parseInt(electronToChromium(targetOps.electron), 10); // if (!targetOps.chrome) { // throw new Error(`Electron version ${targetOps.electron} is either too old or too new`); // } From 494853ba6ca72a3b493d8b4ae273196831eb8eea Mon Sep 17 00:00:00 2001 From: kilian Date: Tue, 17 Jan 2017 20:00:52 +0100 Subject: [PATCH 5/7] electron fixtures: Use number instead of string --- test/fixtures/preset-options/electron/options.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/preset-options/electron/options.json b/test/fixtures/preset-options/electron/options.json index 26135107..281c0fd3 100644 --- a/test/fixtures/preset-options/electron/options.json +++ b/test/fixtures/preset-options/electron/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "electron": "1.4" + "electron": 1.4 }, "modules": false, "useBuiltIns": true From 8dcbff62424fd50c3a05f4cb5272641dc650bac5 Mon Sep 17 00:00:00 2001 From: kilian Date: Tue, 17 Jan 2017 20:03:17 +0100 Subject: [PATCH 6/7] If both chrome and electron are defined, choose the lower version to preserve --- src/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index a42c14f1..68cd1bbb 100644 --- a/src/index.js +++ b/src/index.js @@ -103,10 +103,18 @@ export const getTargets = (targets = {}) => { // Rewrite Electron versions to their Chrome equivalents if (targetOps.electron) { - targetOps.chrome = parseInt(electronToChromium(targetOps.electron), 10); - // if (!targetOps.chrome) { - // throw new Error(`Electron version ${targetOps.electron} is either too old or too new`); - // } + const electronChromeVersion = parseInt(electronToChromium(targetOps.electron), 10); + + if (!electronChromeVersion) { + throw new Error(`Electron version ${targetOps.electron} is either too old or too new`); + } + + if (targetOps.chrome) { + targetOps.chrome = Math.min(targetOps.chrome, electronChromeVersion); + } else { + targetOps.chrome = electronChromeVersion; + } + delete targetOps.electron; } From b45923b47619078ce4694b343e85b146e08f7b87 Mon Sep 17 00:00:00 2001 From: kilian Date: Wed, 18 Jan 2017 20:14:47 +0100 Subject: [PATCH 7/7] Add to test cases to verify correct handling of chrome number --- test/index.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index d53bd72e..6dcfc0b8 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -38,6 +38,25 @@ describe("babel-preset-env", () => { }); }); + + it("should preserve lower Chrome number if Electron version is more recent", function() { + assert.deepEqual(babelPresetEnv.getTargets({ + electron: 1.4, + chrome: 50 + }), { + chrome: 50 + }); + }); + + it("should overwrite Chrome number if Electron version is older", function() { + assert.deepEqual(babelPresetEnv.getTargets({ + electron: 1.0, + chrome: 50 + }), { + chrome: 49 + }); + }); + Object.keys(electronToChromiumData).forEach((electronVersion) => { it(`"should work for Electron: ${electronVersion}`, function() { assert.deepEqual(babelPresetEnv.getTargets({