Skip to content

Commit

Permalink
Overwrite arrays when merging Babel config
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed Dec 6, 2018
1 parent 2c90afc commit 83f5052
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/BabelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class BabelConfig {
* @param {String} babelRcPath
*/
static generate(mixBabelConfig, babelRcPath) {
return merge.all([
new BabelConfig().fetchBabelRc(babelRcPath),
mixBabelConfig,
BabelConfig.default()
]);
return merge.all(
[
BabelConfig.default(),
new BabelConfig().fetchBabelRc(babelRcPath),
mixBabelConfig
],
{
arrayMerge: (destinationArray, sourceArray, options) =>
sourceArray
}
);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/features/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ test.serial('Babel reads the project .babelrc file', t => {
// Cleanup.
File.find(__dirname + '/.testbabelrc').delete();
});

test.serial(
'Values from duplicate keys in the .babelrc file override the defaults entirely.',
t => {
// Setup a test .babelrc file.
let babelRcPath = __dirname + '/.testbabelrc';

new File(babelRcPath).write(
'{ "presets": [ ["@babel/preset-env", {"useBuiltIns": "usage"}] ] }'
);

let babelConfig = Config.babel(babelRcPath);

t.is(1, babelConfig.presets.length);

t.deepEqual({ useBuiltIns: 'usage' }, babelConfig.presets[0][1]);

// Cleanup.
File.find(babelRcPath).delete();
}
);

0 comments on commit 83f5052

Please sign in to comment.