-
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
cli(tsc): make LH.Flags type correct and consistent #5849
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 |
---|---|---|
|
@@ -28,6 +28,18 @@ declare global { | |
[P in K]+?: T[P] | ||
} | ||
|
||
/** An object with the keys in the union K mapped to themselves as values. */ | ||
type SelfMap<K extends string> = { | ||
[P in K]: P; | ||
}; | ||
|
||
/** Make optional all properties on T and any properties on object properties of T. */ | ||
type RecursivePartial<T> = { | ||
[P in keyof T]+?: T[P] extends object ? | ||
RecursivePartial<T[P]> : | ||
T[P]; | ||
}; | ||
|
||
/** | ||
* Exclude void from T | ||
*/ | ||
|
@@ -77,29 +89,36 @@ declare global { | |
onlyAudits?: string[] | null; | ||
onlyCategories?: string[] | null; | ||
skipAudits?: string[] | null; | ||
extraHeaders?: Crdp.Network.Headers | null; // See extraHeaders TODO in bin.js | ||
} | ||
|
||
export interface Flags extends SharedFlagsSettings { | ||
// Used by both core/ and cli/ | ||
port: number; | ||
hostname: string; | ||
output: any; | ||
logLevel: 'silent'|'error'|'info'|'verbose'; | ||
port?: number; | ||
hostname?: string; | ||
logLevel?: 'silent'|'error'|'info'|'verbose'; | ||
configPath?: string; | ||
} | ||
|
||
// Just used by cli/ | ||
/** | ||
* Flags accepted by Lighthouse, plus additional flags just | ||
* for controlling the CLI. | ||
*/ | ||
export interface CliFlags extends Flags { | ||
_: string[]; | ||
chromeFlags: string; | ||
outputPath: string; | ||
saveAssets: boolean; | ||
view: boolean; | ||
enableErrorReporting: boolean; | ||
enableErrorReporting?: boolean; | ||
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. make this a yargs boolean instead. seems weird to have this one optional but the rest not. 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. done 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. wait noooooo, we gotta revert this. it's purposefully not a yargs boolean so that the setting saved to their config will be respected. explicitly setting as false via yargs will always turn error reporting off 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. whoops, very good point. There was a reason it wasn't in |
||
listAllAudits: boolean; | ||
listTraceCategories: boolean; | ||
configPath?: string; | ||
preset?: 'full'|'mixed-content'|'perf'; | ||
verbose: boolean; | ||
quiet: boolean; | ||
extraHeaders?: string; | ||
// following are given defaults in cli-flags, so not optional like in Flags or SharedFlagsSettings | ||
output: OutputMode[]; | ||
port: number; | ||
hostname: string; | ||
} | ||
|
||
export interface RunnerResult { | ||
|
@@ -120,12 +139,6 @@ declare global { | |
group: string; | ||
} | ||
|
||
export interface LaunchedChrome { | ||
pid: number; | ||
port: number; | ||
kill: () => Promise<{}>; | ||
} | ||
|
||
export interface LighthouseError extends Error { | ||
friendlyMessage?: string; | ||
} | ||
|
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.
It's a bug that this wasn't flagged before, but it wasn't until I made any change to
LH.Flags.output
that it started to be flagged (even though the problem is withLH.Flags.throttling
, weirdly enough).We just want to copy any
Settings
properties over from an instance ofFlags
, so the result will only haveSettings
properties but some may not be set. SoPartial<LH.Config.Settings>
would be correct ifSettings
were a simple object.The issue is that one of the properties (
throttling
) is itself an object, and whileFlags.throttling
has all optional properties, onSettings.throttling
they're all required. This change appliesPartial<>
to all ofSettings
properties recursively. It could special casethrottling
instead, but this will catch any future objects added toSharedFlagsSettings
as well.