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.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('')
+ 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)
}
})
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
if (!cache.ideServer && number === 9) {
debug(error)
- console.log(
- 'failed to connect to or start psc-ide-server, ' +
- 'full compilation will occur on rebuild'
- )
+ console.warn('Failed to connect to or start psc-ide-server. A full compilation will occur on rebuild');
return Promise.resolve(psModule)
}
}
if (res && !Array.isArray(res.result)) {
- return res.resultType === 'success'
- ? resolve(psModule)
- : reject(new Error('psc-ide rebuild failed'))
+ return resolve(psModule);
}
Promise.map(res.result, (item, i) => {
})
.then(compileMessages => {
if (res.resultType === 'error') {
- if (res.result.some(item => item.errorCode === 'UnknownModule' || item.errorCode === 'UnknownName')) {
+ if (res.result.some(item => {
+ const isUnknownModule = item.errorCode === 'UnknownModule';
+
+ const isUnknownModuleImport = item.errorCode === 'UnknownName' && /Unknown module/.test(item.message);
+
+ return isUnknownModule || isUnknownModuleImport;
+ })) {
debug('unknown module, attempting full recompile')
return Psc.compile(psModule)
.then(() => PsModuleMap.makeMap(options.src).then(map => {
}))
.then(() => request({ command: 'load' }))
.then(resolve)
- .catch(() => reject(new Error('psc-ide rebuild failed')))
+ .catch(() => resolve(psModule))
+ }
+ const errorMessage = compileMessages.join('\n');
+ if (errorMessage.length) {
+ psModule.emitError(errorMessage);
}
- cache.errors = compileMessages.join('\n')
- reject(new Error('psc-ide rebuild failed'))
+ 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);
}
})
})
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)
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)