Skip to content

Commit 53df05e

Browse files
committed
minor #651 Add .babelrc error to configureBabelPresetEnv and remove some deprecations (Lyrkan)
This PR was merged into the master branch. Discussion ---------- Add .babelrc error to configureBabelPresetEnv and remove some deprecations Since we do not configure `@babel/preset-env` if there is a `.babelrc` file (or something similar) it makes sense to add the same warning we already have for the `Encore.configureBabel()` function to `Encore.configureBabelPresetEnv()`: > The "callback" argument of \<function\> 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 PR also removes some deprecation that were added by #642. We talked about them with @weaverryan and it's probably not worth removing the `useBuiltIns` and `corejs` options of `Encore.configureBabel()`: * they are currently recommended by the flex recipe * it allows us to document them/check them easier than with a callback Commits ------- 5154b38 Add .babelrc warning to configureBabelPresetEnv and remove some deprecations
2 parents 8fc1cb1 + 5154b38 commit 53df05e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-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+
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").');
457+
}
458+
459459
this.babelPresetEnvOptionsCallback = callback;
460460
}
461461

test/WebpackConfig.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,41 @@ 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 throws an error', () => {
671+
const config = createConfig();
672+
config.runtimeConfig.babelRcFileExists = true;
673+
674+
expect(() => {
675+
config.configureBabelPresetEnv(() => {});
676+
}).to.throw('your app already provides an external Babel configuration');
677+
});
678+
});
679+
645680
describe('configureCssLoader', () => {
646681
it('Calling method sets it', () => {
647682
const config = createConfig();

0 commit comments

Comments
 (0)