fix(ngcc): display output from the unlocker process on Windows (#36569)

On Windows, the output of a detached process (such as the unlocker
process used by `LockFileWithChildProcess`) is not shown in the parent
process' stdout.

This commit addresses this by piping the spawned process' stdin/stdout
and manually writing to the parent process' stdout.

PR Close #36569
This commit is contained in:
George Kalpakas 2020-04-12 14:55:57 +03:00 committed by atscott
parent 66effde9f3
commit e041ac6f0d
1 changed files with 11 additions and 2 deletions

View File

@ -5,7 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ChildProcess, fork} from 'child_process';
import {ChildProcess, ChildProcessByStdio, fork} from 'child_process';
import {Readable, Writable} from 'stream';
import {AbsoluteFsPath, CachedFileSystem, FileSystem} from '../../../../src/ngtsc/file_system';
import {Logger, LogLevel} from '../../logging/logger';
@ -81,6 +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();
return fork(this.fs.resolve(__dirname, './unlocker.js'), [path, logLevel], {detached: true});
const unlocker = fork(this.fs.resolve(__dirname, './unlocker.js'), [path, logLevel], {
detached: true,
stdio: 'pipe',
}) as ChildProcessByStdio<Writable, Readable, Readable>;
unlocker.stdout.on('data', data => process.stdout.write(data));
unlocker.stderr.on('data', data => process.stderr.write(data));
return unlocker;
}
}