X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Findex.js;h=bd2a35d05435268319001d8795c926acba4d697c;hb=58f78e37f04f5f64d2d6f40acf650379b9f7eab2;hp=72da4d03648b8f67cb6c1d3389f9cd4f83cd29b7;hpb=d301b47d8fb7139d11f59c5d969bdde6132a8230;p=github%2Ffretlink%2Fpurs-loader.git 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') })