aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAlex Mingoia <talk@alexmingoia.com>2016-05-12 13:57:55 -0700
committerAlex Mingoia <talk@alexmingoia.com>2016-05-12 13:57:55 -0700
commit5163b5a276920e80e71051266696e0d8a3908037 (patch)
treece509f31d19b9e02320bda57b1b0e764026d54bc /src
parentf23665b22bf96eabdfbfc95f20348c9475e85ecd (diff)
downloadpurs-loader-5163b5a276920e80e71051266696e0d8a3908037.tar.gz
purs-loader-5163b5a276920e80e71051266696e0d8a3908037.tar.zst
purs-loader-5163b5a276920e80e71051266696e0d8a3908037.zip
Disable instant psc-ide rebuilds by default.
Using psc-ide-server is experimental and there may be bugs or edge-cases.
Diffstat (limited to 'src')
-rw-r--r--src/index.js34
1 files changed, 20 insertions, 14 deletions
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) {
25 pscArgs: {}, 25 pscArgs: {},
26 pscBundle: 'psc-bundle', 26 pscBundle: 'psc-bundle',
27 pscBundleArgs: {}, 27 pscBundleArgs: {},
28 pscIde: false,
28 pscIdeColors: webpackOptions.psc === 'psa' || query.psc === 'psa', 29 pscIdeColors: webpackOptions.psc === 'psa' || query.psc === 'psa',
29 pscIdeArgs: {}, 30 pscIdeArgs: {},
30 bundleOutput: 'output/bundle.js', 31 bundleOutput: 'output/bundle.js',
@@ -56,7 +57,7 @@ module.exports = function purescriptLoader(source, map) {
56 // invalidate loader cache when bundle is marked as invalid (in watch mode) 57 // invalidate loader cache when bundle is marked as invalid (in watch mode)
57 this._compiler.plugin('invalid', () => { 58 this._compiler.plugin('invalid', () => {
58 cache = config.purescriptLoaderCache = { 59 cache = config.purescriptLoaderCache = {
59 rebuild: true, 60 rebuild: options.pscIde,
60 deferred: [], 61 deferred: [],
61 ideServer: cache.ideServer 62 ideServer: cache.ideServer
62 } 63 }
@@ -216,13 +217,19 @@ function rebuild(psModule) {
216 const ideClient = spawn('psc-ide-client', args) 217 const ideClient = spawn('psc-ide-client', args)
217 218
218 ideClient.stdout.once('data', data => { 219 ideClient.stdout.once('data', data => {
219 const res = JSON.parse(data.toString()) 220 let res = null
220 debug(res)
221 221
222 if (!Array.isArray(res.result)) { 222 try {
223 res = JSON.parse(data.toString())
224 debug(res)
225 } catch (err) {
226 return reject(err)
227 }
228
229 if (res && !Array.isArray(res.result)) {
223 return res.resultType === 'success' 230 return res.resultType === 'success'
224 ? resolve(psModule) 231 ? resolve(psModule)
225 : reject(res) 232 : reject('psc-ide rebuild failed')
226 } 233 }
227 234
228 Promise.map(res.result, (item, i) => { 235 Promise.map(res.result, (item, i) => {
@@ -231,8 +238,15 @@ function rebuild(psModule) {
231 }) 238 })
232 .then(compileMessages => { 239 .then(compileMessages => {
233 if (res.resultType === 'error') { 240 if (res.resultType === 'error') {
241 if (res.result.some(item => item.errorCode === 'UnknownModule')) {
242 console.log('Unknown module, attempting full recompile')
243 return compile(psModule)
244 .then(() => request({ command: 'load' }))
245 .then(resolve)
246 .catch(() => reject('psc-ide rebuild failed'))
247 }
234 cache.errors = compileMessages 248 cache.errors = compileMessages
235 reject(res) 249 reject('psc-ide rebuild failed')
236 } else { 250 } else {
237 cache.warnings = compileMessages 251 cache.warnings = compileMessages
238 resolve(psModule) 252 resolve(psModule)
@@ -251,14 +265,6 @@ function rebuild(psModule) {
251 params: { 265 params: {
252 file: psModule.srcPath, 266 file: psModule.srcPath,
253 } 267 }
254 }).catch(res => {
255 if (res.resultType === 'error') {
256 if (res.result.some(item => item.errorCode === 'UnknownModule')) {
257 console.log('Unknown module, attempting full recompile')
258 return compile(psModule).then(() => request({ command: 'load' }))
259 }
260 }
261 return Promise.resolve(psModule)
262 }) 268 })
263} 269}
264 270