From 5154b38e5ef87013ecb963d10e13c86364631178 Mon Sep 17 00:00:00 2001 From: Lyrkan <850046+Lyrkan@users.noreply.github.com> Date: Wed, 9 Oct 2019 21:01:53 +0200 Subject: [PATCH] Add .babelrc warning to configureBabelPresetEnv and remove some deprecations --- lib/WebpackConfig.js | 8 ++++---- test/WebpackConfig.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 0b323ff8..64b7dc33 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -405,10 +405,6 @@ class WebpackConfig { normalizedOptionKey = 'includeNodeModules'; } - if (['useBuiltIns', 'corejs'].includes(optionKey)) { - logger.deprecation(`configureBabel: "${optionKey}" is deprecated. Please use configureBabelPresetEnv() instead.`); - } - if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) { logger.warning(`The "${normalizedOptionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").`); continue; @@ -456,6 +452,10 @@ class WebpackConfig { throw new Error('Argument 1 to configureBabelPresetEnv() must be a callback function.'); } + if (this.doesBabelRcFileExist()) { + throw new Error('The "callback" argument of configureBabelPresetEnv() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").'); + } + this.babelPresetEnvOptionsCallback = callback; } diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index ea271666..b2311fbb 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -642,6 +642,41 @@ describe('WebpackConfig object', () => { }); }); + describe('configureBabelPresetEnv', () => { + beforeEach(() => { + logger.reset(); + logger.quiet(); + }); + + afterEach(() => { + logger.quiet(false); + }); + + it('Calling method sets it', () => { + const config = createConfig(); + const testCallback = () => {}; + config.configureBabelPresetEnv(testCallback); + expect(config.babelPresetEnvOptionsCallback).to.equal(testCallback); + }); + + it('Calling with non-callback throws an error', () => { + const config = createConfig(); + + expect(() => { + config.configureBabelPresetEnv('FOO'); + }).to.throw('must be a callback function'); + }); + + it('Calling with a callback when .babelrc is present throws an error', () => { + const config = createConfig(); + config.runtimeConfig.babelRcFileExists = true; + + expect(() => { + config.configureBabelPresetEnv(() => {}); + }).to.throw('your app already provides an external Babel configuration'); + }); + }); + describe('configureCssLoader', () => { it('Calling method sets it', () => { const config = createConfig();