Skip to content

fix(core): handle run-commands targets with no commands #31364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ describe('Run Commands', () => {
jest.clearAllMocks();
});

it('should handle empty commands array', async () => {
const result = await runCommands(
{
commands: [],
__unparsed__: [],
},
context
);
expect(result.success).toEqual(true);
expect(result.terminalOutput).toEqual('');
});

it('should interpolate provided --args', async () => {
const f = fileSync().name;
const result = await runCommands(
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as yargsParser from 'yargs-parser';
import { ExecutorContext } from '../../config/misc-interfaces';
import { isTuiEnabled } from '../../tasks-runner/is-tui-enabled';
import { PseudoTerminal } from '../../tasks-runner/pseudo-terminal';
import { NoopChildProcess } from '../../tasks-runner/running-tasks/noop-child-process';
import {
ParallelRunningTasks,
runSingleCommandWithPseudoTerminal,
Expand Down Expand Up @@ -117,6 +118,11 @@ export async function runCommands(
);
}

// Handle empty commands array - return immediately with success
if (normalized.commands.length === 0) {
return new NoopChildProcess({ code: 0, terminalOutput: '' });
}

const isSingleCommand = normalized.commands.length === 1;

const usePseudoTerminal =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Serializable } from 'child_process';
import { RunningTask } from './running-task';

export class NoopChildProcess implements RunningTask {
Expand All @@ -14,7 +13,11 @@ export class NoopChildProcess implements RunningTask {
return;
}

onExit(cb: (code: number) => void): void {
cb(this.results.code);
onExit(cb: (code: number, terminalOutput: string) => void): void {
cb(this.results.code, this.results.terminalOutput);
}

onOutput(cb: (terminalOutput: string) => void): void {
cb(this.results.terminalOutput);
}
}
Loading