@@ -11,24 +11,38 @@ if (existsSync(CONFIG_PATH)) {
1111
1212export const config : Config = deepMerge ( defaults , userConfig ) as Config ;
1313
14- function deepMerge ( target : any , source : any ) : any {
14+ function deepMerge ( target : any , source : any , replaceKeys : string [ ] = [ ] ) {
1515 const result = { ...target } ;
16+
1617 for ( const key of Object . keys ( source ?? { } ) ) {
17- if ( source [ key ] && typeof source [ key ] === "object" && ! Array . isArray ( source [ key ] ) ) {
18- result [ key ] = deepMerge ( target [ key ] ?? { } , source [ key ] ) ;
19- } else {
18+ if ( replaceKeys . includes ( key ) ) {
2019 result [ key ] = source [ key ] ;
20+ continue ;
21+ }
22+
23+ const sourceVal = source [ key ] ;
24+
25+ if (
26+ sourceVal &&
27+ typeof sourceVal === "object" &&
28+ ! Array . isArray ( sourceVal )
29+ ) {
30+ result [ key ] = deepMerge ( target [ key ] ?? { } , sourceVal , replaceKeys ) ;
31+ } else {
32+ result [ key ] = sourceVal ;
2133 }
2234 }
35+
2336 return result ;
2437}
2538
26- export function updateConfig ( updates : any ) {
39+
40+ export function updateConfig ( updates : any , replaceKeys : string [ ] = [ ] ) {
2741 const current = existsSync ( CONFIG_PATH )
2842 ? JSON . parse ( readFileSync ( CONFIG_PATH , "utf-8" ) )
2943 : { } ;
3044
31- const merged = deepMerge ( current , updates ) ;
45+ const merged = deepMerge ( current , updates , replaceKeys ) ;
3246
3347 writeFileSync ( CONFIG_PATH , JSON . stringify ( merged , null , 2 ) ) ;
3448}
0 commit comments