From 7d3de1090cb820121fe245c24d453919546f90e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Chalk?= Date: Sun, 24 Sep 2023 12:11:38 +0200 Subject: [PATCH] refactor(utils): add package.json metadata to report in cli, not utils --- packages/cli/src/lib/collect/command-object.ts | 9 +++++++-- packages/utils/src/lib/collect/index.spec.ts | 13 ++++--------- packages/utils/src/lib/collect/index.ts | 12 ++---------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/cli/src/lib/collect/command-object.ts b/packages/cli/src/lib/collect/command-object.ts index 25b895b09..f281c7d07 100644 --- a/packages/cli/src/lib/collect/command-object.ts +++ b/packages/cli/src/lib/collect/command-object.ts @@ -1,4 +1,4 @@ -import { pluginOutputSchema } from '@quality-metrics/models'; +import { pluginOutputSchema, Report } from '@quality-metrics/models'; import { collect, CollectOptions, @@ -12,7 +12,12 @@ export function yargsCollectCommandObject() { const handler = async ( config: CollectOptions & { format: string }, ): Promise => { - const report = await collect({ ...config, packageJson }); + const collectReport = await collect(config); + const report: Report = { + ...collectReport, + packageName: packageJson.name, + version: packageJson.version, + }; await persistReport(report, config); diff --git a/packages/utils/src/lib/collect/index.spec.ts b/packages/utils/src/lib/collect/index.spec.ts index 726d19158..82174f260 100644 --- a/packages/utils/src/lib/collect/index.spec.ts +++ b/packages/utils/src/lib/collect/index.spec.ts @@ -1,6 +1,5 @@ import { reportSchema } from '@quality-metrics/models'; import { mockCoreConfig } from '@quality-metrics/models/testing'; -import type { PackageJson } from 'type-fest'; import { describe, expect, it } from 'vitest'; import { CollectOptions, collect } from '../collect/'; @@ -13,13 +12,9 @@ const baseOptions: CollectOptions = { describe('collect', () => { it('should execute with valid options`', async () => { - const packageJson: PackageJson = { - name: '@code-pushup/cli', - version: '0.1.0', - }; - const report = await collect({ ...baseOptions, packageJson }); - expect(report.packageName).toBe(packageJson.name); - expect(report.version).toBe(packageJson.version); - expect(() => reportSchema.parse(report)).not.toThrow(); + const report = await collect(baseOptions); + expect(() => + reportSchema.omit({ packageName: true, version: true }).parse(report), + ).not.toThrow(); }); }); diff --git a/packages/utils/src/lib/collect/index.ts b/packages/utils/src/lib/collect/index.ts index d056ee80d..58505175e 100644 --- a/packages/utils/src/lib/collect/index.ts +++ b/packages/utils/src/lib/collect/index.ts @@ -19,19 +19,13 @@ export class CollectOutputError extends Error { export type CollectOptions = GlobalCliArgs & CoreConfig; -type PackageJson = { - name?: string; - version?: string; -}; - /** * Run audits, collect plugin output and aggregate it into a JSON object * @param options */ export async function collect( - options: CollectOptions & { packageJson: PackageJson }, -): Promise { - const { version, name } = options.packageJson; + options: CollectOptions, +): Promise> { const { plugins, categories } = options; if (!plugins?.length) { @@ -43,8 +37,6 @@ export async function collect( const pluginOutputs = await executePlugins(plugins); return { - packageName: name, - version, date, duration: calcDuration(start), categories,