Skip to content

Commit

Permalink
fix(ngcc): display output from the unlocker process on Windows (angul…
Browse files Browse the repository at this point in the history
…ar#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 angular#36569
  • Loading branch information
gkalpak authored and atscott committed Apr 15, 2020
1 parent 66effde commit e041ac6
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
}

0 comments on commit e041ac6

Please sign in to comment.