From df05d7e1e854b318fc74f33ca701ed521fd3a5ce Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 19 Nov 2016 12:26:58 -0500 Subject: Always resolve on psc-ide rebuild failure The objective of enabling psc-ide is to obtain feedback immediately from the PureScript compiler. When the loader triggers an error to webpack, the bundle is invalidated and dependencies of the PureScript file that caused the error will be passed through the loader on the next successful rebuild. However, this behaviour adds time to the feedback loop. In order to reduce the time of the PureScript compiler feedback loop when in development, this commit always resolves the rebuild process with a success. Errors and warnings are still emitted, but the webpack bundle is not invalidated. This means that the loader will only be run for the current file being editted and the developer gets immediate feedback on success or failure when psc-ide is enabled. Resolves #76 --- src/PscIde.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/PscIde.js b/src/PscIde.js index c9d0cfa..b0b56a8 100644 --- a/src/PscIde.js +++ b/src/PscIde.js @@ -77,10 +77,7 @@ function connect(psModule) { 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) } @@ -133,9 +130,7 @@ function rebuild(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) => { @@ -153,10 +148,10 @@ function rebuild(psModule) { })) .then(() => request({ command: 'load' })) .then(resolve) - .catch(() => reject(new Error('psc-ide rebuild failed'))) + .catch(() => resolve(psModule)) } cache.errors = compileMessages.join('\n') - reject(new Error('psc-ide rebuild failed')) + resolve(psModule); } else { cache.warnings = compileMessages.join('\n') resolve(psModule) -- cgit v1.2.3 From 514ab14654d5809c2485455c875471328238d102 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 19 Nov 2016 12:47:18 -0500 Subject: Update debug statements during build/bundle --- src/Psc.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Psc.js b/src/Psc.js index 0aa9fe2..437eb91 100644 --- a/src/Psc.js +++ b/src/Psc.js @@ -29,7 +29,7 @@ function compile(psModule) { 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) @@ -37,7 +37,7 @@ function compile(psModule) { 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('') @@ -74,13 +74,14 @@ function bundle(options, cache) { 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('') return reject(new Error('bundling failed')) -- cgit v1.2.3 From 28124e28f18c5aae38e149a3fc9624b46a906281 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 19 Nov 2016 13:12:54 -0500 Subject: PscIde full recompile on unknown module imports Instead of forcing a recompile on an unknown value and on unknown module imports, opt to only recompile for unknown module imports. An unknown value may be a typo. Having a faster feedback loop in these cases seems ideal. --- src/PscIde.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PscIde.js b/src/PscIde.js index b0b56a8..2e105be 100644 --- a/src/PscIde.js +++ b/src/PscIde.js @@ -139,7 +139,13 @@ function rebuild(psModule) { }) .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 => { -- cgit v1.2.3 From 45c62a2c766132a13c546b19025e9c1ef25bcd5b Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 19 Nov 2016 13:57:32 -0500 Subject: Use emitError and emitWarning --- src/Psc.js | 15 ++++++++++++--- src/PscIde.js | 12 +++++++++--- src/index.js | 17 ++--------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Psc.js b/src/Psc.js index 437eb91..8fe8437 100644 --- a/src/Psc.js +++ b/src/Psc.js @@ -40,10 +40,16 @@ function compile(psModule) { 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) } }) @@ -83,7 +89,10 @@ function bundle(options, cache) { 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 diff --git a/src/PscIde.js b/src/PscIde.js index 2e105be..27b49f6 100644 --- a/src/PscIde.js +++ b/src/PscIde.js @@ -156,11 +156,17 @@ function rebuild(psModule) { .then(resolve) .catch(() => resolve(psModule)) } - cache.errors = compileMessages.join('\n') + const errorMessage = compileMessages.join('\n'); + if (errorMessage.length) { + psModule.emitError(errorMessage); + } 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); } }) }) diff --git a/src/index.js b/src/index.js index f3b2fde..7c29650 100644 --- a/src/index.js +++ b/src/index.js @@ -62,21 +62,6 @@ module.exports = function purescriptLoader(source, map) { 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) @@ -89,6 +74,8 @@ 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) } debug('loader called', psModule.name) -- cgit v1.2.3