@@ -8,7 +8,7 @@ import { allGenerators } from '../../generators/index.mjs';
88import { parseChangelog , parseIndex } from '../../parsers/markdown.mjs' ;
99import { enforceArray } from '../array.mjs' ;
1010import { leftHandAssign } from '../generators.mjs' ;
11- import { lazy } from '../misc.mjs' ;
11+ import { deepMerge , lazy } from '../misc.mjs' ;
1212import { importFromURL } from '../url.mjs' ;
1313
1414/**
@@ -39,53 +39,6 @@ export const getDefaultConfig = lazy(() =>
3939 )
4040) ;
4141
42- /**
43- * Deeply merges multiple objects with special handling for arrays and nested objects.
44- *
45- * @param {Object[] } objs - Objects to merge, with earlier arguments taking precedence
46- * @param {number } maxDepth - Maximum depth for recursive merging
47- * @param {number } currentDepth - Current recursion depth
48- * @returns {Object } A new object containing the merged result
49- */
50- const merge = ( objs , maxDepth , currentDepth = 0 ) => {
51- return objs . reduce ( ( result , current ) => {
52- return Object . keys ( { ...result , ...current } ) . reduce ( ( acc , k ) => {
53- const resultVal = result [ k ] ;
54- const currentVal = current [ k ] ;
55-
56- return {
57- ...acc ,
58- [ k ] :
59- // If both values exist
60- resultVal && currentVal
61- ? // Both are arrays: concatenate them
62- Array . isArray ( resultVal ) && Array . isArray ( currentVal )
63- ? [ ...resultVal , ...currentVal ]
64- : // result is array, current is string: keep result (array wins)
65- Array . isArray ( resultVal ) && typeof currentVal === 'string'
66- ? resultVal . concat ( [ currentVal ] )
67- : // result is string, current is array: keep current (array wins)
68- typeof resultVal === 'string' && Array . isArray ( currentVal )
69- ? currentVal . concat ( [ resultVal ] )
70- : // Both are objects: recursively merge if depth allows
71- typeof resultVal === 'object' &&
72- typeof currentVal === 'object'
73- ? currentDepth < maxDepth
74- ? merge (
75- [ resultVal , currentVal ] ,
76- maxDepth ,
77- currentDepth + 1
78- )
79- : currentVal // At max depth, use current value (last wins)
80- : // Otherwise: result takes precedence
81- resultVal
82- : // Only one exists: use nullish coalescing to pick the defined value
83- ( resultVal ?? currentVal ) ,
84- } ;
85- } , { } ) ;
86- } , { } ) ;
87- } ;
88-
8942/**
9043 * Loads a configuration file from a URL or file path.
9144 *
@@ -158,11 +111,10 @@ export const createRunConfiguration = async options => {
158111 config . target &&= enforceArray ( config . target ) ;
159112
160113 // Merge with defaults
161- // We set maxDepth as 2, as that's the depth of
162- // our object.
163- const merged = merge (
164- [ config , createConfigFromCLIOptions ( options ) , getDefaultConfig ( ) ] ,
165- 1
114+ const merged = deepMerge (
115+ config ,
116+ createConfigFromCLIOptions ( options ) ,
117+ getDefaultConfig ( )
166118 ) ;
167119
168120 // These need to be coerced
0 commit comments