From b8cbb79d8c2ac46224b268c7b9f9829f7efe9cad Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 12:56:43 +0100 Subject: [PATCH 01/24] fix: migrate to latest yargs --- package-lock.json | 29 +++++++++++++++-------------- package.json | 9 +++++---- packages/cli/package.json | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8be79b529..773b4e1b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@puppeteer/replay": "^1.3.1", "@types/concurrently": "^7.0.0", "@types/puppeteer": "^5.4.7", - "@types/yargs": "^17.0.9", + "@types/yargs": "^17.0.32", "concurrently": "^7.1.0", "enquirer": "^2.3.6", "lighthouse": "^9.6.7", @@ -21,7 +21,8 @@ "puppeteer": "^19.0.0", "rxjs": "^7.8.1", "ts-node": "10.9.1", - "tslib": "^2.3.1" + "tslib": "^2.3.1", + "yargs": "^17.7.2" }, "devDependencies": { "@commitlint/cli": "^17.2.0", @@ -4954,9 +4955,9 @@ } }, "node_modules/@types/yargs": { - "version": "17.0.13", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz", - "integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "dependencies": { "@types/yargs-parser": "*" } @@ -18785,9 +18786,9 @@ } }, "node_modules/yargs": { - "version": "17.6.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.2.tgz", - "integrity": "sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", @@ -22587,9 +22588,9 @@ } }, "@types/yargs": { - "version": "17.0.13", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz", - "integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "requires": { "@types/yargs-parser": "*" } @@ -32807,9 +32808,9 @@ "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==" }, "yargs": { - "version": "17.6.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.2.tgz", - "integrity": "sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "requires": { "cliui": "^8.0.1", "escalade": "^3.1.1", diff --git a/package.json b/package.json index 0a9a47d18..bf50d3cec 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@puppeteer/replay": "^1.3.1", "@types/concurrently": "^7.0.0", "@types/puppeteer": "^5.4.7", - "@types/yargs": "^17.0.9", + "@types/yargs": "^17.0.32", "concurrently": "^7.1.0", "enquirer": "^2.3.6", "lighthouse": "^9.6.7", @@ -32,7 +32,8 @@ "puppeteer": "^19.0.0", "rxjs": "^7.8.1", "ts-node": "10.9.1", - "tslib": "^2.3.1" + "tslib": "^2.3.1", + "yargs": "^17.7.2" }, "devDependencies": { "@commitlint/cli": "^17.2.0", @@ -40,6 +41,7 @@ "@jscutlery/semver": "^4.0.0", "@nx/cypress": "17.1.1", "@nx/devkit": "17.1.1", + "@nx/eslint": "17.1.1", "@nx/eslint-plugin": "17.1.1", "@nx/jest": "17.1.1", "@nx/js": "17.1.1", @@ -72,7 +74,6 @@ "nx": "17.1.1", "rimraf": "^3.0.2", "ts-jest": "29.1.0", - "typescript": "^4.9.3", - "@nx/eslint": "17.1.1" + "typescript": "^4.9.3" } } diff --git a/packages/cli/package.json b/packages/cli/package.json index 145dfb269..e7d711c53 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -22,7 +22,7 @@ "dependencies": { "ts-node": "10.9.1", "tslib": "^2.3.1", - "yargs": ">=15.4.1", + "yargs": "^17.7.2", "typescript": "^4.6.3", "lighthouse": "^9.6.7", "puppeteer": "^19.0.0", From 96076f3ac7eeb5459cd86aa9ab60bb0c7b46f9b1 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 13:41:42 +0100 Subject: [PATCH 02/24] fix: implement assert options properly --- packages/cli/src/lib/commands/assert/index.ts | 9 ++------- .../cli/src/lib/commands/assert/options.ts | 19 +++++++++++++++++++ .../lib/commands/assert/options/budgetPath.ts | 16 ---------------- .../lib/commands/assert/options/budgets.ts | 17 ----------------- .../src/lib/commands/assert/options/index.ts | 8 -------- .../src/lib/commands/collect/options/index.ts | 4 ++-- .../src/lib/commands/init/options/index.ts | 4 ++-- 7 files changed, 25 insertions(+), 52 deletions(-) create mode 100644 packages/cli/src/lib/commands/assert/options.ts delete mode 100644 packages/cli/src/lib/commands/assert/options/budgetPath.ts delete mode 100644 packages/cli/src/lib/commands/assert/options/budgets.ts delete mode 100644 packages/cli/src/lib/commands/assert/options/index.ts diff --git a/packages/cli/src/lib/commands/assert/index.ts b/packages/cli/src/lib/commands/assert/index.ts index 130e4961f..aef53643b 100644 --- a/packages/cli/src/lib/commands/assert/index.ts +++ b/packages/cli/src/lib/commands/assert/index.ts @@ -1,22 +1,17 @@ import { YargsCommandObject } from '../../core/yargs/types'; -import { logVerbose } from '../../core/loggin/index'; -import { readBudgets } from './utils/budgets'; +import { logVerbose } from '../../core/loggin'; import { readFile } from '../../core/file'; -import { getCollectCommandOptionsFromArgv } from '../collect/utils/params'; -import { RcJson } from '../../types'; import { generateMdReport } from './utils/md-report'; export const assertCommand: YargsCommandObject = { command: 'assert', description: 'Setup .user-flowrc.json', module: { - handler: async (argv: any) => { + handler: async () => { logVerbose(`run "assert" as a yargs command`); - const cfg = getCollectCommandOptionsFromArgv(argv); const json = JSON.parse(readFile('./packages/cli/docs/raw/order-coffee.uf.json').toString()); const mdReport = generateMdReport(json); console.log('md report', mdReport); - // await run(cfg); } } }; diff --git a/packages/cli/src/lib/commands/assert/options.ts b/packages/cli/src/lib/commands/assert/options.ts new file mode 100644 index 000000000..89d58ab84 --- /dev/null +++ b/packages/cli/src/lib/commands/assert/options.ts @@ -0,0 +1,19 @@ +import { Options } from 'yargs'; + +export const budgets = { + alias: 'j', + type: 'array', + string: true, + description: 'Performance budgets (RC file only)' +} satisfies Options; + +export const budgetPath = { + alias: 'k', + type: 'string', + description: 'Path to budgets.json' +} satisfies Options; + +export const assertOptions = { + budgetPath, + budgets +} satisfies Record; diff --git a/packages/cli/src/lib/commands/assert/options/budgetPath.ts b/packages/cli/src/lib/commands/assert/options/budgetPath.ts deleted file mode 100644 index 9c789faeb..000000000 --- a/packages/cli/src/lib/commands/assert/options/budgetPath.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { argv } from 'yargs'; -import { Param } from './budgetPath.model'; -import { ArgvOption } from '../../../core/yargs/types'; - -export const param: Param = { - budgetPath: { - alias: 'k', - type: 'string', - description: 'Path to budgets.json' - } -}; - -export function get(): string { - const { budgetPath } = argv as any as ArgvOption; - return budgetPath; -} diff --git a/packages/cli/src/lib/commands/assert/options/budgets.ts b/packages/cli/src/lib/commands/assert/options/budgets.ts deleted file mode 100644 index d68c82dc7..000000000 --- a/packages/cli/src/lib/commands/assert/options/budgets.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { argv } from 'yargs'; -import { Param } from './budgets.model'; -import { ArgvOption } from '../../../core/yargs/types'; - -export const param: Param = { - budgets: { - alias: 'j', - type: 'array', - string: true, - description: 'Performance budgets (RC file only)' - } -}; - -export function get(): string[] { - const { budgets } = argv as any as ArgvOption; - return budgets as string[]; -} diff --git a/packages/cli/src/lib/commands/assert/options/index.ts b/packages/cli/src/lib/commands/assert/options/index.ts deleted file mode 100644 index c93555dc2..000000000 --- a/packages/cli/src/lib/commands/assert/options/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { param as budgetPath } from '../../assert/options/budgetPath'; -import { param as budgets } from '../../assert/options/budgets'; -import { AssertYargsOptions } from './types'; - -export const ASSERT_OPTIONS: AssertYargsOptions = { - ...budgetPath, - ...budgets -}; diff --git a/packages/cli/src/lib/commands/collect/options/index.ts b/packages/cli/src/lib/commands/collect/options/index.ts index 75f0f827a..99af13147 100644 --- a/packages/cli/src/lib/commands/collect/options/index.ts +++ b/packages/cli/src/lib/commands/collect/options/index.ts @@ -9,7 +9,7 @@ import { param as format } from './format'; import { param as serveCommand } from './serveCommand'; import { param as awaitServeStdout } from './awaitServeStdout'; import { param as dryRun } from './dryRun'; -import { ASSERT_OPTIONS } from '../../assert/options'; +import { assertOptions } from '../../assert/options'; export const PERSIST_OPTIONS: PersistYargsOptions = { ...outPath, @@ -25,5 +25,5 @@ export const COLLECT_OPTIONS: CollectYargsOptions & AssertYargsOptions = { ...awaitServeStdout, ...dryRun, ...PERSIST_OPTIONS, - ...ASSERT_OPTIONS + ...assertOptions }; diff --git a/packages/cli/src/lib/commands/init/options/index.ts b/packages/cli/src/lib/commands/init/options/index.ts index 57ae8be6e..be1c86413 100644 --- a/packages/cli/src/lib/commands/init/options/index.ts +++ b/packages/cli/src/lib/commands/init/options/index.ts @@ -1,9 +1,9 @@ import { AssertYargsOptions } from '../../assert/options/types'; -import { ASSERT_OPTIONS } from '../../assert/options'; +import { assertOptions } from '../../assert/options'; import { COLLECT_OPTIONS } from '../../collect/options'; import { CollectYargsOptions } from '../../collect/options/types'; export const INIT_OPTIONS: CollectYargsOptions & AssertYargsOptions = { ...COLLECT_OPTIONS, - ...ASSERT_OPTIONS + ...assertOptions }; From 1b3c6415fbd275b94a66c3d210cb6f2694c6f199 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 13:56:35 +0100 Subject: [PATCH 03/24] fix: do not export internals --- packages/cli/src/lib/commands/assert/options.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/lib/commands/assert/options.ts b/packages/cli/src/lib/commands/assert/options.ts index 89d58ab84..2193342a7 100644 --- a/packages/cli/src/lib/commands/assert/options.ts +++ b/packages/cli/src/lib/commands/assert/options.ts @@ -1,13 +1,13 @@ import { Options } from 'yargs'; -export const budgets = { +const budgets = { alias: 'j', type: 'array', string: true, description: 'Performance budgets (RC file only)' } satisfies Options; -export const budgetPath = { +const budgetPath = { alias: 'k', type: 'string', description: 'Path to budgets.json' From 3d8fc9a512fb0a3d4cc889ffb63dfa4798e58c66 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 14:01:09 +0100 Subject: [PATCH 04/24] fix: remove test warning --- packages/cli/jest.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/jest.config.ts b/packages/cli/jest.config.ts index 524389c6f..f93526798 100644 --- a/packages/cli/jest.config.ts +++ b/packages/cli/jest.config.ts @@ -14,5 +14,4 @@ export default { transformIgnorePatterns: ['/node_modules/(?!markdown-table/.*)'], moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/packages/cli', - testTimeout: 40_000, }; From 0595ba8b2c7db68288626efa90eccfd6a379e39a Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 14:09:38 +0100 Subject: [PATCH 05/24] fix: remove unused --- packages/cli/src/lib/commands/init/constants.ts | 1 + .../init/options/generateFlow.constants.ts | 1 - .../commands/init/options/generateFlow.model.ts | 9 --------- .../lib/commands/init/options/generateFlow.ts | 16 ---------------- .../init/options/generateGhWorkflow.constants.ts | 1 - .../init/options/generateGhWorkflow.model.ts | 9 --------- .../commands/init/options/generateGhWorkflow.ts | 16 ---------------- .../commands/init/processes/generate-userflow.ts | 3 +-- 8 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 packages/cli/src/lib/commands/init/options/generateFlow.constants.ts delete mode 100644 packages/cli/src/lib/commands/init/options/generateFlow.model.ts delete mode 100644 packages/cli/src/lib/commands/init/options/generateFlow.ts delete mode 100644 packages/cli/src/lib/commands/init/options/generateGhWorkflow.constants.ts delete mode 100644 packages/cli/src/lib/commands/init/options/generateGhWorkflow.model.ts delete mode 100644 packages/cli/src/lib/commands/init/options/generateGhWorkflow.ts diff --git a/packages/cli/src/lib/commands/init/constants.ts b/packages/cli/src/lib/commands/init/constants.ts index 4693b3ba6..e4d770ec2 100644 --- a/packages/cli/src/lib/commands/init/constants.ts +++ b/packages/cli/src/lib/commands/init/constants.ts @@ -23,3 +23,4 @@ export const RequestCountResourceTypeBudgets: string[] = [ 'script', 'stylesheet' ]; +export const PROMPT_INIT_GENERATE_FLOW = 'Setup user flow'; diff --git a/packages/cli/src/lib/commands/init/options/generateFlow.constants.ts b/packages/cli/src/lib/commands/init/options/generateFlow.constants.ts deleted file mode 100644 index df49333f6..000000000 --- a/packages/cli/src/lib/commands/init/options/generateFlow.constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const PROMPT_INIT_GENERATE_FLOW = 'Setup user flow'; diff --git a/packages/cli/src/lib/commands/init/options/generateFlow.model.ts b/packages/cli/src/lib/commands/init/options/generateFlow.model.ts deleted file mode 100644 index bc286b677..000000000 --- a/packages/cli/src/lib/commands/init/options/generateFlow.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - generateFlow: Modify -}; diff --git a/packages/cli/src/lib/commands/init/options/generateFlow.ts b/packages/cli/src/lib/commands/init/options/generateFlow.ts deleted file mode 100644 index 70b42ea14..000000000 --- a/packages/cli/src/lib/commands/init/options/generateFlow.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { argv } from 'yargs'; -import { Param } from './generateFlow.model'; -import { ArgvOption } from '../../../core/yargs/types'; - -export const param: Param = { - generateFlow: { - alias: 'h', - type: 'boolean', - description: 'Create as user flow under "ufPath"' - } -}; - -export function get(): boolean { - const { generateFlow } = argv as any as ArgvOption; - return generateFlow; -} diff --git a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.constants.ts b/packages/cli/src/lib/commands/init/options/generateGhWorkflow.constants.ts deleted file mode 100644 index cdd961bb5..000000000 --- a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const PROMPT_INIT_GENERATE_GH_WORKFLOW = 'Setup GitHub workflow to run user-flow in the CI'; diff --git a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.model.ts b/packages/cli/src/lib/commands/init/options/generateGhWorkflow.model.ts deleted file mode 100644 index eb5114763..000000000 --- a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - generateGhWorkflow: Modify -}; diff --git a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.ts b/packages/cli/src/lib/commands/init/options/generateGhWorkflow.ts deleted file mode 100644 index 8b832c118..000000000 --- a/packages/cli/src/lib/commands/init/options/generateGhWorkflow.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { argv } from 'yargs'; -import { Param } from './generateGhWorkflow.model'; -import { ArgvOption } from '../../../core/yargs/types'; - -export const param: Param = { - generateGhWorkflow: { - alias: 'g', - type: 'boolean', - description: 'Create a workflow using user-flow under .github/workflows' - } -}; - -export function get(): boolean { - const { generateGhWorkflow } = argv as any as ArgvOption; - return generateGhWorkflow; -} diff --git a/packages/cli/src/lib/commands/init/processes/generate-userflow.ts b/packages/cli/src/lib/commands/init/processes/generate-userflow.ts index 36b916a58..8c406ae64 100644 --- a/packages/cli/src/lib/commands/init/processes/generate-userflow.ts +++ b/packages/cli/src/lib/commands/init/processes/generate-userflow.ts @@ -3,13 +3,12 @@ import { join } from 'node:path'; import { readFile, writeFile } from '../../../core/file'; import { log } from '../../../core/loggin'; import { mkdirSync, readdirSync } from 'node:fs'; -import { FlowExampleMap } from '../constants'; +import { FlowExampleMap, PROMPT_INIT_GENERATE_FLOW } from '../constants'; import { FlowExamples } from '../types'; import { ifThenElse } from '../../../core/processing/behaviors'; import { askToSkip } from '../../../core/prompt'; import { CLIProcess } from '../../../core/processing/types'; import { logVerbose } from '../../../core/loggin'; -import { PROMPT_INIT_GENERATE_FLOW } from '../options/generateFlow.constants'; const exampleName = 'basic-navigation'; From 2db3fecef8f2f2a45662863fe3dc9609a1244d5d Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 14:38:37 +0100 Subject: [PATCH 06/24] fix: remove unnecessary code --- .../cli/src/lib/commands/collect/index.ts | 4 +- .../collect/options/awaitServeStdout.ts | 24 +++------ .../commands/collect/options/configPath.ts | 21 +++----- .../lib/commands/collect/options/dryRun.ts | 16 +++--- .../lib/commands/collect/options/format.ts | 29 +++-------- .../src/lib/commands/collect/options/index.ts | 49 +++++++++---------- .../commands/collect/options/openReport.ts | 18 +++---- .../lib/commands/collect/options/outPath.ts | 21 +++----- .../commands/collect/options/serveCommand.ts | 23 +++------ .../lib/commands/collect/options/ufPath.ts | 21 +++----- .../src/lib/commands/collect/options/url.ts | 22 +++------ packages/cli/src/lib/commands/init/index.ts | 17 ++----- packages/cli/src/lib/commands/init/options.ts | 9 ++++ .../src/lib/commands/init/options/index.ts | 9 ---- .../src/lib/commands/init/options/types.ts | 19 +------ 15 files changed, 101 insertions(+), 201 deletions(-) create mode 100644 packages/cli/src/lib/commands/init/options.ts delete mode 100644 packages/cli/src/lib/commands/init/options/index.ts diff --git a/packages/cli/src/lib/commands/collect/index.ts b/packages/cli/src/lib/commands/collect/index.ts index 117414250..16e16214b 100644 --- a/packages/cli/src/lib/commands/collect/index.ts +++ b/packages/cli/src/lib/commands/collect/index.ts @@ -1,12 +1,12 @@ import {YargsCommandObject} from '../../core/yargs/types'; import {logVerbose} from '../../core/loggin/index'; -import {COLLECT_OPTIONS} from './options'; +import {collectOptions} from './options'; import {runCollectCommand} from "./command-impl"; export const collectUserFlowsCommand: YargsCommandObject = { command: 'collect', description: 'Run a set of user flows and save the result', - builder: (y) => y.options(COLLECT_OPTIONS), + builder: (y) => y.options(collectOptions), module: { handler: async (argv: any) => { logVerbose(`run "collect" as a yargs command with args:`); diff --git a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts b/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts index 1dd918b54..309c4daff 100644 --- a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts +++ b/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts @@ -1,18 +1,8 @@ -import { argv } from 'yargs'; -import { Param } from './awaitServeStdout.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -// inspired by: https://github.com/GoogleChrome/lighthouse-ci/blob/main/packages/cli/src/collect/collect.js#L28-L98 -export const param: Param = { - awaitServeStdout: { - alias: 'w', - type: 'string', - description: 'A string in stdou resulting from serving the app, to be awaited before start running the tests. e.g. "server running..."', - implies: ['w', 'serveCommand'] - } -}; - -export function get(): string { - const { awaitServeStdout } = argv as any as ArgvOption; - return awaitServeStdout; -} +export const awaitServeStdout = { + alias: 'w', + type: 'string', + description: 'A string in stdou resulting from serving the app, to be awaited before start running the tests. e.g. "server running..."', + implies: ['w', 'serveCommand'] +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/configPath.ts b/packages/cli/src/lib/commands/collect/options/configPath.ts index c0216bd91..7797aae12 100644 --- a/packages/cli/src/lib/commands/collect/options/configPath.ts +++ b/packages/cli/src/lib/commands/collect/options/configPath.ts @@ -1,16 +1,7 @@ -import { argv } from 'yargs'; -import { Param } from './configPath.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -export const param: Param = { - configPath: { - alias: 'c', - type: 'string', - description: 'Path to Lighthouse configuration e.g config.json' - } -}; - -export function get(): string { - const { configPath } = argv as any as ArgvOption; - return configPath; -} +export const configPath = { + alias: 'c', + type: 'string', + description: 'Path to Lighthouse configuration e.g config.json' +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/dryRun.ts b/packages/cli/src/lib/commands/collect/options/dryRun.ts index 3b7c61fd2..3ce84e914 100644 --- a/packages/cli/src/lib/commands/collect/options/dryRun.ts +++ b/packages/cli/src/lib/commands/collect/options/dryRun.ts @@ -1,16 +1,14 @@ -import { argv } from 'yargs'; +import { argv, Options } from 'yargs'; import { Param } from './dryRun.model'; import { ArgvOption } from '../../../core/yargs/types'; import { getEnvPreset } from '../../../pre-set'; -export const param: Param = { - dryRun: { - alias: 'd', - type: 'boolean', - description: 'Execute commands without effects', - default: getEnvPreset().dryRun as boolean - } -}; +export const dryRun = { + alias: 'd', + type: 'boolean', + description: 'Execute commands without effects', + default: getEnvPreset().dryRun as boolean +} satisfies Options; export function get(): boolean { const { dryRun } = argv as any as ArgvOption; diff --git a/packages/cli/src/lib/commands/collect/options/format.ts b/packages/cli/src/lib/commands/collect/options/format.ts index 7add0bdd1..793e14c3a 100644 --- a/packages/cli/src/lib/commands/collect/options/format.ts +++ b/packages/cli/src/lib/commands/collect/options/format.ts @@ -1,23 +1,10 @@ -import { argv } from 'yargs'; -import { Param } from './format.model'; -import { getEnvPreset } from '../../../pre-set'; -import { PersistRcOptions } from './types'; +import { Options } from 'yargs'; import { REPORT_FORMAT_VALUES } from '../constants'; -// @ts-ignore -// @ts-ignore -export const param: Param = { - format: { - alias: 'f', - type: 'array', - string: true, - description: 'Report output formats e.g. JSON', - choices: REPORT_FORMAT_VALUES, - //default: (getEnvPreset() as any).format - } -}; - -export function get(): string[] { - const { format } = argv as unknown as PersistRcOptions; - return format as string[]; -} +export const format = { + alias: 'f', + type: 'array', + string: true, + description: 'Report output formats e.g. JSON', + choices: REPORT_FORMAT_VALUES, +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/index.ts b/packages/cli/src/lib/commands/collect/options/index.ts index 99af13147..fd4b95185 100644 --- a/packages/cli/src/lib/commands/collect/options/index.ts +++ b/packages/cli/src/lib/commands/collect/options/index.ts @@ -1,29 +1,28 @@ -import { CollectYargsOptions, PersistYargsOptions } from './types'; -import { AssertYargsOptions } from '../../assert/options/types'; -import { param as openReport } from './openReport'; -import { param as ufPath } from './ufPath'; -import { param as configPath } from './configPath'; -import { param as outPath } from './outPath'; -import { param as url } from './url'; -import { param as format } from './format'; -import { param as serveCommand } from './serveCommand'; -import { param as awaitServeStdout } from './awaitServeStdout'; -import { param as dryRun } from './dryRun'; +import { Options } from 'yargs'; +import { openReport } from './openReport'; +import { ufPath } from './ufPath'; +import { configPath } from './configPath'; +import { outPath } from './outPath'; +import { url } from './url'; +import { format } from './format'; +import { serveCommand } from './serveCommand'; +import { awaitServeStdout } from './awaitServeStdout'; +import { dryRun } from './dryRun'; import { assertOptions } from '../../assert/options'; -export const PERSIST_OPTIONS: PersistYargsOptions = { - ...outPath, - ...format, - ...openReport -}; +export const persistOptions = { + outPath, + format, + openReport +} satisfies Record; -export const COLLECT_OPTIONS: CollectYargsOptions & AssertYargsOptions = { - ...url, - ...ufPath, - ...configPath, - ...serveCommand, - ...awaitServeStdout, - ...dryRun, - ...PERSIST_OPTIONS, +export const collectOptions = { + url, + ufPath, + configPath, + serveCommand, + awaitServeStdout, + dryRun, + ...persistOptions, ...assertOptions -}; +} satisfies Record; diff --git a/packages/cli/src/lib/commands/collect/options/openReport.ts b/packages/cli/src/lib/commands/collect/options/openReport.ts index 49e1025c5..d0728c63d 100644 --- a/packages/cli/src/lib/commands/collect/options/openReport.ts +++ b/packages/cli/src/lib/commands/collect/options/openReport.ts @@ -1,17 +1,15 @@ -import { argv } from 'yargs'; +import { argv, Options } from 'yargs'; import { Param } from './openReport.model'; import { ArgvOption } from '../../../core/yargs/types'; import { getEnvPreset } from '../../../pre-set'; -export const param: Param = { - openReport: { - alias: 'e', - type: 'boolean', - description: 'Opens browser automatically after the user-flow is collected. (true by default)', - default: getEnvPreset().openReport as boolean, - requiresArg: true - } -}; +export const openReport = { + alias: 'e', + type: 'boolean', + description: 'Opens browser automatically after the user-flow is collected. (true by default)', + default: getEnvPreset().openReport as boolean, + requiresArg: true +} satisfies Options; export function get(): boolean { const { openReport } = argv as any as ArgvOption; diff --git a/packages/cli/src/lib/commands/collect/options/outPath.ts b/packages/cli/src/lib/commands/collect/options/outPath.ts index 07ae1db7f..11250cd1e 100644 --- a/packages/cli/src/lib/commands/collect/options/outPath.ts +++ b/packages/cli/src/lib/commands/collect/options/outPath.ts @@ -1,16 +1,7 @@ -import { argv, Options } from 'yargs'; -import { Param } from './outPath.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -export const param: Param = { - outPath: { - alias: 'o', - type: 'string', - description: 'output folder for the user-flow reports' - } -}; - -export function get(): string { - const { outPath } = argv as any as ArgvOption; - return outPath; -} +export const outPath = { + alias: 'o', + type: 'string', + description: 'output folder for the user-flow reports' +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/serveCommand.ts b/packages/cli/src/lib/commands/collect/options/serveCommand.ts index c8c5f95da..5b6713008 100644 --- a/packages/cli/src/lib/commands/collect/options/serveCommand.ts +++ b/packages/cli/src/lib/commands/collect/options/serveCommand.ts @@ -1,18 +1,7 @@ -import { argv } from 'yargs'; -import { Param } from './serveCommand.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -// inspired by: https://github.com/GoogleChrome/lighthouse-ci/blob/main/packages/cli/src/collect/collect.js#L28-L98 -export const param: Param = { - serveCommand: { - alias: 's', - type: 'string', - description: 'The npm command to serve your application. e.g. "npm run serve:prod"', - // demandOption: true - } -}; - -export function get(): string { - const { serveCommand } = argv as any as ArgvOption; - return serveCommand; -} +export const serveCommand = { + alias: 's', + type: 'string', + description: 'The npm command to serve your application. e.g. "npm run serve:prod"', +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/ufPath.ts b/packages/cli/src/lib/commands/collect/options/ufPath.ts index 064f9e8dc..e8a01275e 100644 --- a/packages/cli/src/lib/commands/collect/options/ufPath.ts +++ b/packages/cli/src/lib/commands/collect/options/ufPath.ts @@ -1,16 +1,7 @@ -import { argv, Options } from 'yargs'; -import { Param } from './ufPath.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -export const param: Param = { - ufPath: { - alias: 'u', - type: 'string', - description: 'folder containing user-flow files to run. (`*.uf.ts` or `*.uf.js`)' - } -}; - -export function get(): string { - const { ufPath } = argv as any as ArgvOption; - return ufPath; -} +export const ufPath = { + alias: 'u', + type: 'string', + description: 'folder containing user-flow files to run. (`*.uf.ts` or `*.uf.js`)' +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/url.ts b/packages/cli/src/lib/commands/collect/options/url.ts index 235bbb077..4fb4f50d6 100644 --- a/packages/cli/src/lib/commands/collect/options/url.ts +++ b/packages/cli/src/lib/commands/collect/options/url.ts @@ -1,17 +1,7 @@ -import { argv } from 'yargs'; -import { Param } from './url.model'; -import { ArgvOption } from '../../../core/yargs/types'; +import { Options } from 'yargs'; -export const param: Param = { - url: { - alias: 't', - type: 'string', - description: 'URL to analyze', - // demandOption: true - } -}; - -export function get(): string { - const { url } = argv as any as ArgvOption; - return url; -} +export const url = { + alias: 't', + type: 'string', + description: 'URL to analyze', +} satisfies Options; diff --git a/packages/cli/src/lib/commands/init/index.ts b/packages/cli/src/lib/commands/init/index.ts index db25fa99c..e3ae6f867 100644 --- a/packages/cli/src/lib/commands/init/index.ts +++ b/packages/cli/src/lib/commands/init/index.ts @@ -1,21 +1,12 @@ import { YargsCommandObject } from '../../core/yargs/types'; -import { log, logVerbose } from '../../core/loggin'; -import { INIT_OPTIONS } from './options'; -import { getInitCommandOptionsFromArgv } from './utils'; -import { collectRcJson } from './processes/collect-rc-json'; -import { run } from '../../core/processing/behaviors'; -import { SETUP_CONFIRM_MESSAGE } from './constants'; -import { updateRcJson } from './processes/update-rc-json'; -import { handleFlowGeneration } from './processes/generate-userflow'; -import { getGlobalOptionsFromArgv } from '../../global/utils'; -import { handleGhWorkflowGeneration } from './processes/generate-workflow'; -import { handleBudgetsGeneration } from './processes/generate-lh-budgets'; -import {runInitCommand} from "./command-impl"; +import { logVerbose } from '../../core/loggin'; +import { initOptions } from './options'; +import { runInitCommand } from './command-impl'; export const initCommand: YargsCommandObject = { command: 'init', description: 'Setup .user-flowrc.json', - builder: (y) => y.options(INIT_OPTIONS), + builder: (y) => y.options(initOptions), module: { handler: async (argv: any) => { logVerbose(`run "init" as a yargs command`); diff --git a/packages/cli/src/lib/commands/init/options.ts b/packages/cli/src/lib/commands/init/options.ts new file mode 100644 index 000000000..3ef8a1cd9 --- /dev/null +++ b/packages/cli/src/lib/commands/init/options.ts @@ -0,0 +1,9 @@ +import { CollectYargsOptions } from '../collect/options/types'; +import { AssertYargsOptions } from '../assert/options/types'; +import { collectOptions } from '../collect/options'; +import { assertOptions } from '../assert/options'; + +export const initOptions: CollectYargsOptions & AssertYargsOptions = { + ...collectOptions, + ...assertOptions +}; diff --git a/packages/cli/src/lib/commands/init/options/index.ts b/packages/cli/src/lib/commands/init/options/index.ts deleted file mode 100644 index be1c86413..000000000 --- a/packages/cli/src/lib/commands/init/options/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { AssertYargsOptions } from '../../assert/options/types'; -import { assertOptions } from '../../assert/options'; -import { COLLECT_OPTIONS } from '../../collect/options'; -import { CollectYargsOptions } from '../../collect/options/types'; - -export const INIT_OPTIONS: CollectYargsOptions & AssertYargsOptions = { - ...COLLECT_OPTIONS, - ...assertOptions -}; diff --git a/packages/cli/src/lib/commands/init/options/types.ts b/packages/cli/src/lib/commands/init/options/types.ts index 62fda9336..54ec97609 100644 --- a/packages/cli/src/lib/commands/init/options/types.ts +++ b/packages/cli/src/lib/commands/init/options/types.ts @@ -1,14 +1,5 @@ -import { AssertRcOptions, AssertYargsOptions } from '../../assert/options/types'; -import { - CollectCliOnlyOptions, - CollectRcOptions, - CollectYargsOptions, PersistCliOnlyOptions, PersistRcOptions, - PersistYargsOptions -} from '../../collect/options/types'; -import { YargsArgvOptionFromParamsOptions } from '../../../core/yargs/types'; - -export type InitYargsOptions = CollectYargsOptions & PersistYargsOptions & AssertYargsOptions; - +import { AssertRcOptions } from '../../assert/options/types'; +import { CollectRcOptions, PersistRcOptions } from '../../collect/options/types'; export type InitCliOnlyOptions = { generateFlow?: boolean; @@ -19,10 +10,4 @@ export type InitCliOnlyOptions = { export type InitArgvOptions = CollectRcOptions & PersistRcOptions & AssertRcOptions & InitCliOnlyOptions; -export type InitCommandCfg = { - collect: CollectRcOptions, - persist: PersistRcOptions, - assert?: AssertRcOptions; -} & InitCliOnlyOptions - export type InitCommandArgv = InitArgvOptions; From 99a934ead317fbb21872f70b000c75c2725943c6 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 14:53:13 +0100 Subject: [PATCH 07/24] fix: remove unnecessary patch type errors --- .../cli/src/lib/commands/init/command-impl.ts | 24 +++++++++---------- packages/cli/src/lib/commands/init/options.ts | 3 +++ .../src/lib/commands/init/options/types.ts | 1 - packages/cli/src/lib/index.ts | 1 - .../commands/init/init-configuration.test.ts | 2 +- .../sandbox/e2e/commands/init/init.test.ts | 2 +- .../e2e/commands/init/rc-config.test.ts | 2 +- packages/sandbox/e2e/jest/expect.init.ts | 2 +- .../user-flow-cli-testing/src/lib/types.ts | 10 ++------ .../src/lib/user-flow-cli.ts | 3 +-- 10 files changed, 22 insertions(+), 28 deletions(-) diff --git a/packages/cli/src/lib/commands/init/command-impl.ts b/packages/cli/src/lib/commands/init/command-impl.ts index b74519310..39b9eb579 100644 --- a/packages/cli/src/lib/commands/init/command-impl.ts +++ b/packages/cli/src/lib/commands/init/command-impl.ts @@ -1,15 +1,15 @@ -import {RcJsonAsArgv} from "../../types"; +import { RcJsonAsArgv } from '../../types'; -import {log, logVerbose} from "../../core/loggin"; -import {run} from "../../core/processing/behaviors"; -import {collectRcJson} from "../init/processes/collect-rc-json"; -import {getGlobalOptionsFromArgv} from "../../global/utils"; -import {getInitCommandOptionsFromArgv} from "./utils"; -import {updateRcJson} from "./processes/update-rc-json"; -import {handleFlowGeneration} from "./processes/generate-userflow"; -import {handleGhWorkflowGeneration} from "./processes/generate-workflow"; -import {handleBudgetsGeneration} from "./processes/generate-lh-budgets"; -import {SETUP_CONFIRM_MESSAGE} from "./constants"; +import { log, logVerbose } from '../../core/loggin'; +import { run } from '../../core/processing/behaviors'; +import { collectRcJson } from './processes/collect-rc-json'; +import { getGlobalOptionsFromArgv } from '../../global/utils'; +import { getInitCommandOptionsFromArgv } from './utils'; +import { updateRcJson } from './processes/update-rc-json'; +import { handleFlowGeneration } from './processes/generate-userflow'; +import { handleGhWorkflowGeneration } from './processes/generate-workflow'; +import { handleBudgetsGeneration } from './processes/generate-lh-budgets'; +import { SETUP_CONFIRM_MESSAGE } from './constants'; export async function runInitCommand(argv: RcJsonAsArgv) { const { interactive } = getGlobalOptionsFromArgv(argv); @@ -22,7 +22,7 @@ export async function runInitCommand(argv: RcJsonAsArgv) { handleFlowGeneration({ interactive: !!interactive, generateFlow }), handleGhWorkflowGeneration({ generateGhWorkflow }), handleBudgetsGeneration({ generateBudgets, lhr }), - ])(cfg ); + ])(cfg); log(SETUP_CONFIRM_MESSAGE); // @TODO move to constants log('To execute a user flow run `npx user-flow` or `npx user-flow collect`'); diff --git a/packages/cli/src/lib/commands/init/options.ts b/packages/cli/src/lib/commands/init/options.ts index 3ef8a1cd9..0cdf18d40 100644 --- a/packages/cli/src/lib/commands/init/options.ts +++ b/packages/cli/src/lib/commands/init/options.ts @@ -2,8 +2,11 @@ import { CollectYargsOptions } from '../collect/options/types'; import { AssertYargsOptions } from '../assert/options/types'; import { collectOptions } from '../collect/options'; import { assertOptions } from '../assert/options'; +import { InferredOptionTypes } from 'yargs'; export const initOptions: CollectYargsOptions & AssertYargsOptions = { ...collectOptions, ...assertOptions }; + +export type InitOptions = InferredOptionTypes; diff --git a/packages/cli/src/lib/commands/init/options/types.ts b/packages/cli/src/lib/commands/init/options/types.ts index 54ec97609..51496e931 100644 --- a/packages/cli/src/lib/commands/init/options/types.ts +++ b/packages/cli/src/lib/commands/init/options/types.ts @@ -10,4 +10,3 @@ export type InitCliOnlyOptions = { export type InitArgvOptions = CollectRcOptions & PersistRcOptions & AssertRcOptions & InitCliOnlyOptions; -export type InitCommandArgv = InitArgvOptions; diff --git a/packages/cli/src/lib/index.ts b/packages/cli/src/lib/index.ts index e40a19730..bbc3d90ad 100644 --- a/packages/cli/src/lib/index.ts +++ b/packages/cli/src/lib/index.ts @@ -19,7 +19,6 @@ export { RcJson } from './types'; export { CLI_MODES, CI_PROPERTY, CLI_MODE_PROPERTY } from './global/cli-mode'; export { LhConfigJson } from './hacky-things/lighthouse'; export { getEnvPreset, SANDBOX_PRESET, CI_PRESET, DEFAULT_PRESET } from './pre-set'; -export { InitCommandArgv } from './commands/init/options/types'; export { GlobalOptionsArgv } from './global/options/types'; export { CollectCommandArgv, CollectArgvOptions } from './commands/collect/options/types'; export { DEFAULT_RC_NAME } from './constants'; diff --git a/packages/sandbox/e2e/commands/init/init-configuration.test.ts b/packages/sandbox/e2e/commands/init/init-configuration.test.ts index 95393b25c..6c9cadc92 100644 --- a/packages/sandbox/e2e/commands/init/init-configuration.test.ts +++ b/packages/sandbox/e2e/commands/init/init-configuration.test.ts @@ -92,7 +92,7 @@ describe('init command configuration in setup sandbox', () => { format, // -- assert budgetPath - }, + } as any, ['n'] ); diff --git a/packages/sandbox/e2e/commands/init/init.test.ts b/packages/sandbox/e2e/commands/init/init.test.ts index 73141c761..3a9f7efc2 100644 --- a/packages/sandbox/e2e/commands/init/init.test.ts +++ b/packages/sandbox/e2e/commands/init/init.test.ts @@ -53,7 +53,7 @@ describe('init command in empty sandbox', () => { const { exitCode, stdout, stderr } = await emptyPrj.$init({ interactive: false, url: '' - }); + } as any); expect(stderr).toContain('URL is required'); expect(exitCode).toBe(1); diff --git a/packages/sandbox/e2e/commands/init/rc-config.test.ts b/packages/sandbox/e2e/commands/init/rc-config.test.ts index c2c2d9bac..5020dade7 100644 --- a/packages/sandbox/e2e/commands/init/rc-config.test.ts +++ b/packages/sandbox/e2e/commands/init/rc-config.test.ts @@ -143,7 +143,7 @@ describe('.rc.json in initialized sandbox', () => { const { exitCode, stdout, stderr } = await initializedPrj.$init({ interactive: false, format: [wrongFormat as any] - }); + } as any); // Assertions diff --git a/packages/sandbox/e2e/jest/expect.init.ts b/packages/sandbox/e2e/jest/expect.init.ts index aebc2ecf2..40dafd01c 100644 --- a/packages/sandbox/e2e/jest/expect.init.ts +++ b/packages/sandbox/e2e/jest/expect.init.ts @@ -4,7 +4,7 @@ import { PROMPT_PERSIST_FORMAT, PROMPT_PERSIST_OUT_PATH } from '@push-based/user-flow'; -import { PROMPT_INIT_GENERATE_FLOW } from '../../../cli/src/lib/commands/init/options/generateFlow.constants'; +import { PROMPT_INIT_GENERATE_FLOW } from '@push-based/user-flow/src/lib/commands/init/options/generateFlow.constants'; export function expectInitOptionsToBeContainedInStdout(stdout: string, cliParams: {}) { expect(stdout).toContain(`Init options:`); diff --git a/packages/user-flow-cli-testing/src/lib/types.ts b/packages/user-flow-cli-testing/src/lib/types.ts index 50a852472..1c6c0a2be 100644 --- a/packages/user-flow-cli-testing/src/lib/types.ts +++ b/packages/user-flow-cli-testing/src/lib/types.ts @@ -1,5 +1,5 @@ -import { ExecFn, Project, ProjectConfig } from '@push-based/node-cli-testing'; -import { CLI_MODES, CollectCommandArgv, GlobalOptionsArgv, InitCommandArgv, RcJson } from '@push-based/user-flow'; +import { ProjectConfig } from '@push-based/node-cli-testing'; +import { CLI_MODES, RcJson } from '@push-based/user-flow'; export { RcJson, @@ -10,12 +10,6 @@ export { ReportFormat } from '@push-based/user-flow'; -export type UserFlowProject = Project & { - $init: ExecFn>, - $collect: ExecFn>, - readRcJson: (name: string) => string -} - export type UserFlowProjectConfig = ProjectConfig & UserFlowOnlyProjectConfig; export type UserFlowOnlyProjectConfig = { cliMode?: CLI_MODES, diff --git a/packages/user-flow-cli-testing/src/lib/user-flow-cli.ts b/packages/user-flow-cli-testing/src/lib/user-flow-cli.ts index 953d1d5d7..cf889c3d0 100644 --- a/packages/user-flow-cli-testing/src/lib/user-flow-cli.ts +++ b/packages/user-flow-cli-testing/src/lib/user-flow-cli.ts @@ -7,7 +7,6 @@ import { DEFAULT_PERSIST_OUT_PATH, getEnvPreset, GlobalOptionsArgv, - InitCommandArgv, LhConfigJson, RcJson, ReportFormat @@ -73,7 +72,7 @@ export class UserFlowCliProject extends CliProject { await kill({ port: this.serveCommandPort }); } - $init(processParams?: Partial, userInput?: string[]): Promise { + $init(processParams?: Partial<{} & GlobalOptionsArgv>, userInput?: string[]): Promise { const prcParams: ProcessParams = { _: 'init', ...processParams } as unknown as ProcessParams; // If a rcFile is created delete it on teardown this.deleteFiles.push(prcParams['rcPath'] || this.envPreset?.rcPath); From c89d84c6c3a85105648945bf5df9c45f57b31662 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 14:53:50 +0100 Subject: [PATCH 08/24] fix: remove unnecessary patch type errors --- packages/sandbox/e2e/commands/init/rc-config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sandbox/e2e/commands/init/rc-config.test.ts b/packages/sandbox/e2e/commands/init/rc-config.test.ts index 5020dade7..1102c3bb6 100644 --- a/packages/sandbox/e2e/commands/init/rc-config.test.ts +++ b/packages/sandbox/e2e/commands/init/rc-config.test.ts @@ -176,7 +176,7 @@ describe('.rc.json in initialized sandbox', () => { // persist outPath, format: [htmlFormat] - }, + } as any, ['n']); // Assertions From 5909e2b403f376568247db96747582f8c5952be9 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 15:00:12 +0100 Subject: [PATCH 09/24] fix: remove unnecessary patch type errors --- packages/cli/src/lib/commands/init/options.ts | 10 +++------- packages/sandbox/e2e/commands/init/init.test.ts | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/lib/commands/init/options.ts b/packages/cli/src/lib/commands/init/options.ts index 0cdf18d40..c8708e10d 100644 --- a/packages/cli/src/lib/commands/init/options.ts +++ b/packages/cli/src/lib/commands/init/options.ts @@ -1,12 +1,8 @@ -import { CollectYargsOptions } from '../collect/options/types'; -import { AssertYargsOptions } from '../assert/options/types'; +import { Options } from 'yargs'; import { collectOptions } from '../collect/options'; import { assertOptions } from '../assert/options'; -import { InferredOptionTypes } from 'yargs'; -export const initOptions: CollectYargsOptions & AssertYargsOptions = { +export const initOptions = { ...collectOptions, ...assertOptions -}; - -export type InitOptions = InferredOptionTypes; +} satisfies Record; diff --git a/packages/sandbox/e2e/commands/init/init.test.ts b/packages/sandbox/e2e/commands/init/init.test.ts index 3a9f7efc2..4153b0c07 100644 --- a/packages/sandbox/e2e/commands/init/init.test.ts +++ b/packages/sandbox/e2e/commands/init/init.test.ts @@ -107,7 +107,7 @@ describe('init command in setup sandbox', () => { const workflowPath = join(process.cwd(),expectedFilePath); expect(existsSync(workflowPath)).toBeFalsy(); - const { exitCode, stderr } = await prj.$init({ generateGhWorkflow: true }); + const { exitCode, stderr } = await prj.$init({ generateGhWorkflow: true } as any); expect(existsSync(workflowPath)).toBeTruthy(); expect(stderr).toBe(''); expect(exitCode).toBe(0); From 47533207687024d2a8a94af05f29111fbeef51b3 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 15:31:56 +0100 Subject: [PATCH 10/24] fix: remove unnecessary patch type errors --- .../src/lib/commands/collect/command-impl.ts | 17 ++++++----- .../cli/src/lib/commands/collect/index.ts | 8 ++--- .../src/lib/commands/collect/options/index.ts | 3 +- .../src/lib/commands/collect/options/types.ts | 3 -- .../src/lib/commands/collect/utils/params.ts | 8 ++--- .../cli/src/lib/commands/init/command-impl.ts | 3 +- .../cli/src/lib/commands/init/constants.ts | 14 ++++----- packages/cli/src/lib/commands/init/options.ts | 29 ++++++++++++++++++- .../src/lib/commands/init/options/types.ts | 12 -------- .../init/processes/generate-userflow.ts | 14 ++++----- .../init/processes/generate-workflow.ts | 13 ++++----- packages/cli/src/lib/commands/init/types.ts | 3 -- packages/cli/src/lib/commands/init/utils.ts | 8 ++--- 13 files changed, 68 insertions(+), 67 deletions(-) delete mode 100644 packages/cli/src/lib/commands/init/options/types.ts delete mode 100644 packages/cli/src/lib/commands/init/types.ts diff --git a/packages/cli/src/lib/commands/collect/command-impl.ts b/packages/cli/src/lib/commands/collect/command-impl.ts index a62d6befd..ea3a149e1 100644 --- a/packages/cli/src/lib/commands/collect/command-impl.ts +++ b/packages/cli/src/lib/commands/collect/command-impl.ts @@ -1,12 +1,13 @@ -import {RcJson, RcJsonAsArgv} from "../../types"; -import {getCollectCommandOptionsFromArgv} from "./utils/params"; -import {logVerbose} from "../../core/loggin"; -import {run} from "../../core/processing/behaviors"; -import {collectRcJson} from "../init/processes/collect-rc-json"; -import {startServerIfNeededAndExecute} from "./utils/serve-command"; -import {collectReports} from "./processes/collect-reports"; +import { RcJson } from '../../types'; +import { getCollectCommandOptionsFromArgv } from './utils/params'; +import { logVerbose } from '../../core/loggin'; +import { run } from '../../core/processing/behaviors'; +import { collectRcJson } from '../init/processes/collect-rc-json'; +import { startServerIfNeededAndExecute } from './utils/serve-command'; +import { collectReports } from './processes/collect-reports'; +import { CollectOptions } from './options'; -export async function runCollectCommand(argv: RcJsonAsArgv) { +export async function runCollectCommand(argv: CollectOptions): Promise { const cfg = getCollectCommandOptionsFromArgv(argv); logVerbose('Collect options: ', cfg); await run([ diff --git a/packages/cli/src/lib/commands/collect/index.ts b/packages/cli/src/lib/commands/collect/index.ts index 16e16214b..9bc34eee1 100644 --- a/packages/cli/src/lib/commands/collect/index.ts +++ b/packages/cli/src/lib/commands/collect/index.ts @@ -1,7 +1,7 @@ -import {YargsCommandObject} from '../../core/yargs/types'; -import {logVerbose} from '../../core/loggin/index'; -import {collectOptions} from './options'; -import {runCollectCommand} from "./command-impl"; +import { YargsCommandObject } from '../../core/yargs/types'; +import { logVerbose } from '../../core/loggin/index'; +import { collectOptions } from './options'; +import { runCollectCommand } from './command-impl'; export const collectUserFlowsCommand: YargsCommandObject = { command: 'collect', diff --git a/packages/cli/src/lib/commands/collect/options/index.ts b/packages/cli/src/lib/commands/collect/options/index.ts index fd4b95185..8d8c08e09 100644 --- a/packages/cli/src/lib/commands/collect/options/index.ts +++ b/packages/cli/src/lib/commands/collect/options/index.ts @@ -1,4 +1,4 @@ -import { Options } from 'yargs'; +import { InferredOptionTypes, Options } from 'yargs'; import { openReport } from './openReport'; import { ufPath } from './ufPath'; import { configPath } from './configPath'; @@ -26,3 +26,4 @@ export const collectOptions = { ...persistOptions, ...assertOptions } satisfies Record; +export type CollectOptions = InferredOptionTypes; diff --git a/packages/cli/src/lib/commands/collect/options/types.ts b/packages/cli/src/lib/commands/collect/options/types.ts index 87f2b1677..8ac21b2aa 100644 --- a/packages/cli/src/lib/commands/collect/options/types.ts +++ b/packages/cli/src/lib/commands/collect/options/types.ts @@ -8,9 +8,6 @@ import { Param as Format } from './format.model'; import { AssertArgvOptions } from '../../assert/options/types'; import { LhConfigJson } from '../../../hacky-things/lighthouse'; -export type PersistYargsOptions = OpenReport & OutPath & Format; -export type CollectYargsOptions = UfPath & OutPath & Url & ServeCommand & AwaitServeStdout; - export type CollectRcOptions = { url: string, ufPath: string, diff --git a/packages/cli/src/lib/commands/collect/utils/params.ts b/packages/cli/src/lib/commands/collect/utils/params.ts index e2be248e4..bd15464a4 100644 --- a/packages/cli/src/lib/commands/collect/utils/params.ts +++ b/packages/cli/src/lib/commands/collect/utils/params.ts @@ -6,14 +6,10 @@ import { PersistRcOptions } from '../options/types'; import { AssertArgvOptions } from '../../assert/options/types'; -import { RcJsonAsArgv } from '../../../types'; +import { CollectOptions } from '../options'; -export function getArgvOptionsFromRc(cfg: CollectCommandCfg): RcJsonAsArgv { - const { collect, persist, assert } = cfg; - return { ...collect, ...persist, ...assert } as RcJsonAsArgv; -} -export function getCollectCommandOptionsFromArgv(argv: RcJsonAsArgv): CollectCommandCfg { +export function getCollectCommandOptionsFromArgv(argv: CollectOptions): CollectCommandCfg { const { url, ufPath, serveCommand, awaitServeStdout, dryRun, openReport, diff --git a/packages/cli/src/lib/commands/init/command-impl.ts b/packages/cli/src/lib/commands/init/command-impl.ts index 39b9eb579..eef81d249 100644 --- a/packages/cli/src/lib/commands/init/command-impl.ts +++ b/packages/cli/src/lib/commands/init/command-impl.ts @@ -10,8 +10,9 @@ import { handleFlowGeneration } from './processes/generate-userflow'; import { handleGhWorkflowGeneration } from './processes/generate-workflow'; import { handleBudgetsGeneration } from './processes/generate-lh-budgets'; import { SETUP_CONFIRM_MESSAGE } from './constants'; +import { InitOptions } from './options'; -export async function runInitCommand(argv: RcJsonAsArgv) { +export async function runInitCommand(argv: InitOptions): Promise { const { interactive } = getGlobalOptionsFromArgv(argv); const { generateFlow, generateGhWorkflow, generateBudgets, lhr, ...cfg } = getInitCommandOptionsFromArgv(argv); logVerbose('Init options: ', { interactive, generateFlow, generateGhWorkflow, generateBudgets,lhr, ...cfg }); diff --git a/packages/cli/src/lib/commands/init/constants.ts b/packages/cli/src/lib/commands/init/constants.ts index e4d770ec2..238d7f5e4 100644 --- a/packages/cli/src/lib/commands/init/constants.ts +++ b/packages/cli/src/lib/commands/init/constants.ts @@ -1,15 +1,13 @@ -import { FlowExamples, GhWorkflowExamples, BudgetsExamples } from './types'; - export const SETUP_CONFIRM_MESSAGE = 'user-flow CLI is set up now! 🎉'; -export const FlowExampleMap: Record = { +export const FlowExampleMap = { 'basic-navigation': 'basic-navigation.uf.ts' -}; -export const GhWorkflowExampleMap: Record = { +} as const; +export const GhWorkflowExampleMap = { 'basic-workflow': 'user-flow-ci.yml' -}; -export const BudgetsExampleMap: Record = { +} as const; +export const BudgetsExampleMap = { 'budgets': 'lh-budgets.json' -}; +} as const; export const TransferSizeResourceTypeBudgets: string[] = [ 'xhr', 'script', diff --git a/packages/cli/src/lib/commands/init/options.ts b/packages/cli/src/lib/commands/init/options.ts index c8708e10d..6f2ecd99a 100644 --- a/packages/cli/src/lib/commands/init/options.ts +++ b/packages/cli/src/lib/commands/init/options.ts @@ -1,8 +1,35 @@ -import { Options } from 'yargs'; +import { InferredOptionTypes, Options } from 'yargs'; import { collectOptions } from '../collect/options'; import { assertOptions } from '../assert/options'; +const generateFlow = { + alias: 'h', + type: 'boolean', + description: 'Create as user flow under "ufPath"' +} satisfies Options; + +const generateGhWorkflow = { + alias: 'g', + type: 'boolean', + description: 'Create a workflow using user-flow under .github/workflows' +} satisfies Options; + +const generateBudgets = { + type: 'boolean', + description: 'Create a budgets file' +} satisfies Options; + +const lhr = { + type: 'string', + description: 'Should derive budget from path', +} satisfies Options; + export const initOptions = { + generateFlow, + generateGhWorkflow, + generateBudgets, + lhr, ...collectOptions, ...assertOptions } satisfies Record; +export type InitOptions = InferredOptionTypes; diff --git a/packages/cli/src/lib/commands/init/options/types.ts b/packages/cli/src/lib/commands/init/options/types.ts deleted file mode 100644 index 51496e931..000000000 --- a/packages/cli/src/lib/commands/init/options/types.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { AssertRcOptions } from '../../assert/options/types'; -import { CollectRcOptions, PersistRcOptions } from '../../collect/options/types'; - -export type InitCliOnlyOptions = { - generateFlow?: boolean; - generateGhWorkflow?: boolean; - generateBudgets?: boolean; - lhr?: string; -} - -export type InitArgvOptions = CollectRcOptions & PersistRcOptions & AssertRcOptions & InitCliOnlyOptions; - diff --git a/packages/cli/src/lib/commands/init/processes/generate-userflow.ts b/packages/cli/src/lib/commands/init/processes/generate-userflow.ts index 8c406ae64..03901ecb5 100644 --- a/packages/cli/src/lib/commands/init/processes/generate-userflow.ts +++ b/packages/cli/src/lib/commands/init/processes/generate-userflow.ts @@ -1,23 +1,21 @@ -import { RcJson } from '../../../types'; import { join } from 'node:path'; -import { readFile, writeFile } from '../../../core/file'; -import { log } from '../../../core/loggin'; import { mkdirSync, readdirSync } from 'node:fs'; +import { RcJson } from '../../../types'; +import { readFile, writeFile } from '../../../core/file'; +import { log, logVerbose } from '../../../core/loggin'; import { FlowExampleMap, PROMPT_INIT_GENERATE_FLOW } from '../constants'; -import { FlowExamples } from '../types'; import { ifThenElse } from '../../../core/processing/behaviors'; import { askToSkip } from '../../../core/prompt'; import { CLIProcess } from '../../../core/processing/types'; -import { logVerbose } from '../../../core/loggin'; const exampleName = 'basic-navigation'; -export function getExamplePathDest(flowExample: FlowExamples, folder: string): string { - const fileName = FlowExampleMap[flowExample]; +export function getExamplePathDest(folder: string): string { + const fileName = FlowExampleMap[exampleName]; return join(folder, fileName); } -export const userflowIsNotCreated = (cfg?: RcJson) => Promise.resolve(cfg ? readFile(getExamplePathDest(exampleName, cfg.collect.ufPath)) === '' : false); +export const userflowIsNotCreated = (cfg?: RcJson) => Promise.resolve(cfg ? readFile(getExamplePathDest(cfg.collect.ufPath)) === '' : false); export async function generateUserFlow(cliCfg: RcJson): Promise { const ufPath = cliCfg.collect.ufPath; diff --git a/packages/cli/src/lib/commands/init/processes/generate-workflow.ts b/packages/cli/src/lib/commands/init/processes/generate-workflow.ts index ab360e4fd..1e69f4362 100644 --- a/packages/cli/src/lib/commands/init/processes/generate-workflow.ts +++ b/packages/cli/src/lib/commands/init/processes/generate-workflow.ts @@ -2,29 +2,26 @@ import { RcJson } from '../../../types'; import { join } from 'path'; import { readFile, writeFile } from '../../../core/file'; import { log, logVerbose } from '../../../core/loggin'; -import { mkdirSync, existsSync } from 'fs'; +import { existsSync, mkdirSync } from 'fs'; import { GhWorkflowExampleMap } from '../constants'; -import { GhWorkflowExamples } from '../types'; import { ifThenElse } from '../../../core/processing/behaviors'; import { CLIProcess } from '../../../core/processing/types'; const exampleName = 'basic-workflow'; const destPath = join('.github', 'workflows'); -export function getExamplePathDest(workflowExample: GhWorkflowExamples): string { - const fileName = GhWorkflowExampleMap[workflowExample]; +export function getExamplePathDest(): string { + const fileName = GhWorkflowExampleMap[exampleName]; if(!fileName) { - throw new Error(`workflowExample ${workflowExample} is not registered`); + throw new Error(`workflowExample ${exampleName} is not registered`); } return join(destPath, fileName); } -export const workflowIsNotCreated = (cfg?: RcJson) => Promise.resolve(cfg ? readFile(getExamplePathDest(exampleName)) === '' : false); - export async function generateGhWorkflowFile(cliCfg: RcJson): Promise { const tplFileName = GhWorkflowExampleMap[exampleName]; const exampleSourceLocation = join(__dirname, '..', 'static', tplFileName); - const exampleDestination = getExamplePathDest(exampleName as any); + const exampleDestination = getExamplePathDest(); if (readFile(exampleDestination) !== '') { logVerbose(`User flow ${exampleName} already generated under ${exampleDestination}.`); diff --git a/packages/cli/src/lib/commands/init/types.ts b/packages/cli/src/lib/commands/init/types.ts deleted file mode 100644 index 827d25b41..000000000 --- a/packages/cli/src/lib/commands/init/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type FlowExamples = 'basic-navigation'; -export type GhWorkflowExamples = 'basic-workflow'; -export type BudgetsExamples = 'budgets'; diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index 009127c4f..ed929f570 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -1,13 +1,13 @@ -import { InitArgvOptions } from './options/types'; import { CollectRcOptions, PersistRcOptions } from '../collect/options/types'; import { AssertRcOptions } from '../assert/options/types'; +import { InitOptions } from './options'; -export function getInitCommandOptionsFromArgv(argv: any) { +export function getInitCommandOptionsFromArgv(argv: InitOptions) { let { generateFlow, generateGhWorkflow, generateBudgets, lhr, url, ufPath, serveCommand, awaitServeStdout, outPath, format, budgetPath, budgets - } = argv as unknown as InitArgvOptions; + } = argv; let collect = {} as CollectRcOptions; url && (collect.url = url); @@ -22,7 +22,7 @@ export function getInitCommandOptionsFromArgv(argv: any) { let assert = {} as AssertRcOptions; budgetPath && (assert.budgetPath = budgetPath); - budgets && (assert.budgets = budgets); + budgets && (assert.budgets = budgets as any); return { collect, persist, assert, generateFlow, generateGhWorkflow, generateBudgets, lhr From dc45f93ca9fdf380cfb464aa940fcea27b7e6c8c Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 15:44:42 +0100 Subject: [PATCH 11/24] fix: remove unnecessary patch type errors --- packages/cli/src/lib/commands/assert/command-impl.ts | 8 +++----- packages/cli/src/lib/commands/collect/index.ts | 2 +- packages/cli/src/lib/commands/collect/options/dryRun.ts | 4 +--- .../cli/src/lib/commands/collect/options/openReport.ts | 4 +--- packages/cli/src/lib/commands/init/command-impl.ts | 4 +--- .../src/lib/commands/init/processes/collect-rc-json.ts | 8 ++++---- .../commands/init/{options => processes}/format.setup.ts | 0 .../commands/init/{options => processes}/outPath.setup.ts | 0 .../commands/init/{options => processes}/ufPath.setup.ts | 0 .../lib/commands/init/{options => processes}/url.setup.ts | 0 packages/cli/src/lib/config.middleware.ts | 7 +++---- packages/cli/src/lib/core/yargs/index.ts | 3 +-- packages/cli/src/lib/core/yargs/types.ts | 1 - packages/cli/src/lib/global/options/interactive.ts | 3 +-- packages/cli/src/lib/global/options/verbose.ts | 1 - 15 files changed, 16 insertions(+), 29 deletions(-) rename packages/cli/src/lib/commands/init/{options => processes}/format.setup.ts (100%) rename packages/cli/src/lib/commands/init/{options => processes}/outPath.setup.ts (100%) rename packages/cli/src/lib/commands/init/{options => processes}/ufPath.setup.ts (100%) rename packages/cli/src/lib/commands/init/{options => processes}/url.setup.ts (100%) diff --git a/packages/cli/src/lib/commands/assert/command-impl.ts b/packages/cli/src/lib/commands/assert/command-impl.ts index 721b087a8..271275ae9 100644 --- a/packages/cli/src/lib/commands/assert/command-impl.ts +++ b/packages/cli/src/lib/commands/assert/command-impl.ts @@ -1,9 +1,7 @@ -import {RcJsonAsArgv} from "../../types"; +import { logVerbose } from '../../core/loggin'; +import { readBudgets } from './utils/budgets'; -import {logVerbose} from "../../core/loggin"; -import {readBudgets} from "./utils/budgets"; - -export async function runAssertCommand(argv: RcJsonAsArgv) { +export async function runAssertCommand() { logVerbose(readBudgets()); return Promise.resolve(); } diff --git a/packages/cli/src/lib/commands/collect/index.ts b/packages/cli/src/lib/commands/collect/index.ts index 9bc34eee1..fda38d991 100644 --- a/packages/cli/src/lib/commands/collect/index.ts +++ b/packages/cli/src/lib/commands/collect/index.ts @@ -1,5 +1,5 @@ import { YargsCommandObject } from '../../core/yargs/types'; -import { logVerbose } from '../../core/loggin/index'; +import { logVerbose } from '../../core/loggin'; import { collectOptions } from './options'; import { runCollectCommand } from './command-impl'; diff --git a/packages/cli/src/lib/commands/collect/options/dryRun.ts b/packages/cli/src/lib/commands/collect/options/dryRun.ts index 3ce84e914..d5a3b8818 100644 --- a/packages/cli/src/lib/commands/collect/options/dryRun.ts +++ b/packages/cli/src/lib/commands/collect/options/dryRun.ts @@ -1,6 +1,4 @@ import { argv, Options } from 'yargs'; -import { Param } from './dryRun.model'; -import { ArgvOption } from '../../../core/yargs/types'; import { getEnvPreset } from '../../../pre-set'; export const dryRun = { @@ -11,6 +9,6 @@ export const dryRun = { } satisfies Options; export function get(): boolean { - const { dryRun } = argv as any as ArgvOption; + const { dryRun } = argv as any as { dryRun: boolean }; return dryRun; } diff --git a/packages/cli/src/lib/commands/collect/options/openReport.ts b/packages/cli/src/lib/commands/collect/options/openReport.ts index d0728c63d..2ee6d6311 100644 --- a/packages/cli/src/lib/commands/collect/options/openReport.ts +++ b/packages/cli/src/lib/commands/collect/options/openReport.ts @@ -1,6 +1,4 @@ import { argv, Options } from 'yargs'; -import { Param } from './openReport.model'; -import { ArgvOption } from '../../../core/yargs/types'; import { getEnvPreset } from '../../../pre-set'; export const openReport = { @@ -12,6 +10,6 @@ export const openReport = { } satisfies Options; export function get(): boolean { - const { openReport } = argv as any as ArgvOption; + const { openReport } = argv as any as { openReport: boolean }; return openReport; } diff --git a/packages/cli/src/lib/commands/init/command-impl.ts b/packages/cli/src/lib/commands/init/command-impl.ts index eef81d249..0bddcf4ba 100644 --- a/packages/cli/src/lib/commands/init/command-impl.ts +++ b/packages/cli/src/lib/commands/init/command-impl.ts @@ -1,5 +1,4 @@ -import { RcJsonAsArgv } from '../../types'; - +import { InitOptions } from './options'; import { log, logVerbose } from '../../core/loggin'; import { run } from '../../core/processing/behaviors'; import { collectRcJson } from './processes/collect-rc-json'; @@ -10,7 +9,6 @@ import { handleFlowGeneration } from './processes/generate-userflow'; import { handleGhWorkflowGeneration } from './processes/generate-workflow'; import { handleBudgetsGeneration } from './processes/generate-lh-budgets'; import { SETUP_CONFIRM_MESSAGE } from './constants'; -import { InitOptions } from './options'; export async function runInitCommand(argv: InitOptions): Promise { const { interactive } = getGlobalOptionsFromArgv(argv); diff --git a/packages/cli/src/lib/commands/init/processes/collect-rc-json.ts b/packages/cli/src/lib/commands/init/processes/collect-rc-json.ts index a9cb16a16..d8b1bb5d0 100644 --- a/packages/cli/src/lib/commands/init/processes/collect-rc-json.ts +++ b/packages/cli/src/lib/commands/init/processes/collect-rc-json.ts @@ -1,7 +1,7 @@ -import { setupUrl } from '../options/url.setup'; -import { setupUfPath } from '../options/ufPath.setup'; -import { setupFormat } from '../options/format.setup'; -import { setupOutPath } from '../options/outPath.setup'; +import { setupUrl } from './url.setup'; +import { setupUfPath } from './ufPath.setup'; +import { setupFormat } from './format.setup'; +import { setupOutPath } from './outPath.setup'; import { RcJson } from '../../../types'; export async function collectRcJson(cliCfg: RcJson): Promise { diff --git a/packages/cli/src/lib/commands/init/options/format.setup.ts b/packages/cli/src/lib/commands/init/processes/format.setup.ts similarity index 100% rename from packages/cli/src/lib/commands/init/options/format.setup.ts rename to packages/cli/src/lib/commands/init/processes/format.setup.ts diff --git a/packages/cli/src/lib/commands/init/options/outPath.setup.ts b/packages/cli/src/lib/commands/init/processes/outPath.setup.ts similarity index 100% rename from packages/cli/src/lib/commands/init/options/outPath.setup.ts rename to packages/cli/src/lib/commands/init/processes/outPath.setup.ts diff --git a/packages/cli/src/lib/commands/init/options/ufPath.setup.ts b/packages/cli/src/lib/commands/init/processes/ufPath.setup.ts similarity index 100% rename from packages/cli/src/lib/commands/init/options/ufPath.setup.ts rename to packages/cli/src/lib/commands/init/processes/ufPath.setup.ts diff --git a/packages/cli/src/lib/commands/init/options/url.setup.ts b/packages/cli/src/lib/commands/init/processes/url.setup.ts similarity index 100% rename from packages/cli/src/lib/commands/init/options/url.setup.ts rename to packages/cli/src/lib/commands/init/processes/url.setup.ts diff --git a/packages/cli/src/lib/config.middleware.ts b/packages/cli/src/lib/config.middleware.ts index bc1e7dcf6..99cf389ca 100644 --- a/packages/cli/src/lib/config.middleware.ts +++ b/packages/cli/src/lib/config.middleware.ts @@ -1,12 +1,11 @@ import * as yargs from 'yargs'; +import { Options } from 'yargs'; import { GlobalOptionsArgv } from './global/options/types'; import { logVerbose } from './core/loggin'; -import { detectCliMode } from './global/cli-mode/cli-mode'; -import { RcJson, RcJsonAsArgv } from './types'; -import { Options } from 'yargs'; +import { detectCliMode } from './global/cli-mode'; export function applyConfigMiddleware(handler: (...args: any) => void, configParser: Options['configParser']) { - return (...args: any) => { + return () => { yargs.config((configParser as any)()); const { interactive, verbose, rcPath } = yargs.argv as unknown as GlobalOptionsArgv; logVerbose('CLI Mode: ', detectCliMode()); diff --git a/packages/cli/src/lib/core/yargs/index.ts b/packages/cli/src/lib/core/yargs/index.ts index acea7d001..d60b27364 100644 --- a/packages/cli/src/lib/core/yargs/index.ts +++ b/packages/cli/src/lib/core/yargs/index.ts @@ -30,10 +30,9 @@ export function setupYargs( export function runCli(cliCfg: { commands: YargsCommandObject[]; options: { [key: string]: Options }; - configParser: Options['configParser']; //RcArgvOptions & GlobalOptionsArgv + configParser: Options['configParser']; }) { // apply `.argv` to get args as plain obj available setupYargs(cliCfg.commands, cliCfg.options, cliCfg.configParser).argv; - } diff --git a/packages/cli/src/lib/core/yargs/types.ts b/packages/cli/src/lib/core/yargs/types.ts index c55cd1ab4..b663f2180 100644 --- a/packages/cli/src/lib/core/yargs/types.ts +++ b/packages/cli/src/lib/core/yargs/types.ts @@ -7,7 +7,6 @@ export interface YargsCommandObject { module: CommandModule; } -export type ArgvOption = {[K in keyof T]: YargsOptionTypeToTsType}; export type YargsOptionTypeToTsType = T extends 'array' ? Array : T extends 'count' | 'number' ? number : T extends 'string' ? string : diff --git a/packages/cli/src/lib/global/options/interactive.ts b/packages/cli/src/lib/global/options/interactive.ts index 76264e3ca..dc4507645 100644 --- a/packages/cli/src/lib/global/options/interactive.ts +++ b/packages/cli/src/lib/global/options/interactive.ts @@ -1,6 +1,5 @@ import { argv } from 'yargs'; import { Param } from './interactive.model'; -import { ArgvOption } from '../../core/yargs/types'; import { getEnvPreset } from '../../pre-set'; function getDefaultByCliMode(): boolean { @@ -17,6 +16,6 @@ export const param: Param = { // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { - const { interactive, i } = argv as any as ArgvOption; + const { interactive, i } = argv as any as {interactive?: boolean, i?: boolean}; return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : param.interactive.default; } diff --git a/packages/cli/src/lib/global/options/verbose.ts b/packages/cli/src/lib/global/options/verbose.ts index cd7a07a5d..f204c4b08 100644 --- a/packages/cli/src/lib/global/options/verbose.ts +++ b/packages/cli/src/lib/global/options/verbose.ts @@ -1,6 +1,5 @@ import { argv } from 'yargs'; import { Param } from './verbose.model'; -import { ArgvOption } from '../../core/yargs/types'; import { GlobalOptionsArgv } from './types'; import { getEnvPreset } from '../../pre-set'; From ff5ca9e251090da8d9802ed7c73407d119a8d572 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 15:59:21 +0100 Subject: [PATCH 12/24] fix: remove unnecessary patch type errors --- .../budgetPath.constant.ts => constants.ts} | 0 packages/cli/src/lib/commands/assert/options.ts | 8 ++++++++ .../commands/assert/options/budgetPath.model.ts | 8 -------- .../lib/commands/assert/options/budgets.model.ts | 8 -------- .../cli/src/lib/commands/assert/options/types.ts | 13 ------------- .../src/lib/commands/assert/utils/budgets/index.ts | 14 ++------------ .../cli/src/lib/commands/collect/options/types.ts | 9 +-------- .../cli/src/lib/commands/collect/utils/params.ts | 2 +- .../collect/utils/user-flow/collect-flow.ts | 2 +- packages/cli/src/lib/commands/init/utils.ts | 2 +- packages/cli/src/lib/types.ts | 6 +----- 11 files changed, 15 insertions(+), 57 deletions(-) rename packages/cli/src/lib/commands/assert/{options/budgetPath.constant.ts => constants.ts} (100%) delete mode 100644 packages/cli/src/lib/commands/assert/options/budgetPath.model.ts delete mode 100644 packages/cli/src/lib/commands/assert/options/budgets.model.ts delete mode 100644 packages/cli/src/lib/commands/assert/options/types.ts diff --git a/packages/cli/src/lib/commands/assert/options/budgetPath.constant.ts b/packages/cli/src/lib/commands/assert/constants.ts similarity index 100% rename from packages/cli/src/lib/commands/assert/options/budgetPath.constant.ts rename to packages/cli/src/lib/commands/assert/constants.ts diff --git a/packages/cli/src/lib/commands/assert/options.ts b/packages/cli/src/lib/commands/assert/options.ts index 2193342a7..734188cfe 100644 --- a/packages/cli/src/lib/commands/assert/options.ts +++ b/packages/cli/src/lib/commands/assert/options.ts @@ -1,3 +1,4 @@ +import { SharedFlagsSettings } from 'lighthouse/types/lhr/settings'; import { Options } from 'yargs'; const budgets = { @@ -17,3 +18,10 @@ export const assertOptions = { budgetPath, budgets } satisfies Record; + +// @TODO this type has overlap with the one in rc-json.ts we should fix that and only have one +export type AssertRcOptions = { + budgetPath?: string, + budgets?: SharedFlagsSettings['budgets'] +} +export type AssertArgvOptions = AssertRcOptions; diff --git a/packages/cli/src/lib/commands/assert/options/budgetPath.model.ts b/packages/cli/src/lib/commands/assert/options/budgetPath.model.ts deleted file mode 100644 index b7cd00381..000000000 --- a/packages/cli/src/lib/commands/assert/options/budgetPath.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - budgetPath: Modify -}; diff --git a/packages/cli/src/lib/commands/assert/options/budgets.model.ts b/packages/cli/src/lib/commands/assert/options/budgets.model.ts deleted file mode 100644 index b016bd5ec..000000000 --- a/packages/cli/src/lib/commands/assert/options/budgets.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - budgets: Modify -}; diff --git a/packages/cli/src/lib/commands/assert/options/types.ts b/packages/cli/src/lib/commands/assert/options/types.ts deleted file mode 100644 index 3faf98dc7..000000000 --- a/packages/cli/src/lib/commands/assert/options/types.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Param as BudgetPath } from '../../assert/options/budgetPath.model'; -import { Param as Budgets } from '../../assert/options/budgets.model'; -import { SharedFlagsSettings } from 'lighthouse/types/lhr/settings'; - -export type AssertYargsOptions = BudgetPath & Budgets; - -// @TODO this type has overlap with the one in rc-json.ts we should fix that and only have one -export type AssertRcOptions = { - budgetPath?: string, - budgets?: SharedFlagsSettings['budgets'] -} -export type AssertArgvOptions = AssertRcOptions; - diff --git a/packages/cli/src/lib/commands/assert/utils/budgets/index.ts b/packages/cli/src/lib/commands/assert/utils/budgets/index.ts index 4c31bb826..746e83599 100644 --- a/packages/cli/src/lib/commands/assert/utils/budgets/index.ts +++ b/packages/cli/src/lib/commands/assert/utils/budgets/index.ts @@ -1,21 +1,11 @@ -import { readFile, writeFile } from '../../../../core/file'; -import { logVerbose } from '../../../../core/loggin'; import Budget from 'lighthouse/types/lhr/budget'; -import { DEFAULT_ASSERT_BUDGET_PATH } from '../../options/budgetPath.constant'; +import { readFile } from '../../../../core/file'; +import { DEFAULT_ASSERT_BUDGET_PATH } from '../../constants'; export function readBudgets(budgetPath: string = DEFAULT_ASSERT_BUDGET_PATH): Budget[] { const budgetsJson = JSON.parse(readFile(budgetPath, {fail: true}) || '{}'); return budgetsJson; } -export function writeBudgets(config: Budget[], budgetPath: string = DEFAULT_ASSERT_BUDGET_PATH): void { - logVerbose(`Update budgets under ${budgetPath}`); - if (JSON.stringify(readBudgets()) !== JSON.stringify(config)) { - writeFile(budgetPath, JSON.stringify(config)); - logVerbose(`New budgets ${JSON.stringify(config)}`); - } else { - logVerbose(`No updates for ${budgetPath} to save.`); - } -} diff --git a/packages/cli/src/lib/commands/collect/options/types.ts b/packages/cli/src/lib/commands/collect/options/types.ts index 8ac21b2aa..b7045c1ed 100644 --- a/packages/cli/src/lib/commands/collect/options/types.ts +++ b/packages/cli/src/lib/commands/collect/options/types.ts @@ -1,11 +1,4 @@ -import { Param as OpenReport } from './openReport.model'; -import { Param as UfPath } from './ufPath.model'; -import { Param as Url } from './url.model'; -import { Param as ServeCommand } from './serveCommand.model'; -import { Param as AwaitServeStdout } from './awaitServeStdout.model'; -import { Param as OutPath } from './outPath.model'; -import { Param as Format } from './format.model'; -import { AssertArgvOptions } from '../../assert/options/types'; +import { AssertArgvOptions } from '../../assert/options'; import { LhConfigJson } from '../../../hacky-things/lighthouse'; export type CollectRcOptions = { diff --git a/packages/cli/src/lib/commands/collect/utils/params.ts b/packages/cli/src/lib/commands/collect/utils/params.ts index bd15464a4..2553b854a 100644 --- a/packages/cli/src/lib/commands/collect/utils/params.ts +++ b/packages/cli/src/lib/commands/collect/utils/params.ts @@ -5,7 +5,7 @@ import { PersistArgvOptions, PersistRcOptions } from '../options/types'; -import { AssertArgvOptions } from '../../assert/options/types'; +import { AssertArgvOptions } from '../../assert/options'; import { CollectOptions } from '../options'; diff --git a/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts b/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts index 67f14264d..c0678851b 100644 --- a/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts +++ b/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts @@ -11,7 +11,7 @@ import { detectCliMode } from '../../../../global/cli-mode/cli-mode'; import { CollectArgvOptions } from '../../options/types'; import { getLhConfigFromArgv, mergeLhConfig } from '../config'; import { PersistArgvOptions } from '../../options/types'; -import { AssertRcOptions } from '../../../assert/options/types'; +import { AssertRcOptions } from '../../../assert/options'; export async function collectFlow( cliOption: CollectArgvOptions & PersistArgvOptions & AssertRcOptions, diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index ed929f570..c219ec9b6 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -1,6 +1,6 @@ import { CollectRcOptions, PersistRcOptions } from '../collect/options/types'; -import { AssertRcOptions } from '../assert/options/types'; import { InitOptions } from './options'; +import { AssertRcOptions } from '../assert/options'; export function getInitCommandOptionsFromArgv(argv: InitOptions) { let { diff --git a/packages/cli/src/lib/types.ts b/packages/cli/src/lib/types.ts index d41a639c9..148d0920d 100644 --- a/packages/cli/src/lib/types.ts +++ b/packages/cli/src/lib/types.ts @@ -5,7 +5,7 @@ import { PersistArgvOptions, PersistRcOptions } from './commands/collect/options/types'; -import { AssertArgvOptions, AssertRcOptions } from './commands/assert/options/types'; +import { AssertArgvOptions, AssertRcOptions } from './commands/assert/options'; export type ArgvPreset = { rcPath: GlobalOptionsArgv['rcPath'] } & @@ -18,8 +18,4 @@ export type RcJson = { collect: CollectRcOptions; persist: PersistRcOptions; assert?: AssertRcOptions; - // eslint-disable-next-line @typescript-eslint/ban-types } & Object; - -export type RcJsonAsArgv = CollectRcOptions & PersistRcOptions & AssertRcOptions; - From de37ac660e230adf0975f1a36c8950250633a31b Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 16:07:16 +0100 Subject: [PATCH 13/24] fix: remove unnecessary patch type errors --- packages/cli/src/lib/global/options/index.ts | 18 +++++++-------- .../cli/src/lib/global/options/interactive.ts | 19 +++++++-------- .../cli/src/lib/global/options/verbose.ts | 23 ++++++++----------- .../cli/src/lib/global/rc-json/options/rc.ts | 20 +++++++--------- 4 files changed, 34 insertions(+), 46 deletions(-) diff --git a/packages/cli/src/lib/global/options/index.ts b/packages/cli/src/lib/global/options/index.ts index dd83df647..54ec7540d 100644 --- a/packages/cli/src/lib/global/options/index.ts +++ b/packages/cli/src/lib/global/options/index.ts @@ -1,13 +1,13 @@ -import { param as verbose, get as getVerbose } from './verbose'; -import { param as rc, get as getRcPath } from '../rc-json/options/rc'; -import { param as interactive, get as getInteractive } from './interactive'; -import { CoreOptions } from './types'; +import { verbose, get as getVerbose } from './verbose'; +import { rcPath, get as getRcPath } from '../rc-json/options/rc'; +import { interactive, get as getInteractive } from './interactive'; +import { Options } from 'yargs'; -export const GLOBAL_OPTIONS_YARGS_CFG: CoreOptions = { - ...verbose, - ...rc, - ...interactive -}; +export const GLOBAL_OPTIONS_YARGS_CFG = { + verbose, + rcPath, + interactive +} satisfies Record; export const globalOptions = { getVerbose, diff --git a/packages/cli/src/lib/global/options/interactive.ts b/packages/cli/src/lib/global/options/interactive.ts index dc4507645..17f1a983d 100644 --- a/packages/cli/src/lib/global/options/interactive.ts +++ b/packages/cli/src/lib/global/options/interactive.ts @@ -1,21 +1,18 @@ -import { argv } from 'yargs'; -import { Param } from './interactive.model'; +import { argv, Options } from 'yargs'; import { getEnvPreset } from '../../pre-set'; function getDefaultByCliMode(): boolean { return getEnvPreset().interactive as boolean; } -export const param: Param = { - interactive: { - alias: 'i', - type: 'boolean', - description: 'When false questions are skipped with the values from the suggestions. This is useful for CI integrations.', - default: getDefaultByCliMode() - } -}; +export const interactive = { + alias: 'i', + type: 'boolean', + description: 'When false questions are skipped with the values from the suggestions. This is useful for CI integrations.', + default: getDefaultByCliMode() +} satisfies Options; // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { const { interactive, i } = argv as any as {interactive?: boolean, i?: boolean}; - return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : param.interactive.default; + return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : getDefaultByCliMode(); } diff --git a/packages/cli/src/lib/global/options/verbose.ts b/packages/cli/src/lib/global/options/verbose.ts index f204c4b08..b75da19db 100644 --- a/packages/cli/src/lib/global/options/verbose.ts +++ b/packages/cli/src/lib/global/options/verbose.ts @@ -1,20 +1,15 @@ -import { argv } from 'yargs'; -import { Param } from './verbose.model'; -import { GlobalOptionsArgv } from './types'; +import { argv, Options } from 'yargs'; import { getEnvPreset } from '../../pre-set'; - -export const param: Param = { - verbose: { - alias: 'v', - type: 'boolean', - description: 'Run with verbose logging', - default: getEnvPreset().verbose - } -}; +export const verbose = { + alias: 'v', + type: 'boolean', + description: 'Run with verbose logging', + default: getEnvPreset().verbose +} satisfies Options; // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { - const {verbose} = argv as unknown as GlobalOptionsArgv; - return verbose; + const {verbose} = argv as unknown as {verbose?: boolean}; + return !!verbose; } diff --git a/packages/cli/src/lib/global/rc-json/options/rc.ts b/packages/cli/src/lib/global/rc-json/options/rc.ts index ea7e4a5ca..5f227632a 100644 --- a/packages/cli/src/lib/global/rc-json/options/rc.ts +++ b/packages/cli/src/lib/global/rc-json/options/rc.ts @@ -1,19 +1,15 @@ -import { argv } from 'yargs'; -import { Param } from './rc.model'; +import { argv, Options } from 'yargs'; import { getEnvPreset } from '../../../pre-set'; -import { GlobalOptionsArgv } from '../../options/types'; -export const param: Param = { - rcPath: { - alias: 'p', - type: 'string', - description: 'Path to user-flow.config.json. e.g. `./user-flowrc.json`', - default: getEnvPreset().rcPath - } -}; +export const rcPath = { + alias: 'p', + type: 'string', + description: 'Path to user-flow.config.json. e.g. `./user-flowrc.json`', + default: getEnvPreset().rcPath +} satisfies Options; // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): string { - const { rcPath } = argv as unknown as GlobalOptionsArgv; + const { rcPath } = argv as unknown as { rcPath: string }; return rcPath as string } From 8145193a674ae676a3248fcc3c741cd5ef6da103 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 16:37:40 +0100 Subject: [PATCH 14/24] fix: remove unnecessary patch type errors --- .../src/lib/commands/assert/command-impl.ts | 2 +- .../cli/src/lib/commands/assert/constants.ts | 1 - .../lib/commands/assert/utils/budgets/index.ts | 6 +++--- .../src/lib/commands/assert/utils/md-report.ts | 18 ++++++++---------- 4 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 packages/cli/src/lib/commands/assert/constants.ts diff --git a/packages/cli/src/lib/commands/assert/command-impl.ts b/packages/cli/src/lib/commands/assert/command-impl.ts index 271275ae9..f5e576f26 100644 --- a/packages/cli/src/lib/commands/assert/command-impl.ts +++ b/packages/cli/src/lib/commands/assert/command-impl.ts @@ -1,7 +1,7 @@ import { logVerbose } from '../../core/loggin'; import { readBudgets } from './utils/budgets'; -export async function runAssertCommand() { +export async function runAssertCommand(): Promise { logVerbose(readBudgets()); return Promise.resolve(); } diff --git a/packages/cli/src/lib/commands/assert/constants.ts b/packages/cli/src/lib/commands/assert/constants.ts deleted file mode 100644 index 25b9a4b0e..000000000 --- a/packages/cli/src/lib/commands/assert/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const DEFAULT_ASSERT_BUDGET_PATH = './budget.json'; diff --git a/packages/cli/src/lib/commands/assert/utils/budgets/index.ts b/packages/cli/src/lib/commands/assert/utils/budgets/index.ts index 746e83599..a9db536ff 100644 --- a/packages/cli/src/lib/commands/assert/utils/budgets/index.ts +++ b/packages/cli/src/lib/commands/assert/utils/budgets/index.ts @@ -1,10 +1,10 @@ import Budget from 'lighthouse/types/lhr/budget'; import { readFile } from '../../../../core/file'; -import { DEFAULT_ASSERT_BUDGET_PATH } from '../../constants'; + +const DEFAULT_ASSERT_BUDGET_PATH = './budget.json'; export function readBudgets(budgetPath: string = DEFAULT_ASSERT_BUDGET_PATH): Budget[] { - const budgetsJson = JSON.parse(readFile(budgetPath, {fail: true}) || '{}'); - return budgetsJson; + return JSON.parse(readFile(budgetPath, { fail: true }) || '{}'); } diff --git a/packages/cli/src/lib/commands/assert/utils/md-report.ts b/packages/cli/src/lib/commands/assert/utils/md-report.ts index 67ae72142..506c8fc78 100644 --- a/packages/cli/src/lib/commands/assert/utils/md-report.ts +++ b/packages/cli/src/lib/commands/assert/utils/md-report.ts @@ -1,13 +1,11 @@ -import {FractionResults, GatherMode, ReducedFlowStep, ReducedReport} from '../../collect/utils/report/types'; -import {enrichReducedReportWithBaseline} from '../../collect/utils/report/utils'; -import {Alignment, table} from '../../../core/md/table'; -import {style} from '../../../core/md/font-style'; -import {headline, Hierarchy} from '../../../core/md/headline'; -import {NEW_LINE} from '../../../core/md/constants'; -import {details} from '../../../core/md/details'; -import Budget from "lighthouse/types/lhr/budget"; -import TimingBudget = Budget.TimingBudget; -import Details from "lighthouse/types/lhr/audit-details"; +import { FractionResults, GatherMode, ReducedFlowStep, ReducedReport } from '../../collect/utils/report/types'; +import { enrichReducedReportWithBaseline } from '../../collect/utils/report/utils'; +import { Alignment, table } from '../../../core/md/table'; +import { style } from '../../../core/md/font-style'; +import { headline, Hierarchy } from '../../../core/md/headline'; +import { NEW_LINE } from '../../../core/md/constants'; +import { details } from '../../../core/md/details'; +import Details from 'lighthouse/types/lhr/audit-details'; import Table = Details.Table; const budgetsSymbol = '🔒' From 526592a3c256ed63e0e1b7a4edd45544a8108683 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 16:43:12 +0100 Subject: [PATCH 15/24] fix: remove unnecessary patch type errors --- .../collect/options/awaitServeStdout.model.ts | 8 ------- .../commands/collect/options/config.model.ts | 8 ------- .../lib/commands/collect/options/config.ts | 21 ++++++------------- .../collect/options/configPath.model.ts | 8 ------- .../commands/collect/options/dryRun.model.ts | 9 -------- .../commands/collect/options/format.model.ts | 8 ------- .../src/lib/commands/collect/options/index.ts | 2 ++ .../collect/options/openReport.model.ts | 8 ------- .../commands/collect/options/outPath.model.ts | 9 -------- .../collect/options/serveCommand.model.ts | 8 ------- .../commands/collect/options/ufPath.model.ts | 8 ------- .../lib/commands/collect/options/url.model.ts | 8 ------- 12 files changed, 8 insertions(+), 97 deletions(-) delete mode 100644 packages/cli/src/lib/commands/collect/options/awaitServeStdout.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/config.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/configPath.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/dryRun.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/format.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/openReport.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/outPath.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/serveCommand.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/ufPath.model.ts delete mode 100644 packages/cli/src/lib/commands/collect/options/url.model.ts diff --git a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.model.ts b/packages/cli/src/lib/commands/collect/options/awaitServeStdout.model.ts deleted file mode 100644 index 468e521eb..000000000 --- a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - awaitServeStdout: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/config.model.ts b/packages/cli/src/lib/commands/collect/options/config.model.ts deleted file mode 100644 index 1958acba4..000000000 --- a/packages/cli/src/lib/commands/collect/options/config.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - config: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/config.ts b/packages/cli/src/lib/commands/collect/options/config.ts index 511a607f0..3a0564580 100644 --- a/packages/cli/src/lib/commands/collect/options/config.ts +++ b/packages/cli/src/lib/commands/collect/options/config.ts @@ -1,16 +1,7 @@ -import { argv } from 'yargs'; -import { Param } from './config.model'; -import { LhConfigJson } from '../../../hacky-things/lighthouse'; +import { Options } from 'yargs'; -export const param: Param = { - config: { - alias: 'l', - type: 'object', - description: 'Lighthouse configuration (RC file only)' - } -}; - -export function get(): string[] { - const { config } = argv as any as { config: LhConfigJson }; - return config as string[]; -} +export const config = { + alias: 'l', + type: 'string', // TODO This should be type object + description: 'Lighthouse configuration (RC file only)' +} satisfies Options; diff --git a/packages/cli/src/lib/commands/collect/options/configPath.model.ts b/packages/cli/src/lib/commands/collect/options/configPath.model.ts deleted file mode 100644 index f0ead8f51..000000000 --- a/packages/cli/src/lib/commands/collect/options/configPath.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - configPath: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/dryRun.model.ts b/packages/cli/src/lib/commands/collect/options/dryRun.model.ts deleted file mode 100644 index af8b96561..000000000 --- a/packages/cli/src/lib/commands/collect/options/dryRun.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - dryRun: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/format.model.ts b/packages/cli/src/lib/commands/collect/options/format.model.ts deleted file mode 100644 index 080695842..000000000 --- a/packages/cli/src/lib/commands/collect/options/format.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - format: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/index.ts b/packages/cli/src/lib/commands/collect/options/index.ts index 8d8c08e09..bdf603d12 100644 --- a/packages/cli/src/lib/commands/collect/options/index.ts +++ b/packages/cli/src/lib/commands/collect/options/index.ts @@ -9,6 +9,7 @@ import { serveCommand } from './serveCommand'; import { awaitServeStdout } from './awaitServeStdout'; import { dryRun } from './dryRun'; import { assertOptions } from '../../assert/options'; +import { config } from './config'; export const persistOptions = { outPath, @@ -19,6 +20,7 @@ export const persistOptions = { export const collectOptions = { url, ufPath, + config, configPath, serveCommand, awaitServeStdout, diff --git a/packages/cli/src/lib/commands/collect/options/openReport.model.ts b/packages/cli/src/lib/commands/collect/options/openReport.model.ts deleted file mode 100644 index 07e3ec84f..000000000 --- a/packages/cli/src/lib/commands/collect/options/openReport.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - openReport: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/outPath.model.ts b/packages/cli/src/lib/commands/collect/options/outPath.model.ts deleted file mode 100644 index 9ef5fcb6a..000000000 --- a/packages/cli/src/lib/commands/collect/options/outPath.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Options } from 'yargs'; -import { Modify} from '../../../core/types'; -import { YargsOptionTypeToTsType } from '../../../core/yargs/types'; - -export type Param = { - outPath: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/serveCommand.model.ts b/packages/cli/src/lib/commands/collect/options/serveCommand.model.ts deleted file mode 100644 index e815753ff..000000000 --- a/packages/cli/src/lib/commands/collect/options/serveCommand.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - serveCommand: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/ufPath.model.ts b/packages/cli/src/lib/commands/collect/options/ufPath.model.ts deleted file mode 100644 index 915a2408c..000000000 --- a/packages/cli/src/lib/commands/collect/options/ufPath.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - ufPath: Modify -}; diff --git a/packages/cli/src/lib/commands/collect/options/url.model.ts b/packages/cli/src/lib/commands/collect/options/url.model.ts deleted file mode 100644 index 275b062b4..000000000 --- a/packages/cli/src/lib/commands/collect/options/url.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Options } from 'yargs'; -import { Modify } from '../../../core/types'; - -export type Param = { - url: Modify -}; From 0df44691cb3c735ec7c17f35d603e53c5ddeccd9 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 25 Feb 2024 16:58:21 +0100 Subject: [PATCH 16/24] fix: remove unnecessary patch type errors --- packages/cli/src/lib/global/options/interactive.ts | 4 +++- packages/cli/src/lib/global/options/verbose.ts | 4 ++-- packages/sandbox/e2e/cli/configuration.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/lib/global/options/interactive.ts b/packages/cli/src/lib/global/options/interactive.ts index 17f1a983d..bd8694a19 100644 --- a/packages/cli/src/lib/global/options/interactive.ts +++ b/packages/cli/src/lib/global/options/interactive.ts @@ -11,8 +11,10 @@ export const interactive = { default: getDefaultByCliMode() } satisfies Options; +const defaultValue = interactive.default; + // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { const { interactive, i } = argv as any as {interactive?: boolean, i?: boolean}; - return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : getDefaultByCliMode(); + return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : defaultValue; } diff --git a/packages/cli/src/lib/global/options/verbose.ts b/packages/cli/src/lib/global/options/verbose.ts index b75da19db..31d5c0c71 100644 --- a/packages/cli/src/lib/global/options/verbose.ts +++ b/packages/cli/src/lib/global/options/verbose.ts @@ -10,6 +10,6 @@ export const verbose = { // We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { - const {verbose} = argv as unknown as {verbose?: boolean}; - return !!verbose; + const {verbose} = argv as unknown as {verbose: boolean}; + return verbose; } diff --git a/packages/sandbox/e2e/cli/configuration.test.ts b/packages/sandbox/e2e/cli/configuration.test.ts index 3f97ed624..9b80ca5de 100644 --- a/packages/sandbox/e2e/cli/configuration.test.ts +++ b/packages/sandbox/e2e/cli/configuration.test.ts @@ -28,7 +28,7 @@ describe('the CLI configuration in default mode', () => { it('should have sandbox preset of global options in a fresh environment', async () => { const { exitCode, stdout, stderr } = await emptyPrjSandbox.$init(); - const { collect, persist, assert } = getInitCommandOptionsFromArgv(SANDBOX_PRESET); + const { collect, persist, assert } = getInitCommandOptionsFromArgv(SANDBOX_PRESET as any); // @NOTICE: format is not part of yargs params default values delete (persist as any).format; expectGlobalOptionsToBeContainedInStdout(stdout, getGlobalOptionsFromArgv(SANDBOX_PRESET)); @@ -54,7 +54,7 @@ describe('the CLI configuration in default mode', () => { it('should have default preset in a fresh environment', async () => { const { exitCode, stdout, stderr } = await emptyPrjDefault.$init({ verbose: true }); - const { collect, persist, assert } = getInitCommandOptionsFromArgv(SANDBOX_PRESET); + const { collect, persist, assert } = getInitCommandOptionsFromArgv(SANDBOX_PRESET as any); expectGlobalOptionsToBeContainedInStdout(stdout, getGlobalOptionsFromArgv(SANDBOX_PRESET)); // @NOTICE: format is not part of yargs params default values From e0ad19f873fdfdbae92f4f0fec32f223fceed8df Mon Sep 17 00:00:00 2001 From: Christopher Holder <40126819+ChristopherPHolder@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:20:02 +0100 Subject: [PATCH 17/24] fix: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Katka Pilátová --- .../cli/src/lib/commands/collect/options/awaitServeStdout.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts b/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts index 309c4daff..58e6b7f75 100644 --- a/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts +++ b/packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts @@ -3,6 +3,6 @@ import { Options } from 'yargs'; export const awaitServeStdout = { alias: 'w', type: 'string', - description: 'A string in stdou resulting from serving the app, to be awaited before start running the tests. e.g. "server running..."', + description: 'A string in stdout resulting from serving the app, to be awaited before start running the tests. e.g. "server running..."', implies: ['w', 'serveCommand'] } satisfies Options; From 91b77ead60146155711fa673b1a3068041b8d2ef Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Wed, 6 Mar 2024 18:46:19 +0100 Subject: [PATCH 18/24] fix: remove openReport options getter --- .../src/lib/commands/collect/command-impl.ts | 7 +-- .../commands/collect/options/openReport.ts | 9 +--- .../collect/processes/collect-reports.ts | 11 ++-- .../collect/utils/persist/open-report.ts | 50 ++++++++++--------- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/packages/cli/src/lib/commands/collect/command-impl.ts b/packages/cli/src/lib/commands/collect/command-impl.ts index ea3a149e1..ddd032422 100644 --- a/packages/cli/src/lib/commands/collect/command-impl.ts +++ b/packages/cli/src/lib/commands/collect/command-impl.ts @@ -13,8 +13,9 @@ export async function runCollectCommand(argv: CollectOptions): Promise { await run([ collectRcJson, (cfg: RcJson) => - startServerIfNeededAndExecute(() => collectReports(cfg) - .then() - , cfg.collect) + startServerIfNeededAndExecute( + () => collectReports(cfg, argv.openReport), + cfg.collect + ) ])(cfg); } diff --git a/packages/cli/src/lib/commands/collect/options/openReport.ts b/packages/cli/src/lib/commands/collect/options/openReport.ts index 2ee6d6311..5a913df17 100644 --- a/packages/cli/src/lib/commands/collect/options/openReport.ts +++ b/packages/cli/src/lib/commands/collect/options/openReport.ts @@ -1,15 +1,10 @@ -import { argv, Options } from 'yargs'; +import { Options } from 'yargs'; import { getEnvPreset } from '../../../pre-set'; export const openReport = { alias: 'e', type: 'boolean', description: 'Opens browser automatically after the user-flow is collected. (true by default)', - default: getEnvPreset().openReport as boolean, + default: getEnvPreset().openReport, requiresArg: true } satisfies Options; - -export function get(): boolean { - const { openReport } = argv as any as { openReport: boolean }; - return openReport; -} diff --git a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts index 8d2133656..06da50cf4 100644 --- a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts +++ b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts @@ -1,25 +1,22 @@ -import { UserFlowProvider } from '../utils/user-flow/types'; import { concat } from '../../../core/processing/behaviors'; import { get as dryRun } from '../../../commands/collect/options/dryRun'; import { collectFlow, loadFlow } from '../utils/user-flow'; import { persistFlow } from '../utils/persist/persist-flow'; -import { openFlowReport } from '../utils/persist/open-report'; +import { handleOpenFlowReports } from '../utils/persist/open-report'; import { RcJson } from '../../../types'; -export async function collectReports(cfg: RcJson): Promise { +export async function collectReports(cfg: RcJson, openReport: boolean): Promise { const { collect, persist, assert } = cfg; - let userFlows = [] as ({ exports: UserFlowProvider, path: string })[]; - // Load and run user-flows in sequential - userFlows = loadFlow(collect); + const userFlows = loadFlow(collect); await concat(userFlows.map(({ exports: provider, path }) => (_: any) => { return collectFlow({ ...collect, ...persist, ...assert, dryRun: dryRun() }, { ...provider, path }) .then((flow) => persistFlow(flow, { ...persist, ...collect })) - .then(openFlowReport) + .then(handleOpenFlowReports(openReport)) .then(_ => cfg); }) )(cfg); diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts index fa3953ac5..55fd2cb02 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts @@ -1,33 +1,35 @@ +import * as openReport from 'open'; import { get as dryRun } from '../../../../commands/collect/options/dryRun'; -import { get as openReport } from '../../options/openReport'; import { get as interactive } from '../../../../global/options/interactive'; import { logVerbose } from '../../../../core/loggin'; -import * as openFileInBrowser from 'open'; -export async function openFlowReport(fileNames: string[]): Promise { - // open report if requested and not in executed in CI - if (!dryRun() && openReport() && interactive()) { - - const htmlReport = fileNames.find(i => i.includes('.html')); - if (htmlReport) { - logVerbose('open HTML report in browser'); - await openFileInBrowser(htmlReport, { wait: false }); - return Promise.resolve(void 0); - } +export async function openFlowReports(fileNames: string[]): Promise { + const htmlReport = fileNames.find(i => i.includes('.html')); + if (htmlReport) { + logVerbose('open HTML report in browser'); + await openReport(htmlReport, { wait: false }); + return Promise.resolve(void 0); + } - const mdReport = fileNames.find(i => i.includes('.md')); - if (mdReport) { - logVerbose('open Markdown report in browser'); - await openFileInBrowser(mdReport, { wait: false }); - return Promise.resolve(void 0); - } + const mdReport = fileNames.find(i => i.includes('.md')); + if (mdReport) { + logVerbose('open Markdown report in browser'); + await openReport(mdReport, { wait: false }); + return Promise.resolve(void 0); + } - const jsonReport = fileNames.find(i => i.includes('.json')); - if (jsonReport) { - logVerbose('open JSON report in browser'); - // @TODO if JSON is given open the file in https://googlechrome.github.io/lighthouse/viewer/ - await openFileInBrowser(jsonReport, { wait: false }); - } + const jsonReport = fileNames.find(i => i.includes('.json')); + if (jsonReport) { + logVerbose('open JSON report in browser'); + // @TODO if JSON is given open the file in https://googlechrome.github.io/lighthouse/viewer/ + await openReport(jsonReport, { wait: false }); } return Promise.resolve(void 0); } + +export function handleOpenFlowReports(openReport: boolean): typeof openFlowReports | undefined { + if (dryRun() || !openReport || !interactive()) { + return; + } + return openFlowReports; +} From c38666296f06d48e63b0c141b71e45b94d2f85dd Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Wed, 6 Mar 2024 18:47:13 +0100 Subject: [PATCH 19/24] test: add unit test for open report --- .../utils/persist/open-report.unit.test.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts new file mode 100644 index 000000000..2623358da --- /dev/null +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts @@ -0,0 +1,99 @@ +import { handleOpenFlowReports, openFlowReports } from './open-report'; +import { logVerbose } from '../../../../core/loggin'; +import * as openReport from 'open'; + +import * as dryRun from '../../../../commands/collect/options/dryRun'; +import * as interactive from '../../../../global/options/interactive'; + +jest.mock('../../../../commands/collect/options/dryRun'); +jest.mock('../../../../global/options/interactive'); + +describe('handleOpenFlowReport', () => { + beforeEach(() => { + jest.clearAllMocks(); + }) + + it('should return undefined if openReport is false', () => { + const openReportsProcess = handleOpenFlowReports(false); + expect(openReportsProcess).toEqual(undefined); + }); + + it('should return undefined if dryRun is true', () => { + jest.spyOn(dryRun, 'get').mockReturnValue(true); + const openReportsProcess = handleOpenFlowReports(true); + expect(openReportsProcess).toEqual(undefined); + }); + + it('should return undefined if interactive is false', () => { + jest.spyOn(interactive, 'get').mockReturnValue(false); + const openReportsProcess = handleOpenFlowReports(true); + expect(openReportsProcess).toEqual(undefined); + }); + + it('should return the openFlowReport function if openReport, interactive and not dryRun', async () => { + jest.spyOn(interactive, 'get').mockReturnValue(true); + jest.spyOn(dryRun, 'get').mockReturnValue(false); + const openReportsProcess = handleOpenFlowReports(true); + expect(typeof openReportsProcess).toEqual("function"); + }); +}); + +jest.mock('open'); +jest.mock('../../../../core/loggin'); + +describe('openReports', () => { + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should not open the report if no file name is passed', async () => { + await openFlowReports([]); + expect(openReport).not.toHaveBeenCalled(); + }); + + it('should not logVerbose if no file name is passed', async () => { + await openFlowReports([]); + expect(logVerbose).not.toHaveBeenCalled(); + }); + + it('should open the report if filenames includes an html report', async () => { + await openFlowReports(['example.html']); + expect(openReport).toHaveBeenCalled(); + }); + + it('should logVerbose if filenames includes an html report', async () => { + await openFlowReports(['example.html']); + expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('HTML')); + }); + + it('should open the report if filenames includes a json report', async () => { + await openFlowReports(['example.json']); + expect(openReport).toHaveBeenCalled(); + }); + + it('should logVerbose if filenames includes an json report', async () => { + await openFlowReports(['example.json']); + expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('JSON')); + }); + + it('should open the report if filenames includes a md report', async () => { + await openFlowReports(['example.md']); + expect(openReport).toHaveBeenCalled(); + }); + + it('should logVerbose if filenames includes an md report', async () => { + await openFlowReports(['example.md']); + expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('Markdown')); + }); + + it('should only open 1 time report if multiple report formats are passed', async () => { + await openFlowReports(['example.html', 'example.json', 'example.md']); + expect(openReport).toHaveBeenCalledTimes(1); + }); + + it('should only logVerbose 1 time report if multiple report formats are passed', async () => { + await openFlowReports(['example.html', 'example.json', 'example.md']); + expect(logVerbose).toHaveBeenCalledTimes(1); + }); +}); From 9bc03fe46aa8cc887de4d79cb2aefd880578f3be Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Wed, 6 Mar 2024 19:29:29 +0100 Subject: [PATCH 20/24] fix: fix typing issues --- .../commands/collect/processes/collect-reports.ts | 2 +- .../commands/collect/utils/persist/open-report.ts | 2 +- packages/cli/src/lib/commands/init/utils.ts | 15 +++++++++++++-- packages/cli/src/lib/pre-set.ts | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts index 06da50cf4..4b7105b92 100644 --- a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts +++ b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts @@ -5,7 +5,7 @@ import { persistFlow } from '../utils/persist/persist-flow'; import { handleOpenFlowReports } from '../utils/persist/open-report'; import { RcJson } from '../../../types'; -export async function collectReports(cfg: RcJson, openReport: boolean): Promise { +export async function collectReports(cfg: RcJson, openReport?: boolean): Promise { const { collect, persist, assert } = cfg; diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts index 55fd2cb02..5d96f774a 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts @@ -27,7 +27,7 @@ export async function openFlowReports(fileNames: string[]): Promise { return Promise.resolve(void 0); } -export function handleOpenFlowReports(openReport: boolean): typeof openFlowReports | undefined { +export function handleOpenFlowReports(openReport?: boolean): typeof openFlowReports | undefined { if (dryRun() || !openReport || !interactive()) { return; } diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index c219ec9b6..ac8f10ab0 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -1,6 +1,17 @@ -import { CollectRcOptions, PersistRcOptions } from '../collect/options/types'; +import { CollectRcOptions, PersistRcOptions, ReportFormat } from '../collect/options/types'; import { InitOptions } from './options'; import { AssertRcOptions } from '../assert/options'; +import { REPORT_FORMAT_VALUES } from '../collect/constants'; + +const isValidFormat = (value: any): value is ReportFormat => REPORT_FORMAT_VALUES.includes(value); + +function sanitizedFormats(formats: string[]): ReportFormat[] { + const validatedFormats: ReportFormat[] = formats.filter(isValidFormat); + if (validatedFormats.length !== formats.length) { + throw new Error(`${formats} contains invalid format options`); + } + return validatedFormats; +} export function getInitCommandOptionsFromArgv(argv: InitOptions) { let { @@ -18,7 +29,7 @@ export function getInitCommandOptionsFromArgv(argv: InitOptions) { let persist = {} as PersistRcOptions; outPath && (persist.outPath = outPath); - format && (persist.format = format); + format && (persist.format = sanitizedFormats(format)); let assert = {} as AssertRcOptions; budgetPath && (assert.budgetPath = budgetPath); diff --git a/packages/cli/src/lib/pre-set.ts b/packages/cli/src/lib/pre-set.ts index 88c5bb1aa..2be7d1d3b 100644 --- a/packages/cli/src/lib/pre-set.ts +++ b/packages/cli/src/lib/pre-set.ts @@ -1,5 +1,5 @@ import { ArgvPreset } from './types'; -import { detectCliMode } from './global/cli-mode/cli-mode'; +import { detectCliMode } from './global/cli-mode'; import { DEFAULT_FULL_RC_PATH } from './constants'; export const DEFAULT_PRESET: ArgvPreset = { From 5d75b2a0a37632929e37674a1afd421dcc408416 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Wed, 6 Mar 2024 20:11:09 +0100 Subject: [PATCH 21/24] fix: use command value instead of getters for dryRun and interactive --- .../src/lib/commands/collect/command-impl.ts | 6 +-- .../src/lib/commands/collect/options/index.ts | 2 + .../collect/processes/collect-reports.ts | 5 ++- .../collect/utils/persist/open-report.ts | 7 ++- .../utils/persist/open-report.unit.test.ts | 45 +++++++++++-------- packages/cli/src/lib/global/options/index.ts | 4 +- .../cli/src/lib/global/options/interactive.ts | 12 ++--- 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/packages/cli/src/lib/commands/collect/command-impl.ts b/packages/cli/src/lib/commands/collect/command-impl.ts index ddd032422..5d16b4240 100644 --- a/packages/cli/src/lib/commands/collect/command-impl.ts +++ b/packages/cli/src/lib/commands/collect/command-impl.ts @@ -5,16 +5,16 @@ import { run } from '../../core/processing/behaviors'; import { collectRcJson } from '../init/processes/collect-rc-json'; import { startServerIfNeededAndExecute } from './utils/serve-command'; import { collectReports } from './processes/collect-reports'; -import { CollectOptions } from './options'; +import { CollectCommandOptions } from './options'; -export async function runCollectCommand(argv: CollectOptions): Promise { +export async function runCollectCommand(argv: CollectCommandOptions): Promise { const cfg = getCollectCommandOptionsFromArgv(argv); logVerbose('Collect options: ', cfg); await run([ collectRcJson, (cfg: RcJson) => startServerIfNeededAndExecute( - () => collectReports(cfg, argv.openReport), + () => collectReports(cfg, argv), cfg.collect ) ])(cfg); diff --git a/packages/cli/src/lib/commands/collect/options/index.ts b/packages/cli/src/lib/commands/collect/options/index.ts index bdf603d12..d282f0707 100644 --- a/packages/cli/src/lib/commands/collect/options/index.ts +++ b/packages/cli/src/lib/commands/collect/options/index.ts @@ -10,6 +10,7 @@ import { awaitServeStdout } from './awaitServeStdout'; import { dryRun } from './dryRun'; import { assertOptions } from '../../assert/options'; import { config } from './config'; +import { GlobalCliOptions } from '../../../global/options'; export const persistOptions = { outPath, @@ -29,3 +30,4 @@ export const collectOptions = { ...assertOptions } satisfies Record; export type CollectOptions = InferredOptionTypes; +export type CollectCommandOptions = CollectOptions & GlobalCliOptions; diff --git a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts index 4b7105b92..6e122ce11 100644 --- a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts +++ b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts @@ -4,8 +4,9 @@ import { collectFlow, loadFlow } from '../utils/user-flow'; import { persistFlow } from '../utils/persist/persist-flow'; import { handleOpenFlowReports } from '../utils/persist/open-report'; import { RcJson } from '../../../types'; +import { CollectCommandOptions } from '../options'; -export async function collectReports(cfg: RcJson, openReport?: boolean): Promise { +export async function collectReports(cfg: RcJson, argv: CollectCommandOptions): Promise { const { collect, persist, assert } = cfg; @@ -16,7 +17,7 @@ export async function collectReports(cfg: RcJson, openReport?: boolean): Promise ...collect, ...persist, ...assert, dryRun: dryRun() }, { ...provider, path }) .then((flow) => persistFlow(flow, { ...persist, ...collect })) - .then(handleOpenFlowReports(openReport)) + .then(handleOpenFlowReports(argv)) .then(_ => cfg); }) )(cfg); diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts index 5d96f774a..a819afc95 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts @@ -1,7 +1,6 @@ import * as openReport from 'open'; -import { get as dryRun } from '../../../../commands/collect/options/dryRun'; -import { get as interactive } from '../../../../global/options/interactive'; import { logVerbose } from '../../../../core/loggin'; +import { CollectCommandOptions } from '../../options'; export async function openFlowReports(fileNames: string[]): Promise { const htmlReport = fileNames.find(i => i.includes('.html')); @@ -27,8 +26,8 @@ export async function openFlowReports(fileNames: string[]): Promise { return Promise.resolve(void 0); } -export function handleOpenFlowReports(openReport?: boolean): typeof openFlowReports | undefined { - if (dryRun() || !openReport || !interactive()) { +export function handleOpenFlowReports({ dryRun, openReport, interactive}: CollectCommandOptions) { + if (dryRun || !openReport || !interactive) { return; } return openFlowReports; diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts index 2623358da..b37df137d 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts @@ -1,41 +1,50 @@ +import * as openReport from 'open'; import { handleOpenFlowReports, openFlowReports } from './open-report'; import { logVerbose } from '../../../../core/loggin'; -import * as openReport from 'open'; - -import * as dryRun from '../../../../commands/collect/options/dryRun'; -import * as interactive from '../../../../global/options/interactive'; - -jest.mock('../../../../commands/collect/options/dryRun'); -jest.mock('../../../../global/options/interactive'); +import { CollectCommandOptions } from '../../options'; describe('handleOpenFlowReport', () => { beforeEach(() => { jest.clearAllMocks(); }) + it('should return the openFlowReport function if openReport, interactive and not dryRun', async () => { + const openReportsProcess = handleOpenFlowReports({ + openReport: true, + interactive: true, + dryRun: false, + } as CollectCommandOptions); + expect(typeof openReportsProcess).toEqual("function"); + }); + it('should return undefined if openReport is false', () => { - const openReportsProcess = handleOpenFlowReports(false); + const openReportsProcess = handleOpenFlowReports({ + openReport: false, + interactive: true, + dryRun: false, + } as CollectCommandOptions); expect(openReportsProcess).toEqual(undefined); }); it('should return undefined if dryRun is true', () => { - jest.spyOn(dryRun, 'get').mockReturnValue(true); - const openReportsProcess = handleOpenFlowReports(true); + const openReportsProcess = handleOpenFlowReports({ + openReport: true, + interactive: true, + dryRun: true, + } as CollectCommandOptions); expect(openReportsProcess).toEqual(undefined); }); it('should return undefined if interactive is false', () => { - jest.spyOn(interactive, 'get').mockReturnValue(false); - const openReportsProcess = handleOpenFlowReports(true); + const openReportsProcess = handleOpenFlowReports({ + openReport: true, + interactive: false, + dryRun: false, + } as CollectCommandOptions); expect(openReportsProcess).toEqual(undefined); }); - it('should return the openFlowReport function if openReport, interactive and not dryRun', async () => { - jest.spyOn(interactive, 'get').mockReturnValue(true); - jest.spyOn(dryRun, 'get').mockReturnValue(false); - const openReportsProcess = handleOpenFlowReports(true); - expect(typeof openReportsProcess).toEqual("function"); - }); + }); jest.mock('open'); diff --git a/packages/cli/src/lib/global/options/index.ts b/packages/cli/src/lib/global/options/index.ts index 54ec7540d..9867e9db4 100644 --- a/packages/cli/src/lib/global/options/index.ts +++ b/packages/cli/src/lib/global/options/index.ts @@ -1,13 +1,15 @@ +import { InferredOptionTypes, Options } from 'yargs'; + import { verbose, get as getVerbose } from './verbose'; import { rcPath, get as getRcPath } from '../rc-json/options/rc'; import { interactive, get as getInteractive } from './interactive'; -import { Options } from 'yargs'; export const GLOBAL_OPTIONS_YARGS_CFG = { verbose, rcPath, interactive } satisfies Record; +export type GlobalCliOptions = InferredOptionTypes; export const globalOptions = { getVerbose, diff --git a/packages/cli/src/lib/global/options/interactive.ts b/packages/cli/src/lib/global/options/interactive.ts index bd8694a19..c6d20fd9f 100644 --- a/packages/cli/src/lib/global/options/interactive.ts +++ b/packages/cli/src/lib/global/options/interactive.ts @@ -1,20 +1,14 @@ import { argv, Options } from 'yargs'; import { getEnvPreset } from '../../pre-set'; -function getDefaultByCliMode(): boolean { - return getEnvPreset().interactive as boolean; -} export const interactive = { alias: 'i', type: 'boolean', description: 'When false questions are skipped with the values from the suggestions. This is useful for CI integrations.', - default: getDefaultByCliMode() + default: getEnvPreset().interactive, } satisfies Options; -const defaultValue = interactive.default; - -// We don't rely on yargs option normalization features as this can happen before cli bootstrap export function get(): boolean { - const { interactive, i } = argv as any as {interactive?: boolean, i?: boolean}; - return interactive !== undefined ? Boolean(interactive) : i !== undefined ? Boolean(i) : defaultValue; + const { interactive } = argv as any as { interactive: boolean }; + return interactive; } From dc26a9998f3e23226495f64baa263e378ce9492a Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Wed, 6 Mar 2024 20:25:37 +0100 Subject: [PATCH 22/24] fix: remove dry run option getter --- packages/cli/src/lib/commands/collect/options/dryRun.ts | 4 ---- .../lib/commands/collect/processes/collect-reports.ts | 5 +---- .../lib/commands/collect/utils/user-flow/collect-flow.ts | 9 +++++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/cli/src/lib/commands/collect/options/dryRun.ts b/packages/cli/src/lib/commands/collect/options/dryRun.ts index d5a3b8818..ba74eb85c 100644 --- a/packages/cli/src/lib/commands/collect/options/dryRun.ts +++ b/packages/cli/src/lib/commands/collect/options/dryRun.ts @@ -8,7 +8,3 @@ export const dryRun = { default: getEnvPreset().dryRun as boolean } satisfies Options; -export function get(): boolean { - const { dryRun } = argv as any as { dryRun: boolean }; - return dryRun; -} diff --git a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts index 6e122ce11..084749ca6 100644 --- a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts +++ b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts @@ -1,5 +1,4 @@ import { concat } from '../../../core/processing/behaviors'; -import { get as dryRun } from '../../../commands/collect/options/dryRun'; import { collectFlow, loadFlow } from '../utils/user-flow'; import { persistFlow } from '../utils/persist/persist-flow'; import { handleOpenFlowReports } from '../utils/persist/open-report'; @@ -13,9 +12,7 @@ export async function collectReports(cfg: RcJson, argv: CollectCommandOptions): const userFlows = loadFlow(collect); await concat(userFlows.map(({ exports: provider, path }) => (_: any) => { - return collectFlow({ - ...collect, ...persist, ...assert, dryRun: dryRun() - }, { ...provider, path }) + return collectFlow({ ...collect, ...persist, ...assert }, { ...provider, path }, argv) .then((flow) => persistFlow(flow, { ...persist, ...collect })) .then(handleOpenFlowReports(argv)) .then(_ => cfg); diff --git a/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts b/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts index c0678851b..1b227de14 100644 --- a/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts +++ b/packages/cli/src/lib/commands/collect/utils/user-flow/collect-flow.ts @@ -5,17 +5,18 @@ import { Browser, LaunchOptions, Page } from 'puppeteer'; import { normalize } from 'path'; // @ts-ignore import { startFlow, UserFlow } from 'lighthouse/lighthouse-core/fraggle-rock/api'; -import { get as dryRun } from '../../../../commands/collect/options/dryRun'; import { UserFlowMock } from './user-flow.mock'; -import { detectCliMode } from '../../../../global/cli-mode/cli-mode'; +import { detectCliMode } from '../../../../global/cli-mode'; import { CollectArgvOptions } from '../../options/types'; import { getLhConfigFromArgv, mergeLhConfig } from '../config'; import { PersistArgvOptions } from '../../options/types'; import { AssertRcOptions } from '../../../assert/options'; +import { CollectCommandOptions } from '../../options'; export async function collectFlow( cliOption: CollectArgvOptions & PersistArgvOptions & AssertRcOptions, - userFlowProvider: UserFlowProvider & { path: string } + userFlowProvider: UserFlowProvider & { path: string }, + argv: CollectCommandOptions ) { let { path, @@ -37,7 +38,7 @@ export async function collectFlow( logVerbose(`User-flow path: ${normalize(path)}`); let start = Date.now(); - const flow: UserFlow = !dryRun() ? await startFlow(page, flowOptions) : new UserFlowMock(page, flowOptions); + const flow: UserFlow = !argv.dryRun ? await startFlow(page, flowOptions) : new UserFlowMock(page, flowOptions); // run custom interactions await interactions({ flow, page, browser, collectOptions: cliOption }); From a1ab2dcf75aab13f964d5065f4ae0d28fd399011 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Mon, 11 Mar 2024 10:15:28 +0100 Subject: [PATCH 23/24] test: fix merge conflict --- package-lock.json | 15 ++++++++------- package.json | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3474d3c18..d6eafb38e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@puppeteer/replay": "^1.3.1", "@types/concurrently": "^7.0.0", "@types/puppeteer": "^5.4.7", - "@types/yargs": "^17.0.9", + "@types/yargs": "^17.0.32", "concurrently": "^7.1.0", "dotenv": "^16.4.1", "enquirer": "^2.3.6", @@ -26,6 +26,7 @@ "rxjs": "^7.8.1", "ts-node": "10.9.1", "tslib": "^2.3.1", + "yargs": "^17.7.2", "zod": "^3.22.4" }, "devDependencies": { @@ -6150,9 +6151,9 @@ } }, "node_modules/@types/yargs": { - "version": "17.0.13", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz", - "integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "dependencies": { "@types/yargs-parser": "*" } @@ -26276,9 +26277,9 @@ } }, "@types/yargs": { - "version": "17.0.13", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz", - "integrity": "sha512-9sWaruZk2JGxIQU+IhI1fhPYRcQ0UuTNuKuCW9bR5fp7qi2Llf7WDzNa17Cy7TKnh3cdxDOiyTu6gaLS0eDatg==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "requires": { "@types/yargs-parser": "*" } diff --git a/package.json b/package.json index 08b647cc0..87d9920dc 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@puppeteer/replay": "^1.3.1", "@types/concurrently": "^7.0.0", "@types/puppeteer": "^5.4.7", - "@types/yargs": "^17.0.9", + "@types/yargs": "^17.0.32", "concurrently": "^7.1.0", "dotenv": "^16.4.1", "enquirer": "^2.3.6", @@ -37,6 +37,7 @@ "rxjs": "^7.8.1", "ts-node": "10.9.1", "tslib": "^2.3.1", + "yargs": "^17.7.2", "zod": "^3.22.4" }, "devDependencies": { From a716aecb9242297753fb9fb51e23d4037324a99b Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Mon, 11 Mar 2024 10:30:58 +0100 Subject: [PATCH 24/24] test: simplify test --- .../utils/persist/open-report.unit.test.ts | 57 +++++-------------- packages/cli/src/lib/commands/init/utils.ts | 2 +- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts index b37df137d..0e43eb5fb 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts @@ -3,7 +3,11 @@ import { handleOpenFlowReports, openFlowReports } from './open-report'; import { logVerbose } from '../../../../core/loggin'; import { CollectCommandOptions } from '../../options'; +jest.mock('open'); +jest.mock('../../../../core/loggin'); + describe('handleOpenFlowReport', () => { + beforeEach(() => { jest.clearAllMocks(); }) @@ -14,7 +18,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: false, } as CollectCommandOptions); - expect(typeof openReportsProcess).toEqual("function"); + expect(openReportsProcess).toEqual(expect.any(Function)); }); it('should return undefined if openReport is false', () => { @@ -23,7 +27,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: false, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); it('should return undefined if dryRun is true', () => { @@ -32,7 +36,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: true, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); it('should return undefined if interactive is false', () => { @@ -41,15 +45,10 @@ describe('handleOpenFlowReport', () => { interactive: false, dryRun: false, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); - - }); -jest.mock('open'); -jest.mock('../../../../core/loggin'); - describe('openReports', () => { beforeEach(() => { @@ -61,48 +60,18 @@ describe('openReports', () => { expect(openReport).not.toHaveBeenCalled(); }); - it('should not logVerbose if no file name is passed', async () => { - await openFlowReports([]); - expect(logVerbose).not.toHaveBeenCalled(); - }); - - it('should open the report if filenames includes an html report', async () => { - await openFlowReports(['example.html']); - expect(openReport).toHaveBeenCalled(); - }); - - it('should logVerbose if filenames includes an html report', async () => { - await openFlowReports(['example.html']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('HTML')); - }); - - it('should open the report if filenames includes a json report', async () => { - await openFlowReports(['example.json']); + it.each(['html', 'json', 'md'])('should open the %s report', async (format) => { + await openFlowReports([`example.${format}`]); expect(openReport).toHaveBeenCalled(); }); - it('should logVerbose if filenames includes an json report', async () => { - await openFlowReports(['example.json']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('JSON')); - }); - - it('should open the report if filenames includes a md report', async () => { - await openFlowReports(['example.md']); - expect(openReport).toHaveBeenCalled(); - }); - - it('should logVerbose if filenames includes an md report', async () => { - await openFlowReports(['example.md']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('Markdown')); + it('should not logVerbose if no file name is passed', async () => { + await openFlowReports([]); + expect(logVerbose).not.toHaveBeenCalled(); }); it('should only open 1 time report if multiple report formats are passed', async () => { await openFlowReports(['example.html', 'example.json', 'example.md']); expect(openReport).toHaveBeenCalledTimes(1); }); - - it('should only logVerbose 1 time report if multiple report formats are passed', async () => { - await openFlowReports(['example.html', 'example.json', 'example.md']); - expect(logVerbose).toHaveBeenCalledTimes(1); - }); }); diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index ac8f10ab0..7f9111869 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -5,7 +5,7 @@ import { REPORT_FORMAT_VALUES } from '../collect/constants'; const isValidFormat = (value: any): value is ReportFormat => REPORT_FORMAT_VALUES.includes(value); -function sanitizedFormats(formats: string[]): ReportFormat[] { +function sanitizedFormats(formats: string[]) { const validatedFormats: ReportFormat[] = formats.filter(isValidFormat); if (validatedFormats.length !== formats.length) { throw new Error(`${formats} contains invalid format options`);