Skip to content

Commit a58bc1a

Browse files
committed
Add .babelrc warning to configureBabelPresetEnv and remove some deprecations
1 parent f5a17a4 commit a58bc1a

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/WebpackConfig.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ class WebpackConfig {
405405
normalizedOptionKey = 'includeNodeModules';
406406
}
407407

408-
if (['useBuiltIns', 'corejs'].includes(optionKey)) {
409-
logger.deprecation(`configureBabel: "${optionKey}" is deprecated. Please use configureBabelPresetEnv() instead.`);
410-
}
411-
412408
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) {
413409
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").`);
414410
continue;
@@ -456,6 +452,10 @@ class WebpackConfig {
456452
throw new Error('Argument 1 to configureBabelPresetEnv() must be a callback function.');
457453
}
458454

455+
if (this.doesBabelRcFileExist()) {
456+
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").');
457+
}
458+
459459
this.babelPresetEnvOptionsCallback = callback;
460460
}
461461

test/WebpackConfig.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,42 @@ describe('WebpackConfig object', () => {
642642
});
643643
});
644644

645+
describe('configureBabelPresetEnv', () => {
646+
beforeEach(() => {
647+
logger.reset();
648+
logger.quiet();
649+
});
650+
651+
afterEach(() => {
652+
logger.quiet(false);
653+
});
654+
655+
it('Calling method sets it', () => {
656+
const config = createConfig();
657+
const testCallback = () => {};
658+
config.configureBabelPresetEnv(testCallback);
659+
expect(config.babelPresetEnvOptionsCallback).to.equal(testCallback);
660+
});
661+
662+
it('Calling with non-callback throws an error', () => {
663+
const config = createConfig();
664+
665+
expect(() => {
666+
config.configureBabelPresetEnv('FOO');
667+
}).to.throw('must be a callback function');
668+
});
669+
670+
it('Calling with a callback when .babelrc is present displays a warning', () => {
671+
const config = createConfig();
672+
config.runtimeConfig.babelRcFileExists = true;
673+
config.configureBabelPresetEnv(() => {});
674+
675+
const warnings = logger.getMessages().warning;
676+
expect(warnings).to.have.lengthOf(1);
677+
expect(warnings[0]).to.contain('your app already provides an external Babel configuration');
678+
});
679+
});
680+
645681
describe('configureCssLoader', () => {
646682
it('Calling method sets it', () => {
647683
const config = createConfig();

0 commit comments

Comments
 (0)