-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core(config): clean flags for settings #4960
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,8 +246,24 @@ function expandArtifacts(artifacts) { | |
return artifacts; | ||
} | ||
|
||
/** | ||
* @param {LH.Flags=} flags | ||
* @return {Partial<LH.Config.Settings>} | ||
*/ | ||
function cleanFlagsForSettings(flags = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semantically this is could we call it that instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I'm following you, this is looking at what properties are not on the JSON.parse(JSON.stringify()) approach would address the specific undefined yargs case but not an underlying problem that having miscellaneous junk present that isn't part of settings throws off our isDeepEqual later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh got it.
ahhh.. mmhmmm. k lgtm |
||
const settings = {}; | ||
for (const key of Object.keys(flags)) { | ||
if (typeof constants.defaultSettings[key] !== 'undefined') { | ||
settings[key] = flags[key]; | ||
} | ||
} | ||
|
||
return settings; | ||
} | ||
|
||
function merge(base, extension) { | ||
if (typeof base === 'undefined') { | ||
// If the default value doesn't exist or is explicitly null, defer to the extending value | ||
if (typeof base === 'undefined' || base === null) { | ||
return extension; | ||
} else if (Array.isArray(extension)) { | ||
if (!Array.isArray(base)) throw new TypeError(`Expected array but got ${typeof base}`); | ||
|
@@ -330,7 +346,7 @@ class Config { | |
configJSON.passes = Config.expandGathererShorthandAndMergeOptions(configJSON.passes); | ||
|
||
// Override any applicable settings with CLI flags | ||
configJSON.settings = merge(configJSON.settings || {}, flags || {}); | ||
configJSON.settings = merge(configJSON.settings || {}, cleanFlagsForSettings(flags)); | ||
|
||
// Generate a limited config if specified | ||
if (Array.isArray(configJSON.settings.onlyCategories) || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,24 @@ const throttling = { | |
}, | ||
}; | ||
|
||
/** @type {LH.Config.Settings} */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
const defaultSettings = { | ||
maxWaitForLoad: 45 * 1000, | ||
throttlingMethod: 'devtools', | ||
throttling: throttling.mobile3G, | ||
auditMode: false, | ||
gatherMode: false, | ||
disableStorageReset: false, | ||
disableDeviceEmulation: false, | ||
|
||
// the following settings have no defaults but we still want ensure that `key in settings` | ||
// in config will work in a typechecked way | ||
blockedUrlPatterns: null, | ||
additionalTraceCategories: null, | ||
extraHeaders: null, | ||
onlyAudits: null, | ||
onlyCategories: null, | ||
skipAudits: null, | ||
}; | ||
|
||
const defaultPassConfig = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,11 @@ declare global { | |
settings?: SettingsJson; | ||
passes?: PassJson[]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. someone's got a diff trailing space editor setting it seems :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, damn, eslint isn't checking .ts files, obvs. I'll find the setting :P |
||
|
||
export interface SettingsJson extends SharedFlagsSettings { | ||
extraHeaders?: Crdp.Network.Headers; | ||
extraHeaders?: Crdp.Network.Headers | null; | ||
} | ||
|
||
export interface PassJson { | ||
passName: string; | ||
recordTrace?: boolean; | ||
|
@@ -41,7 +41,7 @@ declare global { | |
blankDuration?: number; | ||
gatherers: GathererJson[]; | ||
} | ||
|
||
export type GathererJson = { | ||
path: string; | ||
options?: {}; | ||
|
@@ -52,14 +52,14 @@ declare global { | |
instance: InstanceType<typeof Gatherer>; | ||
options?: {}; | ||
} | string; | ||
|
||
// TODO(bckenny): we likely don't want to require all these | ||
export type Settings = Required<SettingsJson>; | ||
|
||
export interface Pass extends Required<PassJson> { | ||
gatherers: GathererDefn[]; | ||
} | ||
|
||
export interface GathererDefn { | ||
implementation: typeof Gatherer; | ||
instance: InstanceType<typeof Gatherer>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a function description that this is dropping any flag not found on settings?