X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FPsc.js;h=ffa32b714a69c43bcf8954c8b8f9bb2e35d71c78;hb=3a4eb6d4238f63ef526a6343de220ceb97671511;hp=3901ecaa282e209c7c30c8a86780632026cdda98;hpb=c11cdf69a4b17bc3a9dff2850e2e3a9d0bc60c9d;p=github%2Ffretlink%2Fpurs-loader.git diff --git a/src/Psc.js b/src/Psc.js index 3901eca..ffa32b7 100644 --- a/src/Psc.js +++ b/src/Psc.js @@ -29,21 +29,33 @@ function compile(psModule) { debug('spawning compiler %s %o', options.psc, args) return (new Promise((resolve, reject) => { - console.log('\nCompiling PureScript...') + debug('compiling PureScript...') 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 => { - console.log('Finished compiling PureScript.') + debug('finished compiling PureScript.') cache.compilationFinished = true if (code !== 0) { - cache.errors = stderr.join('') - reject(true) + 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) } }) @@ -74,16 +86,20 @@ function bundle(options, cache) { debug('spawning bundler %s %o', options.pscBundle, args.join(' ')) return (new Promise((resolve, reject) => { - console.log('Bundling PureScript...') + debug('bundling PureScript...') const compilation = spawn(options.pscBundle, args) compilation.stdout.on('data', data => stdout.push(data.toString())) compilation.stderr.on('data', data => stderr.push(data.toString())) compilation.on('close', code => { + debug('finished bundling PureScript.') if (code !== 0) { - cache.errors = (cache.errors || '') + stderr.join('') - return reject(true) + const errorMessage = stderr.join(''); + if (errorMessage.length) { + psModule.emitError(errorMessage); + } + return reject(new Error('bundling failed')) } cache.bundle = stderr resolve(fs.appendFileAsync(options.bundleOutput, `module.exports = ${options.bundleNamespace}`))