From: eric thul Date: Sun, 20 Nov 2016 02:08:47 +0000 (-0500) Subject: Emit warnings/errors to the compilation instance X-Git-Tag: 2.1.1~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=b683b0b17cde53739ccb22da93ffb2bba2719667;p=github%2Ffretlink%2Fpurs-loader.git Emit warnings/errors to the compilation instance Avoids duplication of warnings. Resolves #78 --- diff --git a/src/Psc.js b/src/Psc.js index 8fe8437..4991d5f 100644 --- a/src/Psc.js +++ b/src/Psc.js @@ -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.') diff --git a/src/index.js b/src/index.js index 7c29650..f3390dc 100644 --- a/src/index.js +++ b/src/index.js @@ -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)