Skip to content

Commit

Permalink
fix(esm): fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder committed Dec 19, 2023
1 parent 50db6c6 commit 57e291c
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 55 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/lib/commands/collect/options/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { Param } from './config.model.js';
import { LhConfigJson } from '../../../hacky-things/lighthouse.js';
import { Config } from 'lighthouse';

const yargs = _yargs(hideBin(process.argv));

Expand All @@ -14,6 +14,6 @@ export const param: Param = {
};

export function get(): string[] {
const { config } = yargs.argv as any as { config: LhConfigJson };
const { config } = yargs.argv as any as { config: Config };
return config as string[];
}
5 changes: 3 additions & 2 deletions packages/cli/src/lib/commands/collect/options/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Config } from 'lighthouse';

import { Param as OpenReport } from './openReport.model.js';
import { Param as UfPath } from './ufPath.model.js';
import { Param as Url } from './url.model.js';
Expand All @@ -6,7 +8,6 @@ import { Param as AwaitServeStdout } from './awaitServeStdout.model.js';
import { Param as OutPath } from './outPath.model.js';
import { Param as Format } from './format.model.js';
import { AssertArgvOptions } from '../../assert/options/types.js';
import { LhConfigJson } from '../../../hacky-things/lighthouse.js';

export type PersistYargsOptions = OpenReport & OutPath & Format;
export type CollectYargsOptions = UfPath & OutPath & Url & ServeCommand & AwaitServeStdout;
Expand All @@ -15,7 +16,7 @@ export type CollectRcOptions = {
url: string,
ufPath: string,
configPath?: string;
config?: LhConfigJson,
config?: Config,
// @TODO get better typing for if serveCommand is given await is required
serveCommand?: string,
awaitServeStdout?: string;
Expand Down
16 changes: 7 additions & 9 deletions packages/cli/src/lib/commands/collect/utils/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Budget, Config } from 'lighthouse';

import { readFile, writeFile } from '../../../../core/file/index.js';
import { logVerbose } from '../../../../core/loggin/index.js';
import { DEFAULT_COLLECT_CONFIG_PATH } from '../../options/configPath.constant.js';
import { LhConfigJson } from '../../../../hacky-things/lighthouse.js';
import { CollectCommandArgv } from '../../options/types.js';
import { readBudgets } from '../../../assert/utils/budgets/index.js';
// @ts-ignore
import Budget from 'lighthouse/types/lhr/budget';


