Skip to content

Commit

Permalink
fix: don't treat strings as objects (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-jeb authored Dec 22, 2020
1 parent a18b676 commit 4356dcd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ function mergeWithRule({
return matches;
});

if(!isPlainObject(ao)){
return ao;
}

Object.entries(ao).forEach(([k, v]) => {
const rule = currentRule;

Expand Down
72 changes: 72 additions & 0 deletions test/merge-with-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,4 +1117,76 @@ describe("Merge with rules", function () {
})(conf1, conf2)
).toEqual(result);
});

it('should not merge strings with objects', () => {
const conf1 = {
module: {
rules: [
{
"test": "some-test",
"use": [
"hello-loader"
]
}
],
},
};

const conf2 = {
module: {
rules: [
{
"test": "another-test",
"use": [
{
"loader": "another-loader",
"options": {
"someoption": "hey"
}
}
]
}
]
},
};

const expected = {
module: {
rules: [
{
"test": "some-test",
"use": [
"hello-loader"
]
},
{
"test": "another-test",
"use": [
{
"loader": "another-loader",
"options": {
"someoption": "hey"
}
}
]
}
],
},
};

expect(
mergeWithRules({
module: {
rules: {
test: CustomizeRule.Match,
use: {
loader: CustomizeRule.Match,
options: CustomizeRule.Merge,
},
},
},
})(conf1, conf2)
).toEqual(expected);
})

});

0 comments on commit 4356dcd

Please sign in to comment.