diff --git a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts index b482c717b..047fbfe24 100644 --- a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts @@ -204,7 +204,9 @@ describe('executor command', () => { expect(cleanStdout).toContain('Code PushUp CLI'); await expect( - readJsonFile(path.join(cwd, '.reports', 'terminal-report.json')), + readJsonFile( + path.join(cwd, '.code-pushup', project, 'terminal-report.json'), + ), ).resolves.not.toThrow(); }); diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 2e644f184..be932a35d 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -6,7 +6,7 @@ import { } from '../internal/cli.js'; import { normalizeContext } from '../internal/context.js'; import type { AutorunCommandExecutorOptions } from './schema.js'; -import { mergeExecutorOptions, parseAutorunExecutorOptions } from './utils.js'; +import { parseAutorunExecutorOptions } from './utils.js'; export type ExecutorOutput = { success: boolean; @@ -19,15 +19,11 @@ export default async function runAutorunExecutor( context: ExecutorContext, ): Promise { const normalizedContext = normalizeContext(context); - const mergedOptions = mergeExecutorOptions( - context.target?.options, - terminalAndExecutorOptions, - ); const cliArgumentObject = parseAutorunExecutorOptions( - mergedOptions, + terminalAndExecutorOptions, normalizedContext, ); - const { dryRun, verbose, command, bin } = mergedOptions; + const { dryRun, verbose, command, bin } = terminalAndExecutorOptions; const commandString = createCliCommandString({ command, args: cliArgumentObject, diff --git a/packages/nx-plugin/src/executors/cli/utils.ts b/packages/nx-plugin/src/executors/cli/utils.ts index 5530e00c0..b91753402 100644 --- a/packages/nx-plugin/src/executors/cli/utils.ts +++ b/packages/nx-plugin/src/executors/cli/utils.ts @@ -34,7 +34,7 @@ export function parseAutorunExecutorOptions( options: Partial, normalizedContext: NormalizedExecutorContext, ): AutorunCommandExecutorOptions { - const { projectPrefix, persist, upload, command } = options; + const { projectPrefix, persist, upload, command, output } = options; const needsUploadParams = command === 'upload' || command === 'autorun' || command === undefined; const uploadCfg = uploadConfig( @@ -46,6 +46,7 @@ export function parseAutorunExecutorOptions( ...parsePrintConfigExecutorOptions(options), ...parseAutorunExecutorOnlyOptions(options), ...globalConfig(options, normalizedContext), + ...(output ? { output } : {}), persist: persistConfig({ projectPrefix, ...persist }, normalizedContext), // @TODO This is a hack to avoid validation errors of upload config for commands that dont need it. // Fix: use utils and execute the core logic directly @@ -53,41 +54,3 @@ export function parseAutorunExecutorOptions( ...(needsUploadParams && hasApiToken ? { upload: uploadCfg } : {}), }; } - -/** - * Deeply merges executor options. - * - * @param targetOptions - The original options from the target configuration. - * @param cliOptions - The options from Nx, combining target options and CLI arguments. - * @returns A new object with deeply merged properties. - * - * Nx performs a shallow merge by default, where command-line arguments can override entire objects - * (e.g., `--persist.filename` replaces the entire `persist` object). - * This function ensures that nested properties are deeply merged, - * preserving the original target options where CLI arguments are not provided. - */ -export function mergeExecutorOptions( - targetOptions: Partial, - cliOptions: Partial, -): AutorunCommandExecutorOptions { - return { - ...targetOptions, - ...cliOptions, - ...(targetOptions?.persist || cliOptions?.persist - ? { - persist: { - ...targetOptions?.persist, - ...cliOptions?.persist, - }, - } - : {}), - ...(targetOptions?.upload || cliOptions?.upload - ? { - upload: { - ...targetOptions?.upload, - ...cliOptions?.upload, - }, - } - : {}), - }; -} diff --git a/packages/nx-plugin/src/executors/cli/utils.unit.test.ts b/packages/nx-plugin/src/executors/cli/utils.unit.test.ts index 5f94d7b37..9a75e744b 100644 --- a/packages/nx-plugin/src/executors/cli/utils.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/utils.unit.test.ts @@ -2,7 +2,6 @@ import { type MockInstance, expect, vi } from 'vitest'; import { osAgnosticPath } from '@code-pushup/test-utils'; import type { Command } from '../internal/types.js'; import { - mergeExecutorOptions, parseAutorunExecutorOnlyOptions, parseAutorunExecutorOptions, parsePrintConfigExecutorOptions, @@ -170,26 +169,3 @@ describe('parseAutorunExecutorOptions', () => { }, ); }); - -describe('mergeExecutorOptions', () => { - it('should deeply merge target and CLI options', () => { - const targetOptions = { - persist: { - outputDir: '.reports', - filename: 'report', - }, - }; - const cliOptions = { - persist: { - filename: 'report-file', - }, - }; - const expected = { - persist: { - outputDir: '.reports', - filename: 'report-file', - }, - }; - expect(mergeExecutorOptions(targetOptions, cliOptions)).toEqual(expected); - }); -});