From a58bc1a8caa1b22504c6d7749283e9e09df6c59e 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 | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 0b323ff8..dc606231 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()) { + logger.warning('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..66f0c64a 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -642,6 +642,42 @@ 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 displays a warning', () => { + const config = createConfig(); + config.runtimeConfig.babelRcFileExists = true; + config.configureBabelPresetEnv(() => {}); + + const warnings = logger.getMessages().warning; + expect(warnings).to.have.lengthOf(1); + expect(warnings[0]).to.contain('your app already provides an external Babel configuration'); + }); + }); + describe('configureCssLoader', () => { it('Calling method sets it', () => { const config = createConfig();