Skip to content

Commit cbf9d19

Browse files
author
John Doe
committed
refactor: move objToCliArgs parts and reuse
1 parent 2b05307 commit cbf9d19

File tree

5 files changed

+14
-149
lines changed

5 files changed

+14
-149
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type ExecutorContext } from '@nx/devkit';
22
import { executeProcess } from '../../internal/execute-process.js';
3-
import { objectToCliArgs } from '../internal/cli.js';
43
import type { AutorunCommandExecutorOptions } from './schema.js';
54

65
export type ExecutorOutput = {
@@ -13,6 +12,9 @@ export default async function runAutorunExecutor(
1312
terminalAndExecutorOptions: AutorunCommandExecutorOptions,
1413
{ cwd }: ExecutorContext,
1514
): Promise<ExecutorOutput> {
15+
const { logger, stringifyError, formatCommand, objectToCliArgs } =
16+
await import('@code-pushup/utils');
17+
1618
const {
1719
dryRun,
1820
verbose,
@@ -21,6 +23,7 @@ export default async function runAutorunExecutor(
2123
bin,
2224
...argsObj
2325
} = terminalAndExecutorOptions;
26+
2427
const command = bin ? `node` : 'npx';
2528
const positionals = [
2629
bin ?? '@code-pushup/cli',
@@ -32,9 +35,6 @@ export default async function runAutorunExecutor(
3235
...(verbose && { CP_VERBOSE: 'true' }),
3336
};
3437

35-
const { logger, stringifyError, formatCommand } = await import(
36-
'@code-pushup/utils'
37-
);
3838
const binString = `${command} ${positionals.join(' ')} ${args.join(' ')}`;
3939
const formattedBinString = formatCommand(binString, {
4040
env: envVariables,

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 0 additions & 91 deletions
This file was deleted.

packages/utils/src/lib/transform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export function objectToCliArgs<
102102
return [`${prefix}${value ? '' : 'no-'}${key}`];
103103
}
104104

105+
if (value === null || value === undefined) {
106+
return [];
107+
}
108+
105109
throw new Error(`Unsupported type ${typeof value} for key ${key}`);
106110
});
107111
}

packages/utils/src/lib/transform.unit.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ describe('objectToCliArgs', () => {
226226
]);
227227
});
228228

229+
it('should handle objects with undefined', () => {
230+
const params = { format: undefined };
231+
const result = objectToCliArgs(params);
232+
expect(result).toStrictEqual([]);
233+
});
234+
229235
it('should throw error for unsupported type', () => {
230236
const params = { unsupported: undefined as any };
231237
expect(() => objectToCliArgs(params)).toThrow('Unsupported type');

0 commit comments

Comments
 (0)