Skip to content

Commit 7d3de10

Browse files
committed
refactor(utils): add package.json metadata to report in cli, not utils
1 parent bba4d0a commit 7d3de10

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

packages/cli/src/lib/collect/command-object.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pluginOutputSchema } from '@quality-metrics/models';
1+
import { pluginOutputSchema, Report } from '@quality-metrics/models';
22
import {
33
collect,
44
CollectOptions,
@@ -12,7 +12,12 @@ export function yargsCollectCommandObject() {
1212
const handler = async (
1313
config: CollectOptions & { format: string },
1414
): Promise<void> => {
15-
const report = await collect({ ...config, packageJson });
15+
const collectReport = await collect(config);
16+
const report: Report = {
17+
...collectReport,
18+
packageName: packageJson.name,
19+
version: packageJson.version,
20+
};
1621

1722
await persistReport(report, config);
1823

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { reportSchema } from '@quality-metrics/models';
22
import { mockCoreConfig } from '@quality-metrics/models/testing';
3-
import type { PackageJson } from 'type-fest';
43
import { describe, expect, it } from 'vitest';
54
import { CollectOptions, collect } from '../collect/';
65

@@ -13,13 +12,9 @@ const baseOptions: CollectOptions = {
1312

1413
describe('collect', () => {
1514
it('should execute with valid options`', async () => {
16-
const packageJson: PackageJson = {
17-
name: '@code-pushup/cli',
18-
version: '0.1.0',
19-
};
20-
const report = await collect({ ...baseOptions, packageJson });
21-
expect(report.packageName).toBe(packageJson.name);
22-
expect(report.version).toBe(packageJson.version);
23-
expect(() => reportSchema.parse(report)).not.toThrow();
15+
const report = await collect(baseOptions);
16+
expect(() =>
17+
reportSchema.omit({ packageName: true, version: true }).parse(report),
18+
).not.toThrow();
2419
});
2520
});

packages/utils/src/lib/collect/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ export class CollectOutputError extends Error {
1919

2020
export type CollectOptions = GlobalCliArgs & CoreConfig;
2121

22-
type PackageJson = {
23-
name?: string;
24-
version?: string;
25-
};
26-
2722
/**
2823
* Run audits, collect plugin output and aggregate it into a JSON object
2924
* @param options
3025
*/
3126
export async function collect(
32-
options: CollectOptions & { packageJson: PackageJson },
33-
): Promise<Report> {
34-
const { version, name } = options.packageJson;
27+
options: CollectOptions,
28+
): Promise<Omit<Report, 'packageName' | 'version'>> {
3529
const { plugins, categories } = options;
3630

3731
if (!plugins?.length) {
@@ -43,8 +37,6 @@ export async function collect(
4337
const pluginOutputs = await executePlugins(plugins);
4438

4539
return {
46-
packageName: name,
47-
version,
4840
date,
4941
duration: calcDuration(start),
5042
categories,

0 commit comments

Comments
 (0)