diff --git a/lib/src/child-writer/writer-proxy.js b/lib/src/child-writer/writer-proxy.js index c8c4fd9c..e9523d82 100644 --- a/lib/src/child-writer/writer-proxy.js +++ b/lib/src/child-writer/writer-proxy.js @@ -157,7 +157,21 @@ return isElevated().then((elevated) => { child.on('close', resolve); const emitMessage = (data) => { - ipc.of[process.env.IPC_SERVER_ID].emit('message', data.toString()); + + // Output from stdout/stderr coming from the CLI might be buffered, + // causing several progress lines to come up at once as single message. + // Trying to parse multiple JSON objects separated by new lines will + // of course make the parser confused, causing errors later on. + // + // As a solution, we split the data coming in from the CLI into + // separate lines, and only emit a "message" event for the last one. + // + // Since each line is terminated by a new line, the last string + // is an empty string, which we don't want to send to the IPC + // server, so we take the last element of every element but the last. + const object = _.last(_.initial(_.split(data.toString(), /\r?\n/))); + ipc.of[process.env.IPC_SERVER_ID].emit('message', object); + }; child.stdout.on('data', emitMessage);