From cabf997933541d726a4cb05e450903d03144fbe9 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 16 Apr 2020 12:55:40 +0100 Subject: [PATCH] fix(ngcc): display unlocker process output in sync mode (#36637) The change in e041ac6f0d8c519d104601b2b49c008721c074b7 to support sending unlocker process output to the main ngcc console output prevents messages require that the main process relinquishes the event-loop to allow the `stdout.on()` handler to run. This results in none of the messages being written when ngcc is run in `--no-async` mode, and some messages failing to be written if the main process is killed (e.g. ctrl-C). It appears that the problem with Windows and detached processes is known - see https://github.com/nodejs/node/issues/3596#issuecomment-250890218. But in the meantime, this commit is a workaround, where non-Windows `inherit` the main process `stdout` while on Windows it reverts to the async handler approach, which is better than nothing. PR Close #36637 --- .../lock_file_with_child_process/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/locking/lock_file_with_child_process/index.ts b/packages/compiler-cli/ngcc/src/locking/lock_file_with_child_process/index.ts index 9dcb848829..e85ffca92b 100644 --- a/packages/compiler-cli/ngcc/src/locking/lock_file_with_child_process/index.ts +++ b/packages/compiler-cli/ngcc/src/locking/lock_file_with_child_process/index.ts @@ -82,14 +82,14 @@ export class LockFileWithChildProcess implements LockFile { this.logger.debug('Forking unlocker child-process'); const logLevel = this.logger.level !== undefined ? this.logger.level.toString() : LogLevel.info.toString(); - - const unlocker = fork(this.fs.resolve(__dirname, './unlocker.js'), [path, logLevel], { - detached: true, - stdio: 'pipe', - }) as ChildProcessByStdio; - unlocker.stdout.on('data', data => process.stdout.write(data)); - unlocker.stderr.on('data', data => process.stderr.write(data)); - + const isWindows = process.platform === 'win32'; + const unlocker = fork( + this.fs.resolve(__dirname, './unlocker.js'), [path, logLevel], + {detached: true, stdio: isWindows ? 'pipe' : 'inherit'}); + if (isWindows) { + unlocker.stdout?.on('data', process.stdout.write.bind(process.stdout)); + unlocker.stderr?.on('data', process.stderr.write.bind(process.stderr)); + } return unlocker; } }