From 58f78e37f04f5f64d2d6f40acf650379b9f7eab2 Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 24 May 2016 07:34:35 -0400 Subject: [PATCH] Handler for multiple psc-ide-client data events Attach a handler to the `psc-ide-client` process to capture one or more chunks from the `data` event. Resolves #48 --- src/index.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 72da4d0..bd2a35d 100644 --- a/src/index.js +++ b/src/index.js @@ -216,11 +216,27 @@ function rebuild(psModule) { const args = dargs(options.pscIdeArgs) const ideClient = spawn('psc-ide-client', args) - ideClient.stdout.once('data', data => { + var stdout = '' + var stderr = '' + + ideClient.stdout.on('data', data => { + stdout = stdout + data.toString() + }) + + ideClient.stderr.on('data', data => { + stderr = stderr + data.toString() + }) + + ideClient.on('close', code => { + if (code !== 0) { + const error = stderr === '' ? 'Failed to spawn psc-ide-client' : stderr + return reject(new Error(error)) + } + let res = null try { - res = JSON.parse(data.toString()) + res = JSON.parse(stdout.toString()) debug(res) } catch (err) { return reject(err) @@ -254,8 +270,6 @@ function rebuild(psModule) { }) }) - ideClient.stderr.once('data', data => reject(data.toString())) - ideClient.stdin.write(JSON.stringify(body)) ideClient.stdin.write('\n') }) -- 2.41.0