Skip to content

Commit 21a11a7

Browse files
committed
fix(core): pipe plugin stdout to avoid inconsistent terminal state
1 parent 1eecf46 commit 21a11a7

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
@@ -444,13 +444,31 @@ async function startPluginWorker(name: string) {
444444
name,
445445
],
446446
{
447-
stdio: 'inherit',
447+
stdio: 'pipe',
448448
env,
449449
detached: true,
450450
shell: false,
451451
windowsHide: true,
452452
}
453453
);
454+
455+
// To make debugging easier and allow plugins to communicate things
456+
// like performance metrics, we pipe the stdout/stderr of the worker
457+
// to the main process.
458+
// This adds one listener per plugin to a few events on process.stdout/stderr,
459+
// so we need to increase the max listener count to avoid warnings.
460+
//
461+
// We originally used `inherit` for stdio, but that caused issues with
462+
// some environments where the terminal was left in an inconsistent state
463+
// that prevented `↑`/`↓` arrow keys from working correctly after Nx finished execution.
464+
// Instead, they would print things like `^[[A`/`^[[B` to the terminal.
465+
const stdoutMaxListeners = process.stdout.getMaxListeners();
466+
const stderrMaxListeners = process.stderr.getMaxListeners();
467+
process.stdout.setMaxListeners(stdoutMaxListeners + 1);
468+
process.stderr.setMaxListeners(stderrMaxListeners + 1);
469+
worker.stdout.pipe(process.stdout);
470+
worker.stderr.pipe(process.stderr);
471+
454472
worker.unref();
455473

456474
let attempts = 0;

0 commit comments

Comments
 (0)