Skip to content
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

feat(cli): add psi strategy in option for psi runner, keeping mobile … #631

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Options:
--puppeteerLaunchOptions The object of puppeteer launch options
--psiApiKey [psi only] The API key to use for PageSpeed Insights runner method.
You do not need to use this unless you wrote a custom version.
--psiStrategy [psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile
--startServerCommand The command to run to start the server.
--startServerReadyPattern String pattern to listen for started server.
[string] [default: "listen|ready"]
Expand Down Expand Up @@ -338,6 +339,12 @@ _method=psi only_

The API endpoint to hit for making a PageSpeed Insights request. It is very unlikely you should need to use this option. Only use this if you have self-hosted a custom version of the PSI API.

#### `psiStrategy`

_method=psi only_

Use this option to change the strategy to use for PageSpeed Insights runner method. Use `mobile` or `desktop`. The default value is `mobile`.

#### `startServerCommand`

The shell command to use to start the project's webserver. LHCI will use this command to start the server before loading the `url`s and automatically shut it down once collection is complete.
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function buildCommand(yargs) {
psiApiKey: {
description: '[psi only] The API key to use for PageSpeed Insights runner method.',
},
psiStrategy: {
description:
'[psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile',
},
staticDistDir: {
description: 'The build directory where your HTML files to run Lighthouse on are located.',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/collect/psi-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PsiRunner {
const apiKey = options.psiApiKey;
if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner');
const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint});
return JSON.stringify(await client.run(url));
return JSON.stringify(await client.run(url, {strategy: options.psiStrategy}));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/psi-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class PsiRunner {

/**
* @param {string} url
* @param {{psiApiKey?: string, psiApiEndpoint?: string}} [options]
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop'}} [options]
* @return {Promise<string>}
*/
async run(url, options) {
options = {...this._options, ...options};
const apiKey = options.psiApiKey;
if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner');
const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint});
return JSON.stringify(await client.run(url));
return JSON.stringify(await client.run(url, {strategy: options.psiStrategy}));
}

/**
Expand Down
1 change: 1 addition & 0 deletions types/collect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare global {
autodiscoverUrlBlocklist?: string | string[];
psiApiKey?: string;
psiApiEndpoint?: string;
psiStrategy?: 'mobile'|'desktop';
staticDistDir?: string;
isSinglePageApplication?: boolean;
startServerCommand?: string;
Expand Down