Skip to content

Commit e9cee04

Browse files
fix(core-kernel): override array on merge (#4269)
1 parent 2f493d7 commit e9cee04

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

__tests__/unit/core-kernel/providers/plugin-configuration.test.ts

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ describe("PluginConfiguration", () => {
3131
expect(pluginConfiguration.all()).toEqual({ defaultKey: "defaultValue" });
3232
});
3333

34-
it("should merge the given value", () => {
35-
pluginConfiguration.set("key", "value");
36-
pluginConfiguration.merge({ some: "value" });
37-
38-
expect(pluginConfiguration.all()).toEqual({ some: "value", key: "value" });
39-
});
40-
4134
it("should set and get the given value", () => {
4235
pluginConfiguration.set("key", "value");
4336

@@ -59,4 +52,48 @@ describe("PluginConfiguration", () => {
5952
it("should throw when using deprecated get default value argument", () => {
6053
expect(() => pluginConfiguration.get("key", "default value")).toThrow();
6154
});
55+
56+
describe("merge", () => {
57+
it("should merge the given value", () => {
58+
pluginConfiguration.set("key", "value");
59+
pluginConfiguration.merge({ some: "value" });
60+
61+
expect(pluginConfiguration.all()).toEqual({ some: "value", key: "value" });
62+
});
63+
64+
it("should merge nested object", () => {
65+
pluginConfiguration.set("key", {
66+
"1": {
67+
"1.1": "test",
68+
},
69+
});
70+
pluginConfiguration.merge({
71+
key: {
72+
"1": {
73+
"1.2": "test",
74+
},
75+
},
76+
});
77+
78+
expect(pluginConfiguration.all()).toEqual({
79+
key: {
80+
"1": {
81+
"1.1": "test",
82+
"1.2": "test",
83+
},
84+
},
85+
});
86+
});
87+
88+
it("should override array", () => {
89+
pluginConfiguration.set("key", [1, 2, 3]);
90+
pluginConfiguration.merge({
91+
key: [3, 4, 5],
92+
});
93+
94+
expect(pluginConfiguration.all()).toEqual({
95+
key: [3, 4, 5],
96+
});
97+
});
98+
});
6299
});

packages/core-kernel/src/providers/plugin-configuration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export class PluginConfiguration {
7171
*/
7272
public merge(values: JsonObject | undefined): this {
7373
if (values) {
74-
this.items = deepmerge(this.items, values);
74+
this.items = deepmerge(this.items, values, {
75+
arrayMerge: (destination, source) => source,
76+
});
7577
}
7678

7779
return this;

0 commit comments

Comments
 (0)