]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Handler for multiple psc-ide-client data events
authoreric thul <thul.eric@gmail.com>
Tue, 24 May 2016 11:34:35 +0000 (07:34 -0400)
committereric thul <thul.eric@gmail.com>
Tue, 24 May 2016 11:34:35 +0000 (07:34 -0400)
Attach a handler to the `psc-ide-client` process to capture one or more
chunks from the `data` event.

Resolves #48

src/index.js

index 72da4d03648b8f67cb6c1d3389f9cd4f83cd29b7..bd2a35d05435268319001d8795c926acba4d697c 100644 (file)
@@ -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')
   })