Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/plugin-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"@code-pushup/models": "0.85.0",
"@code-pushup/utils": "0.85.0",
"ansis": "^3.3.0",
"parse-lcov": "^1.0.4",
"yargs": "^17.7.2",
"zod": "^4.0.5"
Expand Down
20 changes: 5 additions & 15 deletions packages/plugin-coverage/src/lib/nx/coverage-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type {
} from '@nx/devkit';
import type { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema';
import type { VitestExecutorOptions } from '@nx/vite/executors';
import { bold } from 'ansis';
import path from 'node:path';
import { importModule, stringifyError, ui } from '@code-pushup/utils';
import { importModule, logger, stringifyError } from '@code-pushup/utils';
import type { CoverageResult } from '../config.js';

/**
Expand All @@ -22,7 +21,7 @@ async function resolveCachedProjectGraph() {
try {
return readCachedProjectGraph();
} catch (error) {
ui().logger.info(
logger.info(
`Could not read cached project graph, falling back to async creation.
${stringifyError(error)}`,
);
Expand All @@ -36,13 +35,8 @@ async function resolveCachedProjectGraph() {
*/
export async function getNxCoveragePaths(
targets: string[] = ['test'],
verbose?: boolean,
): Promise<CoverageResult[]> {
if (verbose) {
ui().logger.info(
bold('💡 Gathering coverage from the following nx projects:'),
);
}
logger.debug('💡 Gathering coverage from the following nx projects:');

const { nodes } = await resolveCachedProjectGraph();

Expand All @@ -55,18 +49,14 @@ export async function getNxCoveragePaths(
return await Promise.all(
relevantNodes.map<Promise<CoverageResult>>(async ({ name, data }) => {
const coveragePaths = await getCoveragePathsForTarget(data, target);
if (verbose) {
ui().logger.info(`- ${name}: ${target}`);
}
logger.debug(`- ${name}: ${target}`);
return coveragePaths;
}),
);
}),
);

if (verbose) {
ui().logger.info('\n');
}
logger.debug('');

