]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Emit warnings/errors to the compilation instance
authoreric thul <thul.eric@gmail.com>
Sun, 20 Nov 2016 02:08:47 +0000 (21:08 -0500)
committereric thul <thul.eric@gmail.com>
Sun, 20 Nov 2016 02:08:47 +0000 (21:08 -0500)
Avoids duplication of warnings. Resolves #78

src/Psc.js
src/index.js

index 8fe843751442b42b2dae5de7ca4374d996b03661..4991d5fd8c90a7cd4d6390a767f83e7322c6a362 100644 (file)
@@ -33,8 +33,9 @@ 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.')
index 7c296508a4e8b81cdb683d6351fd78b849f86984..f3390dca1a9b128d93c650962c792b8c8456f034 100644 (file)
@@ -44,7 +44,9 @@ module.exports = function purescriptLoader(source, map) {
   let cache = config.purescriptLoaderCache = config.purescriptLoaderCache || {
     rebuild: false,
     deferred: [],
-    bundleModules: []
+    bundleModules: [],
+    warnings: [],
+    errors: []
   }
 
   if (!config.purescriptLoaderInstalled) {
@@ -59,9 +61,24 @@ module.exports = function purescriptLoader(source, map) {
         deferred: [],
         bundleModules: [],
         ideServer: cache.ideServer,
-        psModuleMap: cache.psModuleMap
+        psModuleMap: cache.psModuleMap,
+        warnings: [],
+        errors: []
       }
-    })
+    });
+
+    // add psc warnings to webpack compilation warnings
+    this._compiler.plugin('after-compile', (compilation, callback) => {
+      cache.warnings.forEach(warning => {
+        compilation.warnings.push(warning);
+      });
+
+      cache.errors.forEach(error => {
+        compilation.errors.push(error);
+      });
+
+      callback()
+    });
   }
 
   const psModuleName = PsModuleMap.match(source)
@@ -74,8 +91,16 @@ module.exports = function purescriptLoader(source, map) {
     jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')),
     options: options,
     cache: cache,
-    emitWarning: warning => this.emitWarning(warning),
-    emitError: error => this.emitError(error)
+    emitWarning: warning => {
+      if (options.warnings && warning.length) {
+        cache.warnings.push(warning);
+      }
+    },
+    emitError: error => {
+      if (error.length) {
+        cache.errors.push(error);
+      }
+    }
   }
 
   debug('loader called', psModule.name)