export function readConfig(configPath: string = DEFAULT_COLLECT_CONFIG_PATH): LhConfigJson {
export function readConfig(configPath: string = DEFAULT_COLLECT_CONFIG_PATH): Config {
return JSON.parse(readFile(configPath, { fail: true }));
}

export function writeConfig(config: LhConfigJson, configPath: string = DEFAULT_COLLECT_CONFIG_PATH): void {
export function writeConfig(config: Config, configPath: string = DEFAULT_COLLECT_CONFIG_PATH): void {
logVerbose(`Update config under ${configPath}`);

if (JSON.stringify(readConfig()) !== JSON.stringify(config)) {
Expand All @@ -23,8 +21,8 @@ export function writeConfig(config: LhConfigJson, configPath: string = DEFAULT_C
}
}

export function getLhConfigFromArgv(rc: Partial<Pick<CollectCommandArgv, 'configPath' | 'config' | 'budgets' | 'budgetPath'>>): LhConfigJson {
let cfg: LhConfigJson = {};
export function getLhConfigFromArgv(rc: Partial<Pick<CollectCommandArgv, 'configPath' | 'config' | 'budgets' | 'budgetPath'>>): Config {
let cfg: Config = {};
if (!!rc?.configPath && !!rc?.config) {
throw new Error('configPath and config can\'t be used together');
}
Expand Down Expand Up @@ -62,7 +60,7 @@ export function getLhConfigFromArgv(rc: Partial<Pick<CollectCommandArgv, 'config
return cfg;
}

export function mergeLhConfig(globalCfg: LhConfigJson = {}, localCfg: LhConfigJson = {}): LhConfigJson {
export function mergeLhConfig(globalCfg: Config = {}, localCfg: Config = {}): Config {
let cfg = { ...globalCfg };

if (localCfg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { UserFlow } from '../../../../hacky-things/lighthouse.js';
import { join } from 'path';
import { existsSync, mkdirSync } from 'fs';

import { UserFlow, FlowResult } from 'lighthouse';

// @ts-ignore
import FlowResult from 'lighthouse/types/lhr/flow';
import { log, logVerbose } from '../../../../core/loggin/index.js';
import { join } from 'path';
import { writeFile } from '../../../../core/file/index.js';
import { existsSync, mkdirSync } from 'fs';
import { PersistFlowOptions } from './types.js';
import { createReducedReport } from '../../../../index.js';
import { generateStdoutReport } from './utils.js';
Expand All @@ -14,7 +13,7 @@ import { ReducedReport } from '../report/types.js';
import { generateMdReport } from '../../../assert/utils/md-report.js';

export async function persistFlow(
flow: any,
flow: UserFlow,
{ outPath, format, url }: PersistFlowOptions
): Promise<string[]> {
if (!format.length) {
Expand Down Expand Up @@ -56,7 +55,8 @@ export async function persistFlow(
}
}

const fileName = toReportName(url, flow.name, reducedReport);
// @TODO Define correct fallback for missing name!
const fileName = toReportName(url, flow._options?.name ?? 'flow-results', reducedReport);
return results.map((result) => {
const filePath = join(outPath, `${fileName}.${result.format}`);
writeFile(filePath, result.out);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { UserFlowProvider } from './types.js';
import { logVerbose } from '../../../../core/loggin/index.js';
import * as puppeteer from 'puppeteer';
import puppeteer from 'puppeteer';
import { Browser, LaunchOptions, Page } from 'puppeteer';
import { normalize } from 'path';
// @ts-ignore
import { startFlow, UserFlow } from 'lighthouse/lighthouse-core/fraggle-rock/api';
import { startFlow, UserFlow } from 'lighthouse';
import { get as dryRun } from '../../../../commands/collect/options/dryRun.js';
import { UserFlowMock } from './user-flow.mock.js';
import { detectCliMode } from '../../../../global/cli-mode/cli-mode.js';
Expand Down Expand Up @@ -37,7 +36,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 = !dryRun() ? await startFlow(page, flowOptions) : new UserFlowMock(page, flowOptions) as any as UserFlow;

// run custom interactions
await interactions({ flow, page, browser, collectOptions: cliOption });
Expand Down
13 changes: 4 additions & 9 deletions packages/cli/src/lib/commands/collect/utils/user-flow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ import {
Product
} from 'puppeteer';

// @ts-ignore
import * as Config from 'lighthouse/types/config';
import { UserFlow } from '../../../../hacky-things/lighthouse.js';
// @ts-ignore
import { SharedFlagsSettings } from 'lighthouse/types/lhr/settings';

import {SharedFlagsSettings, UserFlow } from 'lighthouse';

export type UserFlowContext = {
browser: Browser;
page: Page;
flow: any;
flow: UserFlow;
collectOptions: { url: string };
};

export type StepOptions = {
stepName: string;
} & {
/*page: Page,*/ config?: Config.default.Json /*configContext?: LH.Config.FRContext*/;
/*page: Page,*/ config?: UserFlow.Options /*configContext?: LH.Config.FRContext*/;
};

export type UserFlowInteractionsFn = (
Expand All @@ -35,7 +30,7 @@ export type UserFlowOptions = {
name: string;
} & {
// throttling
/*page: Page,*/ config?: Config.default.Json /*configContext?: LH.Config.FRContext*/;
/*page: Page,*/ config?: UserFlow.Options['config'] /*configContext?: LH.Config.FRContext*/;
};

// @TODO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Page } from 'puppeteer';
import { logVerbose } from '../../../../core/loggin/index.js';
// @ts-ignore
import FlowResult from 'lighthouse/types/lhr/flow';

import { StepOptions, UserFlowOptions } from './types.js';
import { FlowResult } from 'lighthouse';

const dummyFlowResult: (cfg: UserFlowOptions) => FlowResult = (cfg: UserFlowOptions): FlowResult => {
const config = cfg?.config || {};
Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/lib/commands/init/derive-budgets-from-lhr.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { UserFlow } from '../../hacky-things/lighthouse.js';
// @ts-ignore
import Budget from 'lighthouse/types/lhr/budget';
import type { Budget, FlowResult} from 'lighthouse';

import { RequestCountResourceTypeBudgets, TransferSizeResourceTypeBudgets } from './constants.js';
import { logVerbose } from '../../core/loggin/index.js';

export function deriveBudgetsFromLhr(flow: any): Budget[] {
export function deriveBudgetsFromLhr(flow: FlowResult): Budget[] {
const budgetObject: Budget = {};
if (flow?.steps[0].lhr?.audits) {
if (flow.steps[0].lhr.audits['resource-summary']) {
const resourceSummary = flow.steps[0].lhr.audits['resource-summary'];
// TODO fix typing Error
// @ts-ignore
budgetObject.resourceSizes = (resourceSummary.details.items as any)
.filter(({ resourceType }: any) => TransferSizeResourceTypeBudgets.includes(resourceType))
.map(({ resourceType, transferSize }: any) => ({
resourceType,
budget: transferSize
})
);
// TODO fix typing Error
// @ts-ignore
budgetObject.resourceCounts = (resourceSummary.details.items as any)
.filter(({ resourceType }: any) => RequestCountResourceTypeBudgets.includes(resourceType))
.map(({ resourceType, requestCount }: any) => ({
Expand All @@ -31,6 +34,8 @@ export function deriveBudgetsFromLhr(flow: any): Budget[] {
if (flow.steps[0].lhr.audits['cumulative-layout-shift']) {
budgetObject.timings.push({
'metric': 'cumulative-layout-shift',
// TODO fix typing Error
// @ts-ignore
'budget': flow.steps[0].lhr.audits['cumulative-layout-shift'].details.items[0].totalCumulativeLayoutShift
});
} else {
Expand All @@ -40,6 +45,8 @@ export function deriveBudgetsFromLhr(flow: any): Budget[] {
if (flow.steps[0].lhr.audits['largest-contentful-paint']) {
budgetObject.timings.push({
'metric': 'largest-contentful-paint',
// TODO fix typing Error
// @ts-ignore
'budget': parseInt(flow.steps[0].lhr.audits['largest-contentful-paint'].numericValue)
});
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INITIATED_PRJ_CFG, INITIATED_RC_JSON, EMPTY_PRJ_CFG } from 'test-data';
import { handleFlowGeneration } from './generate-userflow';
import { handleFlowGeneration } from './generate-userflow.js';
import { existsSync } from 'fs';
import { join } from 'path';
import { withUserFlowProject } from '@push-based/user-flow-cli-testing';
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/lib/core/prettier/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { format as prettier, Options as PrettierOptions, resolveConfig } from 'prettier';
import pkg, { Options } from 'prettier';

import { SupportedExtname, SupportedParser } from './types.js';
import { supportedExtname } from './constants.js';

const { format: prettier, resolveConfig } = pkg;

export function getParserFromExtname(extname: SupportedExtname | string): SupportedParser {
extname = extname[0] === '.' ? extname.slice(1, extname.length) : extname;

Expand All @@ -25,7 +28,7 @@ export function getParserFromExtname(extname: SupportedExtname | string): Suppor
*/
export function formatCode(
code: string,
parser: PrettierOptions['parser'] = 'typescript'
parser: Options['parser'] = 'typescript'
) {
const prettierConfig = resolveConfig.sync(__dirname);
return prettier(code, {
Expand Down
12 changes: 0 additions & 12 deletions packages/cli/src/lib/hacky-things/lighthouse.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export { MeasureModes } from './commands/collect/utils/replay/types.js';
export { RcJson } from './types.js';
export { CI_PROPERTY, CLI_MODE_PROPERTY } from './global/cli-mode/cli-mode.js';
export { CLI_MODES } from './global/cli-mode/types.js';
export { LhConfigJson } from './hacky-things/lighthouse.js';
export { getEnvPreset, SANDBOX_PRESET, CI_PRESET, DEFAULT_PRESET } from './pre-set.js';
export { InitCommandArgv } from './commands/init/options/types.js';
export { GlobalOptionsArgv } from './global/options/types.js';
Expand Down

0 comments on commit 57e291c

Please sign in to comment.