From 5163b5a276920e80e71051266696e0d8a3908037 Mon Sep 17 00:00:00 2001 From: Alex Mingoia Date: Thu, 12 May 2016 13:57:55 -0700 Subject: Disable instant psc-ide rebuilds by default. Using psc-ide-server is experimental and there may be bugs or edge-cases. --- README.md | 8 ++++++++ src/index.js | 34 ++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ed25296..e7e0b45 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ const webpackConfig = { } ``` +### Options + Default options: ```javascript @@ -45,6 +47,7 @@ Default options: pscArgs: {}, pscBundle: 'psc-bundle', pscBundleArgs: {}, + pscIde: false, // instant rebuilds using psc-ide-server (experimental) pscIdeColors: false, // defaults to true if psc === 'psa' bundleOutput: 'output/bundle.js', bundleNamespace: 'PS', @@ -61,3 +64,8 @@ Default options: ], } ``` + +### Instant rebuilds (experimental) + +Experimental support for instant rebuilds using `psc-ide-server` can be enabled +via the `pscIde: true` option. diff --git a/src/index.js b/src/index.js index 17951d3..9db8a63 100644 --- a/src/index.js +++ b/src/index.js @@ -25,6 +25,7 @@ module.exports = function purescriptLoader(source, map) { pscArgs: {}, pscBundle: 'psc-bundle', pscBundleArgs: {}, + pscIde: false, pscIdeColors: webpackOptions.psc === 'psa' || query.psc === 'psa', pscIdeArgs: {}, bundleOutput: 'output/bundle.js', @@ -56,7 +57,7 @@ module.exports = function purescriptLoader(source, map) { // invalidate loader cache when bundle is marked as invalid (in watch mode) this._compiler.plugin('invalid', () => { cache = config.purescriptLoaderCache = { - rebuild: true, + rebuild: options.pscIde, deferred: [], ideServer: cache.ideServer } @@ -216,13 +217,19 @@ function rebuild(psModule) { const ideClient = spawn('psc-ide-client', args) ideClient.stdout.once('data', data => { - const res = JSON.parse(data.toString()) - debug(res) + let res = null - if (!Array.isArray(res.result)) { + try { + res = JSON.parse(data.toString()) + debug(res) + } catch (err) { + return reject(err) + } + + if (res && !Array.isArray(res.result)) { return res.resultType === 'success' ? resolve(psModule) - : reject(res) + : reject('psc-ide rebuild failed') } Promise.map(res.result, (item, i) => { @@ -231,8 +238,15 @@ function rebuild(psModule) { }) .then(compileMessages => { if (res.resultType === 'error') { + if (res.result.some(item => item.errorCode === 'UnknownModule')) { + console.log('Unknown module, attempting full recompile') + return compile(psModule) + .then(() => request({ command: 'load' })) + .then(resolve) + .catch(() => reject('psc-ide rebuild failed')) + } cache.errors = compileMessages - reject(res) + reject('psc-ide rebuild failed') } else { cache.warnings = compileMessages resolve(psModule) @@ -251,14 +265,6 @@ function rebuild(psModule) { params: { file: psModule.srcPath, } - }).catch(res => { - if (res.resultType === 'error') { - if (res.result.some(item => item.errorCode === 'UnknownModule')) { - console.log('Unknown module, attempting full recompile') - return compile(psModule).then(() => request({ command: 'load' })) - } - } - return Promise.resolve(psModule) }) } -- cgit v1.2.3