Skip to content

Commit

Permalink
fix: migrate yargs and fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder authored Mar 14, 2024
2 parents a092381 + a5e7b7e commit 31f2ec4
Show file tree
Hide file tree
Showing 83 changed files with 437 additions and 705 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,7 +33,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": {
"@code-pushup/cli": "^0.25.6",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ export default {
transformIgnorePatterns: ['/node_modules/(?!markdown-table/.*)'],
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/cli',
testTimeout: 40_000,
};
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/lib/commands/assert/command-impl.ts
Original file line number Diff line number Diff line change
@@ -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(): Promise<void> {
logVerbose(readBudgets());
return Promise.resolve();
}
9 changes: 2 additions & 7 deletions packages/cli/src/lib/commands/assert/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
};
Expand Down
27 changes: 27 additions & 0 deletions packages/cli/src/lib/commands/assert/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { SharedFlagsSettings } from 'lighthouse/types/lhr/settings';
import { Options } from 'yargs';

const budgets = {
alias: 'j',
type: 'array',
string: true,
description: 'Performance budgets (RC file only)'
} satisfies Options;

const budgetPath = {
alias: 'k',
type: 'string',
description: 'Path to budgets.json'
} satisfies Options;

export const assertOptions = {
budgetPath,
budgets
} satisfies Record<string, Options>;

// @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;

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions packages/cli/src/lib/commands/assert/options/budgetPath.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/cli/src/lib/commands/assert/options/budgets.model.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/cli/src/lib/commands/assert/options/budgets.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/cli/src/lib/commands/assert/options/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/cli/src/lib/commands/assert/options/types.ts

This file was deleted.

18 changes: 4 additions & 14 deletions packages/cli/src/lib/commands/assert/utils/budgets/index.ts
Original file line number Diff line number Diff line change
@@ -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';

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 }) || '{}');
}

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.`);
}
}

18 changes: 8 additions & 10 deletions packages/cli/src/lib/commands/assert/utils/md-report.ts
Original file line number Diff line number Diff line change
@@ -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 = '🔒'
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/src/lib/commands/collect/command-impl.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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 { CollectCommandOptions } from './options';

export async function runCollectCommand(argv: RcJsonAsArgv) {
export async function runCollectCommand(argv: CollectCommandOptions): Promise<void> {
const cfg = getCollectCommandOptionsFromArgv(argv);
logVerbose('Collect options: ', cfg);
await run([
collectRcJson,
(cfg: RcJson) =>
startServerIfNeededAndExecute(() => collectReports(cfg)
.then()
, cfg.collect)
startServerIfNeededAndExecute(
() => collectReports(cfg, argv),
cfg.collect
)
])(cfg);
}
10 changes: 5 additions & 5 deletions packages/cli/src/lib/commands/collect/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {YargsCommandObject} from '../../core/yargs/types';
import {logVerbose} from '../../core/loggin/index';
import {COLLECT_OPTIONS} from './options';
import {runCollectCommand} from "./command-impl";
import { YargsCommandObject } from '../../core/yargs/types';
import { logVerbose } from '../../core/loggin';
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:`);
Expand Down

This file was deleted.

24 changes: 7 additions & 17 deletions packages/cli/src/lib/commands/collect/options/awaitServeStdout.ts
Original file line number Diff line number Diff line change
@@ -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<Param>;
return awaitServeStdout;
}
export const awaitServeStdout = {
alias: 'w',
type: 'string',
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;
8 changes: 0 additions & 8 deletions packages/cli/src/lib/commands/collect/options/config.model.ts

This file was deleted.

21 changes: 6 additions & 15 deletions packages/cli/src/lib/commands/collect/options/config.ts
Original file line number Diff line number Diff line change
@@ -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;

This file was deleted.

Loading

0 comments on commit 31f2ec4

Please sign in to comment.