From b683b0b17cde53739ccb22da93ffb2bba2719667 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 19 Nov 2016 21:08:47 -0500 Subject: [PATCH] Emit warnings/errors to the compilation instance Avoids duplication of warnings. Resolves #78 --- src/Psc.js | 5 +++-- src/index.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) 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) -- 2.41.0