Skip to content

Commit 06bd7be

Browse files
committed
fix(core): pipe plugin stdout to avoid inconsistent terminal state
1 parent c2fba1f commit 06bd7be

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/nx/src/project-graph/plugins/isolation/plugin-pool.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,31 @@ async function startPluginWorker() {
415415
ipcPath,
416416
],
417417
{
418-
stdio: 'inherit',
418+
stdio: 'pipe',
419419
env,
420420
detached: true,
421421
shell: false,
422422
windowsHide: true,
423423
}
424424
);
425+
426+
// To make debugging easier and allow plugins to communicate things
427+
// like performance metrics, we pipe the stdout/stderr of the worker
428+
// to the main process.
429+
// This adds one listener per plugin to a few events on process.stdout/stderr,
430+
// so we need to increase the max listener count to avoid warnings.
431+
//
432+
// We originally used `inherit` for stdio, but that caused issues with
433+
// some environments where the terminal was left in an inconsistent state
434+
// that prevented `↑`/`↓` arrow keys from working correctly after Nx finished execution.
435+
// Instead, they would print things like `^[[A`/`^[[B` to the terminal.
436+
const stdoutMaxListeners = process.stdout.getMaxListeners();
437+
const stderrMaxListeners = process.stderr.getMaxListeners();
438+
process.stdout.setMaxListeners(stdoutMaxListeners + 1);
439+
process.stderr.setMaxListeners(stderrMaxListeners + 1);
440+
worker.stdout.pipe(process.stdout);
441+
worker.stderr.pipe(process.stderr);
442+
425443
worker.unref();
426444

427445
let attempts = 0;

0 commit comments

Comments
 (0)