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

Use external Electron to Chromium library #144

Merged
merged 7 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions data/electron-to-chromium.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 13 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 { electronToChromium } from "electron-to-chromium";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options.js";
import pluginList from "../data/plugins.json";
Expand Down Expand Up @@ -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];
Expand All @@ -124,7 +103,18 @@ export const getTargets = (targets = {}) => {

// Rewrite Electron versions to their Chrome equivalents
if (targetOps.electron) {
targetOps.chrome = electronVersionToChromeVersion(targetOps.electron);
const electronChromeVersion = parseInt(electronToChromium(targetOps.electron), 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think parseInt(a, 10); is necessary anymore in ES5? Can remove later


if (!electronChromeVersion) {
throw new Error(`Electron version ${targetOps.electron} is either too old or too new`);
}

if (targetOps.chrome) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right! will add it tonight.

targetOps.chrome = Math.min(targetOps.chrome, electronChromeVersion);
} else {
targetOps.chrome = electronChromeVersion;
}

delete targetOps.electron;
}

Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/preset-options/electron/expected.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";


a ** b;
a ** b;
2 changes: 1 addition & 1 deletion test/fixtures/preset-options/electron/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["../../../../lib", {
"targets": {
"electron": 1.5
"electron": 1.4
},
"modules": false,
"useBuiltIns": true
Expand Down
23 changes: 21 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -26,18 +26,37 @@ describe("babel-preset-env", () => {
assert.deepEqual(babelPresetEnv.getTargets({
electron: "1.0"
}), {
chrome: 50
chrome: 49
});
});

it("should work with a number", function() {
assert.deepEqual(babelPresetEnv.getTargets({
electron: 1.0
}), {
chrome: 49
});
});


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({
Expand Down