]> git.immae.eu Git - github/fretlink/purs-loader.git/blobdiff - src/Psc.js
Version 2.4.0-beta.0
[github/fretlink/purs-loader.git] / src / Psc.js
index 437eb9176e444406a436f9cfffc1c9c5ffe84a5a..ffa32b714a69c43bcf8954c8b8f9bb2e35d71c78 100644 (file)
@@ -33,17 +33,29 @@ function compile(psModule) {
 
     const compilation = spawn(options.psc, args)
 
-    compilation.stdout.on('data', data => stderr.push(data.toString()))
-    compilation.stderr.on('data', data => stderr.push(data.toString()))
+    compilation.stderr.on('data', data => {
+      stderr.push(data.toString());
+    });
 
     compilation.on('close', code => {
       debug('finished compiling PureScript.')
       cache.compilationFinished = true
       if (code !== 0) {
-        cache.errors = stderr.join('')
-        reject(new Error('compilation failed'))
+        const errorMessage = stderr.join('');
+        if (errorMessage.length) {
+          psModule.emitError(errorMessage);
+        }
+        if (options.watch) {
+          resolve(psModule);
+        }
+        else {
+          reject(new Error('compilation failed'))
+        }
       } else {
-        cache.warnings = stderr.join('')
+        const warningMessage = stderr.join('');
+        if (options.warnings && warningMessage.length) {
+          psModule.emitWarning(warningMessage);
+        }
         resolve(psModule)
       }
     })
@@ -83,7 +95,10 @@ function bundle(options, cache) {
     compilation.on('close', code => {
       debug('finished bundling PureScript.')
       if (code !== 0) {
-        cache.errors = (cache.errors || '') + stderr.join('')
+        const errorMessage = stderr.join('');
+        if (errorMessage.length) {
+          psModule.emitError(errorMessage);
+        }
         return reject(new Error('bundling failed'))
       }
       cache.bundle = stderr