@@ -246,8 +246,27 @@ function expandArtifacts(artifacts) {
246
246
return artifacts ;
247
247
}
248
248
249
+ /**
250
+ * Creates a settings object from potential flags object by dropping all the properties
251
+ * that don't exist on Config.Settings.
252
+ *
253
+ * @param {LH.Flags= } flags
254
+ * @return {Partial<LH.Config.Settings> }
255
+ */
256
+ function cleanFlagsForSettings ( flags = { } ) {
257
+ const settings = { } ;
258
+ for ( const key of Object . keys ( flags ) ) {
259
+ if ( typeof constants . defaultSettings [ key ] !== 'undefined' ) {
260
+ settings [ key ] = flags [ key ] ;
261
+ }
262
+ }
263
+
264
+ return settings ;
265
+ }
266
+
249
267
function merge ( base , extension ) {
250
- if ( typeof base === 'undefined' ) {
268
+ // If the default value doesn't exist or is explicitly null, defer to the extending value
269
+ if ( typeof base === 'undefined' || base === null ) {
251
270
return extension ;
252
271
} else if ( Array . isArray ( extension ) ) {
253
272
if ( ! Array . isArray ( base ) ) throw new TypeError ( `Expected array but got ${ typeof base } ` ) ;
@@ -330,7 +349,7 @@ class Config {
330
349
configJSON . passes = Config . expandGathererShorthandAndMergeOptions ( configJSON . passes ) ;
331
350
332
351
// Override any applicable settings with CLI flags
333
- configJSON . settings = merge ( configJSON . settings || { } , flags || { } ) ;
352
+ configJSON . settings = merge ( configJSON . settings || { } , cleanFlagsForSettings ( flags ) ) ;
334
353
335
354
// Generate a limited config if specified
336
355
if ( Array . isArray ( configJSON . settings . onlyCategories ) ||
0 commit comments