Skip to content

Commit 80bc137

Browse files
committed
fix(core): handle run-commands targets with no commands
1 parent a71a6ca commit 80bc137

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

packages/nx/src/executors/run-commands/run-commands.impl.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ describe('Run Commands', () => {
2222
jest.clearAllMocks();
2323
});
2424

25+
it('should handle empty commands array', async () => {
26+
const result = await runCommands(
27+
{
28+
commands: [],
29+
__unparsed__: [],
30+
},
31+
context
32+
);
33+
expect(result.success).toEqual(true);
34+
expect(result.terminalOutput).toEqual('');
35+
});
36+
2537
it('should interpolate provided --args', async () => {
2638
const f = fileSync().name;
2739
const result = await runCommands(

packages/nx/src/executors/run-commands/run-commands.impl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as yargsParser from 'yargs-parser';
22
import { ExecutorContext } from '../../config/misc-interfaces';
33
import { isTuiEnabled } from '../../tasks-runner/is-tui-enabled';
44
import { PseudoTerminal } from '../../tasks-runner/pseudo-terminal';
5+
import { NoopChildProcess } from '../../tasks-runner/running-tasks/noop-child-process';
56
import {
67
ParallelRunningTasks,
78
runSingleCommandWithPseudoTerminal,
@@ -117,6 +118,11 @@ export async function runCommands(
117118
);
118119
}
119120

121+
// Handle empty commands array - return immediately with success
122+
if (normalized.commands.length === 0) {
123+
return new NoopChildProcess({ code: 0, terminalOutput: '' });
124+
}
125+
120126
const isSingleCommand = normalized.commands.length === 1;
121127

122128
const usePseudoTerminal =
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { Serializable } from 'child_process';
21
import { RunningTask } from './running-task';
32

43
export class NoopChildProcess implements RunningTask {
5-
constructor(private results: { code: number; terminalOutput: string }) {}
4+
private exitCallbacks: Array<(code: number, terminalOutput: string) => void> =
5+
[];
6+
private outputCallbacks: Array<(terminalOutput: string) => void> = [];
7+
8+
constructor(private results: { code: number; terminalOutput: string }) {
9+
// Call exit callbacks asynchronously to simulate task completion
10+
for (const cb of this.exitCallbacks) {
11+
cb(this.results.code, this.results.terminalOutput);
12+
}
13+
}
614

715
send(): void {}
816

@@ -14,7 +22,11 @@ export class NoopChildProcess implements RunningTask {
1422
return;
1523
}
1624

17-
onExit(cb: (code: number) => void): void {
18-
cb(this.results.code);
25+
onExit(cb: (code: number, terminalOutput: string) => void): void {
26+
cb(this.results.code, this.results.terminalOutput);
27+
}
28+
29+
onOutput(cb: (terminalOutput: string) => void): void {
30+
cb(this.results.terminalOutput);
1931
}
2032
}

0 commit comments

Comments
 (0)