Skip to content

Commit

Permalink
fix(ngcc): display unlocker process output in sync mode
Browse files Browse the repository at this point in the history
The change in e041ac6
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 nodejs/node#3596 (comment).
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.
  • Loading branch information
petebacondarwin committed Apr 16, 2020
1 parent e22f60b commit a07663a
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ 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<Writable, Readable, Readable>;
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'}) as
ChildProcessByStdio<Writable, Readable, Readable>;
if (isWindows) {
unlocker.stdout.on('data', process.stdout.write.bind(process.stdout));
unlocker.stderr.on('data', process.stderr.write.bind(process.stderr));
}
return unlocker;
}
}

0 comments on commit a07663a

Please sign in to comment.