Skip to content

Commit 348246c

Browse files
author
John Doe
committed
refactor: set env vars if verbose is given
1 parent 513f187 commit 348246c

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ export default async function runAutorunExecutor(
2323
terminalAndExecutorOptions,
2424
normalizedContext,
2525
);
26-
const { dryRun, verbose, command, bin } = terminalAndExecutorOptions;
26+
const { dryRun, verbose, command, bin, ...args } = cliArgumentObject;
27+
const executorEnvVariables = {
28+
...(verbose && { CP_VERBOSE: 'true' }),
29+
};
2730
const commandString = createCliCommandString({
2831
command,
29-
args: cliArgumentObject,
32+
args: args,
3033
bin,
3134
});
32-
if (verbose) {
33-
logger.info(`Run CLI executor ${command ?? ''}`);
34-
logger.info(`Command: ${commandString}`);
35-
}
35+
3636
if (dryRun) {
3737
logger.warn(`DryRun execution of: ${commandString}`);
3838
} else {
3939
try {
4040
await executeProcess({
41-
...createCliCommandObject({ command, args: cliArgumentObject, bin }),
41+
...createCliCommandObject({ command, args, bin }),
4242
...(context.cwd ? { cwd: context.cwd } : {}),
43+
...(Object.keys(executorEnvVariables).length
44+
? { env: executorEnvVariables }
45+
: {}),
4346
});
4447
} catch (error) {
4548
logger.error(error);

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,17 @@ describe('runAutorunExecutor', () => {
108108
expect(output.command).toMatch('--upload.project="CLI"');
109109
});
110110

111-
it('should log information if verbose is set', async () => {
111+
it('should set env var information if verbose is set', async () => {
112112
const output = await runAutorunExecutor(
113113
{ verbose: true },
114114
{ ...executorContext('github-action'), cwd: '<CWD>' },
115115
);
116116
expect(executeProcessSpy).toHaveBeenCalledTimes(1);
117117

118-
expect(output.command).toMatch('--verbose');
118+
expect(output.command).not.toContain('--verbose');
119119
expect(loggerWarnSpy).toHaveBeenCalledTimes(0);
120-
expect(loggerInfoSpy).toHaveBeenCalledTimes(2);
121120
expect(loggerInfoSpy).toHaveBeenCalledWith(
122-
expect.stringContaining(`Run CLI executor`),
123-
);
124-
expect(loggerInfoSpy).toHaveBeenCalledWith(
125-
expect.stringContaining('Command: npx @code-pushup/cli'),
121+
expect.stringContaining('CP_VERBOSE=true'),
126122
);
127123
});
128124

@@ -132,9 +128,7 @@ describe('runAutorunExecutor', () => {
132128
expect(loggerInfoSpy).toHaveBeenCalledTimes(0);
133129
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
134130
expect(loggerWarnSpy).toHaveBeenCalledWith(
135-
expect.stringContaining(
136-
'DryRun execution of: npx @code-pushup/cli --dryRun',
137-
),
131+
expect.stringContaining('DryRun execution of'),
138132
);
139133
});
140134
});

0 commit comments

Comments
 (0)