fix(Execute Command Node): Don't spawn console on Windows (#40909)

This commit is contained in:
yehorkardash 2026-10-13 16:07:56 +00:00 committed by GitHub
parent 1d2c879fab
commit 52aed7ac97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View File

@ -45,7 +45,13 @@ async function execPromise(command: string, abortSignal?: AbortSignal): Promise<
// that detached console and their stdout never reaches our pipe. Windows kills
// the tree via `taskkill /T`, so detaching is unnecessary there.
const detached = process.platform !== 'win32';
const child = spawn(command, { cwd: process.cwd(), shell: true, detached });
// `windowsHide` stops Windows from opening a visible console window for the command.
const child = spawn(command, {
cwd: process.cwd(),
shell: true,
detached,
windowsHide: true,
});
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
@ -79,7 +85,7 @@ async function execPromise(command: string, abortSignal?: AbortSignal): Promise<
return;
}
if (process.platform === 'win32') {
spawn('taskkill', ['/pid', child.pid.toString(), '/T', '/F']);
spawn('taskkill', ['/pid', child.pid.toString(), '/T', '/F'], { windowsHide: true });
return;
}
try {

View File

@ -84,7 +84,13 @@ describe('ExecuteCommand cancellation', () => {
await Promise.resolve();
controller.abort();
expect(mockedSpawn).toHaveBeenCalledWith('taskkill', ['/pid', String(CHILD_PID), '/T', '/F']);
expect(mockedSpawn).toHaveBeenCalledWith(
'taskkill',
['/pid', String(CHILD_PID), '/T', '/F'],
{
windowsHide: true,
},
);
expect(killSpy).not.toHaveBeenCalled();
await expect(promise).rejects.toBeInstanceOf(ManualExecutionCancelledError);

View File

@ -64,4 +64,21 @@ describe('ExecuteCommand stdout on Windows', () => {
Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
}
});
it('hides the console window of the spawned command on Windows', async () => {
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
try {
const promise = node.execute.call(createContext());
await Promise.resolve();
child.emit('close', 0);
await promise;
const spawnOptions = mockedSpawn.mock.calls[0][1] as { windowsHide?: boolean };
expect(spawnOptions.windowsHide).toBe(true);
} finally {
Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
}
});
});