fix(core): prevent cmd popups from isolation (#26730)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
Isolation uses `fork` which can cause popups on windows

## Expected Behavior
Isolation uses `spawn` which doesn't cause popups when used with
windowsHide.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Craigory Coppola 2024-06-27 14:42:40 -04:00 committed by GitHub
parent f5c8eda6e1
commit 66140faeec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import { ChildProcess, Serializable, fork } from 'child_process';
import { ChildProcess, spawn } from 'child_process';
import path = require('path');
import { Socket, connect } from 'net';
import { PluginConfiguration } from '../../../config/nx-json';
@ -9,13 +10,13 @@ import { PluginConfiguration } from '../../../config/nx-json';
import { LoadedNxPlugin, nxPluginCache } from '../internal-api';
import { getPluginOsSocketPath } from '../../../daemon/socket-utils';
import { consumeMessagesFromSocket } from '../../../utils/consume-messages-from-socket';
import { signalToCode } from '../../../utils/exit-codes';
import {
consumeMessage,
isPluginWorkerResult,
sendMessageOverSocket,
} from './messaging';
import { Socket, connect } from 'net';
const cleanupFunctions = new Set<() => void>();
@ -248,7 +249,6 @@ function createWorkerExitHandler(
let cleanedUp = false;
const exitHandler = () => {
if (cleanedUp) return;
for (const fn of cleanupFunctions) {
fn();
}
@ -256,7 +256,10 @@ const exitHandler = () => {
};
process.on('exit', exitHandler);
process.on('SIGINT', exitHandler);
process.on('SIGINT', () => {
exitHandler();
process.exit(signalToCode('SIGINT'));
});
process.on('SIGTERM', exitHandler);
function registerPendingPromise(
@ -314,17 +317,21 @@ async function startPluginWorker() {
[process.pid, global.nxPluginWorkerCount++].join('-')
);
const worker = fork(workerPath, [ipcPath], {
const worker = spawn(
process.execPath,
[
...(isWorkerTypescript ? ['--require', 'ts-node/register'] : []),
workerPath,
ipcPath,
],
{
stdio: process.stdout.isTTY ? 'inherit' : 'ignore',
env,
execArgv: [
...process.execArgv,
// If the worker is typescript, we need to register ts-node
...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
],
detached: true,
});
worker.disconnect();
shell: false,
windowsHide: true,
}
);
worker.unref();
let attempts = 0;