Skip to content

Commit

Permalink
fix(merge): Clone arrays correctly if only one exists
Browse files Browse the repository at this point in the history
Closes #106.
  • Loading branch information
bebraw committed Jan 4, 2019
1 parent 320ff68 commit 559292d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/join-arrays.js
@@ -1,5 +1,5 @@
import {
cloneDeep, isFunction, isPlainObject, mergeWith
clone, cloneDeep, isFunction, isPlainObject, mergeWith
} from 'lodash';

const isArray = Array.isArray;
Expand Down Expand Up @@ -35,6 +35,10 @@ export default function joinArrays({
return cloneDeep(b);
}

if (isArray(b)) {
return [...b];
}

return b;
};
}
41 changes: 41 additions & 0 deletions tests/test-merge.js
Expand Up @@ -291,6 +291,47 @@ function customizeMergeTests(merge) {

assert.equal(receivedKey, 'plugins');
});

it('should not mutate plugins #106', function () {
const config1 = {
entry: {
page1: 'src/page1',
page2: 'src/page2'
},
output: {
path: 'dist',
publicPath: '/'
}
};
const config2 = {
entry: {
page3: 'src/page3',
page4: 'src/page4'
},
output: {
path: 'dist',
publicPath: '/'
}
};
const enhance = {
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]
};

const result1 = merge(config1, enhance);
const result2 = merge(config2, enhance);

assert.equal(result1.plugins.length, 1);
assert.equal(result2.plugins.length, 1);

result1.plugins.push(
new webpack.HotModuleReplacementPlugin()
);

assert.equal(result1.plugins.length, 2);
assert.equal(result2.plugins.length, 1);
});
}

module.exports = normalMergeTests;

0 comments on commit 559292d

Please sign in to comment.