diff options
author | eric thul <thul.eric@gmail.com> | 2016-05-24 07:34:35 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2016-05-24 07:34:35 -0400 |
commit | 58f78e37f04f5f64d2d6f40acf650379b9f7eab2 (patch) | |
tree | f07ede477182c88aa516db1b661e95011d11f748 /src | |
parent | 44eb153bce3d995e8ded6d5fef486567f5379d0d (diff) | |
download | purs-loader-58f78e37f04f5f64d2d6f40acf650379b9f7eab2.tar.gz purs-loader-58f78e37f04f5f64d2d6f40acf650379b9f7eab2.tar.zst purs-loader-58f78e37f04f5f64d2d6f40acf650379b9f7eab2.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 22 |
1 files 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) { | |||
216 | const args = dargs(options.pscIdeArgs) | 216 | const args = dargs(options.pscIdeArgs) |
217 | const ideClient = spawn('psc-ide-client', args) | 217 | const ideClient = spawn('psc-ide-client', args) |
218 | 218 | ||
219 | ideClient.stdout.once('data', data => { | 219 | var stdout = '' |
220 | var stderr = '' | ||
221 | |||
222 | ideClient.stdout.on('data', data => { | ||
223 | stdout = stdout + data.toString() | ||
224 | }) | ||
225 | |||
226 | ideClient.stderr.on('data', data => { | ||
227 | stderr = stderr + data.toString() | ||
228 | }) | ||
229 | |||
230 | ideClient.on('close', code => { | ||
231 | if (code !== 0) { | ||
232 | const error = stderr === '' ? 'Failed to spawn psc-ide-client' : stderr | ||
233 | return reject(new Error(error)) | ||
234 | } | ||
235 | |||
220 | let res = null | 236 | let res = null |
221 | 237 | ||
222 | try { | 238 | try { |
223 | res = JSON.parse(data.toString()) | 239 | res = JSON.parse(stdout.toString()) |
224 | debug(res) | 240 | debug(res) |
225 | } catch (err) { | 241 | } catch (err) { |
226 | return reject(err) | 242 | return reject(err) |
@@ -254,8 +270,6 @@ function rebuild(psModule) { | |||
254 | }) | 270 | }) |
255 | }) | 271 | }) |
256 | 272 | ||
257 | ideClient.stderr.once('data', data => reject(data.toString())) | ||
258 | |||
259 | ideClient.stdin.write(JSON.stringify(body)) | 273 | ideClient.stdin.write(JSON.stringify(body)) |
260 | ideClient.stdin.write('\n') | 274 | ideClient.stdin.write('\n') |
261 | }) | 275 | }) |