Skip to content

Commit

Permalink
Add .babelrc warning to configureBabelPresetEnv and remove some depre…
Browse files Browse the repository at this point in the history
…cations
  • Loading branch information
Lyrkan committed Oct 10, 2019
1 parent f5a17a4 commit 5154b38
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/WebpackConfig.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
35 changes: 35 additions & 0 deletions test/WebpackConfig.js
Expand Up @@ -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();
Expand Down

0 comments on commit 5154b38

Please sign in to comment.