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
4 changes: 2 additions & 2 deletions packages/core/src/lib/implementation/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export async function executePlugin(
? // IF not null, take the result from cache
((await readRunnerResults(pluginMeta.slug, outputDir)) ??
// ELSE execute the plugin runner
(await executePluginRunner(pluginConfig)))
: await executePluginRunner(pluginConfig);
(await executePluginRunner(pluginConfig, persist)))
: await executePluginRunner(pluginConfig, persist);

if (cacheWrite) {
await writeRunnerResults(pluginMeta.slug, outputDir, {
Expand Down
21 changes: 16 additions & 5 deletions packages/core/src/lib/implementation/execute-plugin.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('executePlugin', () => {
vi.restoreAllMocks();
});

it('should execute a valid plugin config', async () => {
it('should execute a valid plugin config and pass runner params', async () => {
const executePluginRunnerSpy = vi.spyOn(
runnerModule,
'executePluginRunner',
);

await expect(
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
persist: { outputDir: '' },
Expand All @@ -39,6 +44,11 @@ describe('executePlugin', () => {
}),
]),
});

expect(executePluginRunnerSpy).toHaveBeenCalledWith(
MINIMAL_PLUGIN_CONFIG_MOCK,
{ outputDir: '' },
);
});

it('should try to read cache if cache.read is true', async () => {
Expand Down Expand Up @@ -102,7 +112,7 @@ describe('executePlugin', () => {

await expect(
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
persist: { outputDir: 'dummy-path-result-is-mocked' },
persist: { outputDir: MEMFS_VOLUME },
cache: { read: true, write: false },
}),
).resolves.toStrictEqual({
Expand All @@ -122,6 +132,7 @@ describe('executePlugin', () => {

expect(executePluginRunnerSpy).toHaveBeenCalledWith(
MINIMAL_PLUGIN_CONFIG_MOCK,
{ outputDir: MEMFS_VOLUME },
);
});

Expand Down Expand Up @@ -383,8 +394,8 @@ describe('executePlugins', () => {
{
...MINIMAL_PLUGIN_CONFIG_MOCK,
runner: {
command: 'node',
args: ['-v'],
command: 'echo',
args: ['16'],
outputFile: 'output.json',
outputTransform: (outputs: unknown): Promise<AuditOutputs> =>
Promise.resolve([
Expand All @@ -398,7 +409,7 @@ describe('executePlugins', () => {
},
},
],
persist: { outputDir: '.code-pushup' },
persist: { outputDir: MEMFS_VOLUME },
cache: { read: false, write: false },
},
{ progress: false },
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/lib/implementation/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import {
type AuditOutputs,
type PersistConfig,
type PluginConfig,
type RunnerConfig,
type RunnerFunction,
Expand All @@ -14,6 +15,7 @@ import {
executeProcess,
fileExists,
isVerbose,
objectToCliArgs,
readJsonFile,
removeDirectoryIfExists,
ui,
Expand All @@ -32,12 +34,13 @@ export type ValidatedRunnerResult = Omit<RunnerResult, 'audits'> & {

export async function executeRunnerConfig(
cfg: RunnerConfig,
config: Required<Pick<PersistConfig, 'outputDir'>>,
): Promise<RunnerResult> {
const { args, command, outputFile, outputTransform } = cfg;

const { duration, date } = await executeProcess({
command,
args,
args: [...(args ?? []), ...objectToCliArgs(config)],
observer: {
onStdout: stdout => {
if (isVerbose()) {
Expand Down Expand Up @@ -66,12 +69,13 @@ export async function executeRunnerConfig(

export async function executeRunnerFunction(
runner: RunnerFunction,
config: PersistConfig,
): Promise<RunnerResult> {
const date = new Date().toISOString();
const start = performance.now();

// execute plugin runner
const audits = await runner();
const audits = await runner(config);

// create runner result
return {
Expand All @@ -96,12 +100,13 @@ export class AuditOutputsMissingAuditError extends Error {

export async function executePluginRunner(
pluginConfig: Pick<PluginConfig, 'audits' | 'runner'>,
persist: Required<Pick<PersistConfig, 'outputDir'>>,
): Promise<Omit<RunnerResult, 'audits'> & { audits: AuditOutputs }> {
const { audits: pluginConfigAudits, runner } = pluginConfig;
const runnerResult: RunnerResult =
typeof runner === 'object'
? await executeRunnerConfig(runner)
: await executeRunnerFunction(runner);
? await executeRunnerConfig(runner, persist)
: await executeRunnerFunction(runner, persist);
const { audits: unvalidatedAuditOutputs, ...executionMeta } = runnerResult;

const result = auditOutputsSchema.safeParse(unvalidatedAuditOutputs);
Expand Down
2 changes: 1 addition & 1 deletion packages/models/docs/models-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ _Function._

_Parameters:_

- _none_
1. [PersistConfig](#persistconfig)

_Returns:_

Expand Down
2 changes: 2 additions & 0 deletions packages/models/src/lib/runner-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from 'zod/v4';
import { auditOutputsSchema } from './audit-output.js';
import { convertAsyncZodFunctionToSchema } from './implementation/function.js';
import { filePathSchema } from './implementation/schemas.js';
import { persistConfigSchema } from './persist-config.js';

export const outputTransformSchema = convertAsyncZodFunctionToSchema(
z.function({
Expand All @@ -25,6 +26,7 @@ export type RunnerConfig = z.infer<typeof runnerConfigSchema>;

export const runnerFunctionSchema = convertAsyncZodFunctionToSchema(
z.function({
input: [persistConfigSchema],
output: z.union([auditOutputsSchema, z.promise(auditOutputsSchema)]),
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-eslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { eslintPlugin } from './lib/eslint-plugin.js';
export default eslintPlugin;

export type { ESLintPluginConfig } from './lib/config.js';
export { ESLINT_PLUGIN_SLUG } from './lib/constants.js';

export {
eslintConfigFromAllNxProjects,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-eslint/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ESLINT_PLUGIN_SLUG = 'eslint';
3 changes: 2 additions & 1 deletion packages/plugin-eslint/src/lib/eslint-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
eslintPluginConfigSchema,
eslintPluginOptionsSchema,
} from './config.js';
import { ESLINT_PLUGIN_SLUG } from './constants.js';
import { listAuditsAndGroups } from './meta/index.js';
import { createRunnerConfig } from './runner/index.js';

Expand Down Expand Up @@ -60,7 +61,7 @@ export async function eslintPlugin(
) as typeof import('../../package.json');

return {
slug: 'eslint',
slug: ESLINT_PLUGIN_SLUG,
title: 'ESLint',
icon: 'eslint',
description: 'Official Code PushUp ESLint plugin',
Expand Down
Loading