Merge pull request #176 from babel/add-electron-fail
Add test for invalid electron version
This commit is contained in:
commit
393746d781
@ -1,9 +1,8 @@
|
||||
import browserslist from "browserslist";
|
||||
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";
|
||||
|
||||
@ -101,19 +100,13 @@ export const getTargets = (targets = {}) => {
|
||||
targetOps.node = getCurrentNodeVersion();
|
||||
}
|
||||
|
||||
// Rewrite Electron versions to their Chrome equivalents
|
||||
// Replace Electron target with its Chrome equivalent
|
||||
if (targetOps.electron) {
|
||||
const electronChromeVersion = parseInt(electronToChromium(targetOps.electron), 10);
|
||||
const electronChromeVersion = getElectronChromeVersion(targetOps.electron);
|
||||
|
||||
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;
|
||||
}
|
||||
targetOps.chrome = targetOps.chrome
|
||||
? Math.min(targetOps.chrome, electronChromeVersion)
|
||||
: electronChromeVersion;
|
||||
|
||||
delete targetOps.electron;
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
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";
|
||||
@ -69,6 +70,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) {
|
||||
|
||||
@ -66,6 +66,23 @@ describe("babel-preset-env", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should error if electron version is invalid", () => {
|
||||
const fixtures = [
|
||||
"0.19",
|
||||
0.19,
|
||||
999,
|
||||
"999",
|
||||
];
|
||||
|
||||
fixtures.forEach((electronVersion) => {
|
||||
assert.throws(() => {
|
||||
babelPresetEnv.getTargets({
|
||||
electron: electronVersion,
|
||||
});
|
||||
}, Error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("isPluginRequired", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user