debug('spawning compiler %s %o', options.psc, args)
return (new Promise((resolve, reject) => {
- debug('\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 => {
- debug('Finished compiling PureScript.')
+ debug('finished compiling PureScript.')
cache.compilationFinished = true
if (code !== 0) {
- cache.errors = stderr.join('')
- reject(new Error('compilation failed'))
+ 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)
}
})
debug('spawning bundler %s %o', options.pscBundle, args.join(' '))
return (new Promise((resolve, reject) => {
- debug('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('')
+ const errorMessage = stderr.join('');
+ if (errorMessage.length) {
+ psModule.emitError(errorMessage);
+ }
return reject(new Error('bundling failed'))
}
cache.bundle = stderr