Skip to content

Commit

Permalink
fix: mergeConfig function to return an object (#6024)
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Jul 31, 2024
1 parent dc736ef commit 916559a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/tall-socks-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/runtime': patch
'@modern-js/runtime-utils': patch
---

fix: mergeConfig function to return an object when the first configuration is not an object

fix: 修复 mergeConfig 函数,使其在第一个配置非对象时返回对象
2 changes: 1 addition & 1 deletion packages/runtime/plugin-runtime/src/core/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export function mergeConfig(
config: Record<string, any>,
...otherConfig: Record<string, any>[]
) {
return merge(config, ...otherConfig);
return merge({}, config, ...otherConfig);
}
6 changes: 6 additions & 0 deletions packages/toolkit/runtime-utils/tests/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ describe('merge function', () => {
const result = merge({}, obj1, obj2, obj3);
expect(result).toEqual({ a: 3 });
});
test('should return right value when item is not object', () => {
expect(merge({}, true as any, { a: 1 })).toEqual({ a: 1 });
expect(merge({}, false as any, { a: 1 })).toEqual({ a: 1 });
expect(merge({}, 1 as any, { a: 1 })).toEqual({ a: 1 });
expect(merge({}, 'b' as any, { a: 1 })).toEqual({ a: 1 });
});
});

0 comments on commit 916559a

Please sign in to comment.