Skip to content

Commit 513f187

Browse files
BioPhotonJohn Doe
andauthored
refactor(nx-plugin): remove options merge (#1158)
Related to #1091 --------- Co-authored-by: John Doe <john.doe@example.com>
1 parent a83baae commit 513f187

File tree

4 files changed

+8
-71
lines changed

4 files changed

+8
-71
lines changed

e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ describe('executor command', () => {
204204
expect(cleanStdout).toContain('Code PushUp CLI');
205205

206206
await expect(
207-
readJsonFile(path.join(cwd, '.reports', 'terminal-report.json')),
207+
readJsonFile(
208+
path.join(cwd, '.code-pushup', project, 'terminal-report.json'),
209+
),
208210
).resolves.not.toThrow();
209211
});
210212

packages/nx-plugin/src/executors/cli/executor.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../internal/cli.js';
77
import { normalizeContext } from '../internal/context.js';
88
import type { AutorunCommandExecutorOptions } from './schema.js';
9-
import { mergeExecutorOptions, parseAutorunExecutorOptions } from './utils.js';
9+
import { parseAutorunExecutorOptions } from './utils.js';
1010

1111
export type ExecutorOutput = {
1212
success: boolean;
@@ -19,15 +19,11 @@ export default async function runAutorunExecutor(
1919
context: ExecutorContext,
2020
): Promise<ExecutorOutput> {
2121
const normalizedContext = normalizeContext(context);
22-
const mergedOptions = mergeExecutorOptions(
23-
context.target?.options,
24-
terminalAndExecutorOptions,
25-
);
2622
const cliArgumentObject = parseAutorunExecutorOptions(
27-
mergedOptions,
23+
terminalAndExecutorOptions,
2824
normalizedContext,
2925
);
30-
const { dryRun, verbose, command, bin } = mergedOptions;
26+
const { dryRun, verbose, command, bin } = terminalAndExecutorOptions;
3127
const commandString = createCliCommandString({
3228
command,
3329
args: cliArgumentObject,

packages/nx-plugin/src/executors/cli/utils.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function parseAutorunExecutorOptions(
3434
options: Partial<AutorunCommandExecutorOptions>,
3535
normalizedContext: NormalizedExecutorContext,
3636
): AutorunCommandExecutorOptions {
37-
const { projectPrefix, persist, upload, command } = options;
37+
const { projectPrefix, persist, upload, command, output } = options;
3838
const needsUploadParams =
3939
command === 'upload' || command === 'autorun' || command === undefined;
4040
const uploadCfg = uploadConfig(
@@ -46,48 +46,11 @@ export function parseAutorunExecutorOptions(
4646
...parsePrintConfigExecutorOptions(options),
4747
...parseAutorunExecutorOnlyOptions(options),
4848
...globalConfig(options, normalizedContext),
49+
...(output ? { output } : {}),
4950
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),
5051
// @TODO This is a hack to avoid validation errors of upload config for commands that dont need it.
5152
// Fix: use utils and execute the core logic directly
5253
// Blocked by Nx plugins can't compile to es6
5354
...(needsUploadParams && hasApiToken ? { upload: uploadCfg } : {}),
5455
};
5556
}
56-
57-
/**
58-
* Deeply merges executor options.
59-
*
60-
* @param targetOptions - The original options from the target configuration.
61-
* @param cliOptions - The options from Nx, combining target options and CLI arguments.
62-
* @returns A new object with deeply merged properties.
63-
*
64-
* Nx performs a shallow merge by default, where command-line arguments can override entire objects
65-
* (e.g., `--persist.filename` replaces the entire `persist` object).
66-
* This function ensures that nested properties are deeply merged,
67-
* preserving the original target options where CLI arguments are not provided.
68-
*/
69-
export function mergeExecutorOptions(
70-
targetOptions: Partial<AutorunCommandExecutorOptions>,
71-
cliOptions: Partial<AutorunCommandExecutorOptions>,
72-
): AutorunCommandExecutorOptions {
73-
return {
74-
...targetOptions,
75-
...cliOptions,
76-
...(targetOptions?.persist || cliOptions?.persist
77-
? {
78-
persist: {
79-
...targetOptions?.persist,
80-
...cliOptions?.persist,
81-
},
82-
}
83-
: {}),
84-
...(targetOptions?.upload || cliOptions?.upload
85-
? {
86-
upload: {
87-
...targetOptions?.upload,
88-
...cliOptions?.upload,
89-
},
90-
}
91-
: {}),
92-
};
93-
}

packages/nx-plugin/src/executors/cli/utils.unit.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { type MockInstance, expect, vi } from 'vitest';
22
import { osAgnosticPath } from '@code-pushup/test-utils';
33
import type { Command } from '../internal/types.js';
44
import {
5-
mergeExecutorOptions,
65
parseAutorunExecutorOnlyOptions,
76
parseAutorunExecutorOptions,
87
parsePrintConfigExecutorOptions,
@@ -170,26 +169,3 @@ describe('parseAutorunExecutorOptions', () => {
170169
},
171170
);
172171
});
173-
174-
describe('mergeExecutorOptions', () => {
175-
it('should deeply merge target and CLI options', () => {
176-
const targetOptions = {
177-
persist: {
178-
outputDir: '.reports',
179-
filename: 'report',
180-
},
181-
};
182-
const cliOptions = {
183-
persist: {
184-
filename: 'report-file',
185-
},
186-
};
187-
const expected = {
188-
persist: {
189-
outputDir: '.reports',
190-
filename: 'report-file',
191-
},
192-
};
193-
expect(mergeExecutorOptions(targetOptions, cliOptions)).toEqual(expected);
194-
});
195-
});

0 commit comments

Comments
 (0)