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

Commit

Permalink
add electron version util to normalize-options
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Feb 28, 2017
1 parent ff8ad0f commit ac36828
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 3 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import browserslist from "browserslist";
import invariant from "invariant";
import builtInsList from "../data/built-ins.json";
import defaultInclude from "./default-includes";
import { electronToChromium } from "electron-to-chromium";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options.js";
import normalizeOptions, { getElectronChromeVersion } from "./normalize-options.js";
import pluginList from "../data/plugins.json";
import transformPolyfillRequirePlugin from "./transform-polyfill-require-plugin";

Expand Down Expand Up @@ -102,14 +100,9 @@ export const getTargets = (targets = {}) => {
targetOps.node = getCurrentNodeVersion();
}

// Replace Electron versions with their Chrome equivalent
// Replace Electron target with its Chrome equivalent
if (targetOps.electron) {
const electronChromeVersion = parseInt(electronToChromium(targetOps.electron), 10);

invariant(
!!electronChromeVersion,
`Electron version ${targetOps.electron} is either too old or too new`
);
const electronChromeVersion = getElectronChromeVersion(targetOps.electron);

targetOps.chrome = targetOps.chrome
? Math.min(targetOps.chrome, electronChromeVersion)
Expand Down
13 changes: 12 additions & 1 deletion src/normalize-options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import intersection from "lodash/intersection";
import invariant from "invariant";

import { electronToChromium } from "electron-to-chromium";
import builtInsList from "../data/built-ins.json";
import defaultInclude from "./default-includes";
import moduleTransformations from "./module-transformations";
Expand Down Expand Up @@ -69,6 +69,17 @@ 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

0 comments on commit ac36828

Please sign in to comment.