From fa951abfdc129d02a264aaf131ff539d37b0c367 Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Mon, 21 Oct 2019 16:23:59 -0500 Subject: [PATCH] Do not use `env` key in Babel common preset (#48661) The merging behavior of having both `plugins` and `env.test.plugins` in the Babel configuration is confusing and does not work how we would like (that is, disabling the idx Babel plugin in test environments.) There had been some [discussion about deprecating the `env` key in Babel](https://github.com/babel/babel/issues/5276) because of this behavior and recommending using conditional logic. The behavior has been modified in later versions of Babel, but still does not work as intended in our case. Change this to only add the idx plugin if we're in a non-test environment. --- packages/kbn-babel-preset/common_preset.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/kbn-babel-preset/common_preset.js b/packages/kbn-babel-preset/common_preset.js index 8fc532bd572a..d2bad41e8de8 100644 --- a/packages/kbn-babel-preset/common_preset.js +++ b/packages/kbn-babel-preset/common_preset.js @@ -28,17 +28,17 @@ const plugins = [ // See https://github.com/babel/proposals/issues/12 for progress require.resolve('@babel/plugin-proposal-class-properties'), ]; +const isTestEnv = process.env.BABEL_ENV === 'test' || process.env.NODE_ENV === 'test'; + +// Only load the idx plugin in non-test environments, since it conflicts with +// Jest's coverage mapping. +if (!isTestEnv) { + plugins.push(require.resolve('@kbn/elastic-idx/babel')); +} module.exports = { presets: [require.resolve('@babel/preset-typescript'), require.resolve('@babel/preset-react')], - plugins: plugins.concat(require.resolve('@kbn/elastic-idx/babel')), - // Do not use the idx plugin in the test environment because it causes - // causes conflicts with Jest's coverage mapping. - env: { - test: { - plugins, - }, - }, + plugins, overrides: [ { // Babel 7 don't support the namespace feature on typescript code.