From: eric thul Date: Sat, 19 Nov 2016 18:57:32 +0000 (-0500) Subject: Use emitError and emitWarning X-Git-Tag: 2.1.0~1^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=45c62a2c766132a13c546b19025e9c1ef25bcd5b;p=github%2Ffretlink%2Fpurs-loader.git Use emitError and emitWarning --- diff --git a/src/Psc.js b/src/Psc.js index 437eb91..8fe8437 100644 --- a/src/Psc.js +++ b/src/Psc.js @@ -40,10 +40,16 @@ function compile(psModule) { debug('finished compiling PureScript.') cache.compilationFinished = true if (code !== 0) { - cache.errors = stderr.join('') + const errorMessage = stderr.join(''); + if (errorMessage.length) { + psModule.emitError(errorMessage); + } 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 +89,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 diff --git a/src/PscIde.js b/src/PscIde.js index 2e105be..27b49f6 100644 --- a/src/PscIde.js +++ b/src/PscIde.js @@ -156,11 +156,17 @@ function rebuild(psModule) { .then(resolve) .catch(() => resolve(psModule)) } - cache.errors = compileMessages.join('\n') + const errorMessage = compileMessages.join('\n'); + if (errorMessage.length) { + psModule.emitError(errorMessage); + } resolve(psModule); } else { - cache.warnings = compileMessages.join('\n') - resolve(psModule) + const warningMessage = compileMessages.join('\n'); + if (options.warnings && warningMessage.length) { + psModule.emitWarning(warningMessage); + } + resolve(psModule); } }) }) diff --git a/src/index.js b/src/index.js index f3b2fde..7c29650 100644 --- a/src/index.js +++ b/src/index.js @@ -62,21 +62,6 @@ module.exports = function purescriptLoader(source, map) { psModuleMap: cache.psModuleMap } }) - - // add psc warnings to webpack compilation warnings - this._compiler.plugin('after-compile', (compilation, callback) => { - if (options.warnings && cache.warnings) { - compilation.warnings.unshift(`PureScript compilation:\n${cache.warnings}`) - cache.warnings = null; - } - - if (cache.errors) { - compilation.errors.unshift(`PureScript compilation:\n${cache.errors}`) - cache.errors = null; - } - - callback() - }) } const psModuleName = PsModuleMap.match(source) @@ -89,6 +74,8 @@ 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) } debug('loader called', psModule.name)