return coverageResults.flat();
}
Expand Down
13 changes: 0 additions & 13 deletions packages/plugin-coverage/src/lib/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { bold } from 'ansis';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import type { RunnerConfig, RunnerFilesPaths } from '@code-pushup/models';
import {
ProcessError,
createRunnerFiles,
ensureDirectoryExists,
executeProcess,
filePathToCliArg,
objectToCliArgs,
readJsonFile,
ui,
} from '@code-pushup/utils';
import type { FinalCoveragePluginConfig } from '../config.js';
import { lcovResultsToAuditOutputs } from './lcov/lcov-runner.js';
Expand All @@ -28,16 +25,6 @@ export async function executeRunner({
try {
await executeProcess({ command, args });
} catch (error) {
if (error instanceof ProcessError) {
const loggingFn = continueOnCommandFail
? ui().logger.warning.bind(ui().logger)
: ui().logger.error.bind(ui().logger);
loggingFn(bold('stdout from failed coverage tool process:'));
loggingFn(error.stdout);
loggingFn(bold('stderr from failed coverage tool process:'));
loggingFn(error.stderr);
}

if (!continueOnCommandFail) {
throw new Error(
'Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing.',
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
type FileCoverage,
exists,
getGitRoot,
logger,
objectFromEntries,
objectToEntries,
readTextFile,
toUnixNewlines,
ui,
} from '@code-pushup/utils';
import type { CoverageResult, CoverageType } from '../../config.js';
import { mergeLcovResults } from './merge-lcov.js';
Expand Down Expand Up @@ -72,9 +72,7 @@ export async function parseLcovFiles(
typeof result === 'string' ? result : result.resultsPath;
const lcovFileContent = await readTextFile(resultsPath);
if (lcovFileContent.trim() === '') {
ui().logger.warning(
`Coverage plugin: Empty lcov report file detected at ${resultsPath}.`,
);
logger.warn(`Empty lcov report file detected at ${resultsPath}.`);
}
const parsedRecords = parseLcov(toUnixNewlines(lcovFileContent));
return parsedRecords.map(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { vol } from 'memfs';
import path from 'node:path';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getGitRoot, ui } from '@code-pushup/utils';
import { getGitRoot, logger } from '@code-pushup/utils';
import type { CoverageResult, CoverageType } from '../../config.js';
import { lcovResultsToAuditOutputs, parseLcovFiles } from './lcov-runner.js';

Expand Down Expand Up @@ -144,9 +144,8 @@ end_of_record
path.join('coverage', 'lcov.info'),
]);

expect(ui()).toHaveLogged(
'warn',
`Coverage plugin: Empty lcov report file detected at ${path.join(
expect(logger.warn).toHaveBeenCalledWith(
`Empty lcov report file detected at ${path.join(
'coverage',
'lcov.info',
)}.`,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-eslint/src/lib/meta/groups.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Rule } from 'eslint';
import type { Group, GroupRef } from '@code-pushup/models';
import { objectToKeys, slugify, ui } from '@code-pushup/utils';
import { logger, objectToKeys, slugify } from '@code-pushup/utils';
import type { CustomGroup } from '../config.js';
import { ruleToSlug } from './hash.js';
import { type RuleData, parseRuleId } from './parse.js';
Expand Down Expand Up @@ -109,7 +109,7 @@ export function groupsFromCustomConfig(
`Invalid rule configuration in group ${group.slug}. All rules are invalid.`,
);
}
ui().logger.warning(
logger.warn(
`Some rules in group ${group.slug} are invalid: ${invalidRules.join(', ')}`,
);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-eslint/src/lib/meta/groups.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Group } from '@code-pushup/models';
import { ui } from '@code-pushup/utils';
import { logger } from '@code-pushup/utils';
import {
createRulesMap,
groupsFromCustomConfig,
Expand Down Expand Up @@ -306,8 +306,7 @@ describe('groupsFromCustomConfig', () => {
refs: [{ slug: 'react-jsx-key', weight: 3 }],
},
]);
expect(ui()).toHaveLogged(
'warn',
expect(logger.warn).toHaveBeenCalledWith(
'Some rules in group custom-group are invalid: invalid-rule',
);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-eslint/src/lib/meta/versions/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Linter, Rule } from 'eslint';
import { builtinRules } from 'eslint/use-at-your-own-risk';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { exists, findNearestFile, toArray, ui } from '@code-pushup/utils';
import { exists, findNearestFile, logger, toArray } from '@code-pushup/utils';
import type { ESLintTarget } from '../../config.js';
import { jsonHash } from '../hash.js';
import {
Expand All @@ -25,7 +25,7 @@ export async function loadRulesForFlatConfig({
.map(rule => {
const meta = findRuleMeta(rule.id, configs);
if (!meta) {
ui().logger.warning(`Cannot find metadata for rule ${rule.id}`);
logger.warn(`Cannot find metadata for rule ${rule.id}`);
return null;
}
return { ...rule, meta };
Expand Down Expand Up @@ -106,7 +106,7 @@ function findPluginRuleMeta(
const rule = config?.plugins?.[plugin]?.rules?.[name];

if (typeof rule === 'function') {
ui().logger.warning(
logger.warn(
`Cannot parse metadata for rule ${plugin}/${name}, plugin registers it as a function`,
);
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-eslint/src/lib/meta/versions/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
asyncSequential,
distinct,
exists,
logger,
toArray,
ui,
} from '@code-pushup/utils';
import type { ESLintTarget } from '../../config.js';
import { setupESLint } from '../../setup.js';
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function loadRulesForLegacyConfig({
}
const ruleMeta = rulesMeta[id];
if (!ruleMeta) {
ui().logger.warning(`Metadata not found for ESLint rule ${id}`);
logger.warn(`Metadata not found for ESLint rule ${id}`);
return null;
}
// ignoring meta.defaultOptions to match legacy config handling in calculateConfigForFile
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-eslint/src/lib/nx/find-all-projects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringifyError, ui } from '@code-pushup/utils';
import { logger, stringifyError } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { filterProjectGraph } from './filter-project-graph.js';
import { nxProjectsToConfig } from './projects-to-config.js';
Expand All @@ -14,9 +14,8 @@ async function resolveCachedProjectGraph() {
try {
return readCachedProjectGraph();
} catch (error) {
ui().logger.info(
`Could not read cached project graph, falling back to async creation.
${stringifyError(error)}`,
logger.info(
`Could not read cached project graph, falling back to async creation.\n${stringifyError(error)}`,
);
return await createProjectGraphAsync({ exitOnError: false });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-eslint/src/lib/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
PluginArtifactOptions,
RunnerFunction,
} from '@code-pushup/models';
import { asyncSequential, ui } from '@code-pushup/utils';
import { asyncSequential, logger } from '@code-pushup/utils';
import type { ESLintPluginRunnerConfig, ESLintTarget } from '../config.js';
import { lint } from './lint.js';
import { lintResultsToAudits, mergeLinterOutputs } from './transform.js';
Expand All @@ -23,7 +23,7 @@ export function createRunnerFunction(options: {
};

return async (): Promise<AuditOutputs> => {
ui().logger.log(`ESLint plugin executing ${targets.length} lint targets`);
logger.info(`ESLint plugin executing ${targets.length} lint targets`);

const linterOutputs = artifacts
? await loadArtifacts(artifacts)
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-eslint/src/lib/runner/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DEFAULT_PERSIST_CONFIG,
type pluginArtifactOptionsSchema,
} from '@code-pushup/models';
import { ui } from '@code-pushup/utils';
import { logger } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { createRunnerFunction } from './index.js';
import * as lintModule from './lint.js';
Expand Down Expand Up @@ -130,7 +130,9 @@ describe('createRunnerFunction', () => {

expect(loadArtifactsSpy).toHaveBeenCalledWith(artifacts);
expect(lintSpy).not.toHaveBeenCalled();
expect(ui()).toHaveLogged('log', 'ESLint plugin executing 2 lint targets');
expect(logger.info).toHaveBeenCalledWith(
'ESLint plugin executing 2 lint targets',
);
});

it('should use internal linting logic when artifacts are not provided', async () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-eslint/src/lib/runner/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { AuditOutput, Issue, IssueSeverity } from '@code-pushup/models';
import {
compareIssueSeverity,
countOccurrences,
logger,
objectToEntries,
pluralizeToken,
truncateIssueMessage,
ui,
} from '@code-pushup/utils';
import { ruleIdToSlug } from '../meta/index.js';
import type { LinterOutput } from './types.js';
Expand Down Expand Up @@ -36,9 +36,7 @@ export function lintResultsToAudits({
.reduce<Record<string, LintIssue[]>>((acc, issue) => {
const { ruleId, message, filePath } = issue;
if (!ruleId) {
ui().logger.warning(
`ESLint core error - ${message} (file: ${filePath})`,
);
logger.warn(`ESLint core error - ${message} (file: ${filePath})`);
return acc;
}
const options = ruleOptionsPerFile[filePath]?.[ruleId] ?? [];
Expand Down
11 changes: 4 additions & 7 deletions packages/plugin-lighthouse/src/lib/normalize-flags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { bold, yellow } from 'ansis';
import { ui } from '@code-pushup/utils';
import { LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
import ansis from 'ansis';
import { logger } from '@code-pushup/utils';
import { DEFAULT_CLI_FLAGS } from './runner/constants.js';
import type { LighthouseCliFlags } from './runner/types.js';
import type { LighthouseOptions } from './types.js';
Expand Down Expand Up @@ -73,10 +72,8 @@ export function logUnsupportedFlagsInUse(
if (unsupportedFlagsInUse.length > 0) {
const postFix = (count: number) =>
count > displayCount ? ` and ${count - displayCount} more.` : '';
ui().logger.debug(
`${yellow('⚠')} Plugin ${bold(
LIGHTHOUSE_PLUGIN_SLUG,
)} used unsupported flags: ${bold(
logger.warn(
`Used unsupported flags: ${ansis.bold(
unsupportedFlagsInUse.slice(0, displayCount).join(', '),
)}${postFix(unsupportedFlagsInUse.length)}`,
);
Expand Down
24 changes: 9 additions & 15 deletions packages/plugin-lighthouse/src/lib/normalize-flags.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bold, yellow } from 'ansis';
import ansis from 'ansis';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { ui } from '@code-pushup/utils';
import { logger } from '@code-pushup/utils';
import { DEFAULT_CHROME_FLAGS, LIGHTHOUSE_OUTPUT_PATH } from './constants.js';
import { logUnsupportedFlagsInUse, normalizeFlags } from './normalize-flags.js';
import { LIGHTHOUSE_REPORT_NAME } from './runner/constants.js';
Expand All @@ -10,12 +10,9 @@ import type { LighthouseOptions } from './types.js';
describe('logUnsupportedFlagsInUse', () => {
it('should log unsupported entries', () => {
logUnsupportedFlagsInUse({ 'list-all-audits': true } as LighthouseOptions);
expect(ui()).toHaveLoggedTimes(1);
expect(ui()).toHaveLogged(
'debug',
`${yellow('⚠')} Plugin ${bold(
'lighthouse',
)} used unsupported flags: ${bold('list-all-audits')}`,
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith(
`Used unsupported flags: ${ansis.bold('list-all-audits')}`,
);
});

Expand All @@ -32,12 +29,9 @@ describe('logUnsupportedFlagsInUse', () => {
// unsupported
...unsupportedFlags,
} as unknown as LighthouseOptions);
expect(ui()).toHaveLoggedTimes(1);
expect(ui()).toHaveLogged(
'debug',
`${yellow('⚠')} Plugin ${bold(
'lighthouse',
)} used unsupported flags: ${bold(
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith(
`Used unsupported flags: ${ansis.bold(
'list-all-audits, list-locales, list-trace-categories',
)} and 3 more.`,
);
Expand Down Expand Up @@ -119,7 +113,7 @@ describe('normalizeFlags', () => {
...supportedFlags,
} as unknown as LighthouseOptions),
).toEqual(expect.not.objectContaining({ 'list-all-audits': true }));
expect(ui()).toHaveLoggedTimes(1);
expect(logger.warn).toHaveBeenCalledTimes(1);
});

it('should remove any flag with an empty array as a value', () => {
Expand Down
Loading