diff options
author | eric thul <thul.eric@gmail.com> | 2017-04-23 18:17:27 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2017-04-23 18:20:22 -0400 |
commit | 78e2b0d91f5eb98674c5b05db0ef2c4f417581c0 (patch) | |
tree | d76942d9da52f7b72747ac2c825b80e8c27b57fb /src | |
parent | e17196589a380eed3ffc47705f8c6c87f99b58c2 (diff) | |
download | purs-loader-78e2b0d91f5eb98674c5b05db0ef2c4f417581c0.tar.gz purs-loader-78e2b0d91f5eb98674c5b05db0ef2c4f417581c0.tar.zst purs-loader-78e2b0d91f5eb98674c5b05db0ef2c4f417581c0.zip |
Handle multiple forced compiles on rebuild
Resolves #90
Diffstat (limited to 'src')
-rw-r--r-- | src/bundle.js | 2 | ||||
-rw-r--r-- | src/compile.js | 2 | ||||
-rw-r--r-- | src/ide.js | 8 | ||||
-rw-r--r-- | src/index.js | 50 |
4 files changed, 42 insertions, 20 deletions
diff --git a/src/bundle.js b/src/bundle.js index 3f55f01..99633f1 100644 --- a/src/bundle.js +++ b/src/bundle.js | |||
@@ -27,7 +27,7 @@ module.exports = function bundle(options, bundleModules) { | |||
27 | 27 | ||
28 | bundleModules.forEach(name => bundleArgs.push('--module', name)) | 28 | bundleModules.forEach(name => bundleArgs.push('--module', name)) |
29 | 29 | ||
30 | debug('bundle: %s %o', bundleCommand, bundleArgs); | 30 | debug('bundle: %s %O', bundleCommand, bundleArgs); |
31 | 31 | ||
32 | return (new Promise((resolve, reject) => { | 32 | return (new Promise((resolve, reject) => { |
33 | debug('bundling PureScript...') | 33 | debug('bundling PureScript...') |
diff --git a/src/compile.js b/src/compile.js index 707605c..6759bf3 100644 --- a/src/compile.js +++ b/src/compile.js | |||
@@ -24,7 +24,7 @@ module.exports = function compile(psModule) { | |||
24 | 24 | ||
25 | const stderr = []; | 25 | const stderr = []; |
26 | 26 | ||
27 | debug('compile %s %o', compileCommand, compileArgs) | 27 | debug('compile %s %O', compileCommand, compileArgs) |
28 | 28 | ||
29 | return new Promise((resolve, reject) => { | 29 | return new Promise((resolve, reject) => { |
30 | debug('compiling PureScript...') | 30 | debug('compiling PureScript...') |
@@ -44,7 +44,7 @@ function spawnIdeClient(body, options) { | |||
44 | 44 | ||
45 | const stdout = []; | 45 | const stdout = []; |
46 | 46 | ||
47 | debug('ide client %s %o %o', ideClientCommand, ideClientArgs, body); | 47 | debug('ide client %s %o %O', ideClientCommand, ideClientArgs, body); |
48 | 48 | ||
49 | return new Promise((resolve, reject) => { | 49 | return new Promise((resolve, reject) => { |
50 | const ideClient = spawn(ideClientCommand, ideClientArgs); | 50 | const ideClient = spawn(ideClientCommand, ideClientArgs); |
@@ -211,7 +211,7 @@ module.exports.rebuild = function rebuild(psModule) { | |||
211 | try { | 211 | try { |
212 | const parsed = JSON.parse(response); | 212 | const parsed = JSON.parse(response); |
213 | 213 | ||
214 | debugVerbose('parsed JSON response: %o', parsed); | 214 | debugVerbose('parsed JSON response: %O', parsed); |
215 | 215 | ||
216 | return Promise.resolve(parsed); | 216 | return Promise.resolve(parsed); |
217 | } | 217 | } |
@@ -224,7 +224,7 @@ module.exports.rebuild = function rebuild(psModule) { | |||
224 | const result = Array.isArray(parsed.result) ? parsed.result : []; | 224 | const result = Array.isArray(parsed.result) ? parsed.result : []; |
225 | 225 | ||
226 | return Promise.map(result, (item, i) => { | 226 | return Promise.map(result, (item, i) => { |
227 | debugVerbose('formatting result %o', item); | 227 | debugVerbose('formatting result %O', item); |
228 | 228 | ||
229 | return formatIdeResult(item, options, i, result.length); | 229 | return formatIdeResult(item, options, i, result.length); |
230 | }).then(formatted => ({ | 230 | }).then(formatted => ({ |
@@ -254,7 +254,7 @@ module.exports.rebuild = function rebuild(psModule) { | |||
254 | 254 | ||
255 | return isModuleNotFound || isUnknownModule || isUnknownModuleImport; | 255 | return isModuleNotFound || isUnknownModule || isUnknownModuleImport; |
256 | })) { | 256 | })) { |
257 | debug('failed to rebuild because the module is unknown') | 257 | debug('module %s was not rebuilt because the module is unknown', psModule.name); |
258 | 258 | ||
259 | return Promise.reject(new UnknownModuleError()); | 259 | return Promise.reject(new UnknownModuleError()); |
260 | } | 260 | } |
diff --git a/src/index.js b/src/index.js index 19a549e..f77e5f8 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -137,8 +137,8 @@ module.exports = function purescriptLoader(source, map) { | |||
137 | psModuleMap: cache.psModuleMap, | 137 | psModuleMap: cache.psModuleMap, |
138 | warnings: [], | 138 | warnings: [], |
139 | errors: [], | 139 | errors: [], |
140 | compilationStarted: cache.compilationStarted, | 140 | compilationStarted: false, |
141 | compilationFinished: cache.compilationFinished, | 141 | compilationFinished: false, |
142 | installed: cache.installed, | 142 | installed: cache.installed, |
143 | srcOption: cache.srcOption | 143 | srcOption: cache.srcOption |
144 | }; | 144 | }; |
@@ -217,8 +217,20 @@ module.exports = function purescriptLoader(source, map) { | |||
217 | }; | 217 | }; |
218 | 218 | ||
219 | const rebuild = () => | 219 | const rebuild = () => |
220 | ide.rebuild(psModule).catch(error => { | 220 | ide.rebuild(psModule) |
221 | .then(() => | ||
222 | toJavaScript(psModule) | ||
223 | .then(psModule.load) | ||
224 | .catch(psModule.reject) | ||
225 | ) | ||
226 | .catch(error => { | ||
221 | if (error instanceof ide.UnknownModuleError) { | 227 | if (error instanceof ide.UnknownModuleError) { |
228 | // Store the modules that trigger a recompile due to an | ||
229 | // unknown module error. We need to wait until compilation is | ||
230 | // done before loading these files. | ||
231 | |||
232 | cache.deferred.push(psModule); | ||
233 | |||
222 | if (!cache.compilationStarted) { | 234 | if (!cache.compilationStarted) { |
223 | cache.compilationStarted = true; | 235 | cache.compilationStarted = true; |
224 | 236 | ||
@@ -233,28 +245,37 @@ module.exports = function purescriptLoader(source, map) { | |||
233 | cache.psModuleMap = map; | 245 | cache.psModuleMap = map; |
234 | }) | 246 | }) |
235 | ) | 247 | ) |
236 | .then(() => ide.load(psModule)) | 248 | .then(() => |
237 | .then(() => psModule) | 249 | Promise.map(cache.deferred, psModule => |
250 | ide.load(psModule) | ||
251 | .then(() => toJavaScript(psModule)) | ||
252 | .then(psModule.load) | ||
253 | ) | ||
254 | ) | ||
255 | .catch(error => { | ||
256 | cache.deferred[0].reject(error); | ||
257 | |||
258 | cache.deferred.slice(1).forEach(psModule => { | ||
259 | psModule.reject(new Error('purs-loader failed')); | ||
260 | }) | ||
261 | }) | ||
238 | ; | 262 | ; |
239 | } | 263 | } |
240 | else { | 264 | else { |
241 | return Promise.resolve(psModule); | 265 | // The compilation has started. We must wait until it is |
266 | // done in order to ensure the module map contains all of | ||
267 | // the unknown modules. | ||
242 | } | 268 | } |
243 | } | 269 | } |
244 | else { | 270 | else { |
245 | debug('ide rebuild failed due to an unhandled error: %o', error); | 271 | debug('ide rebuild failed due to an unhandled error: %o', error); |
246 | 272 | ||
247 | return Promise.reject(error); | 273 | psModule.reject(error); |
248 | } | 274 | } |
249 | }) | 275 | }) |
250 | ; | 276 | ; |
251 | 277 | ||
252 | connect() | 278 | connect().then(rebuild); |
253 | .then(rebuild) | ||
254 | .then(toJavaScript) | ||
255 | .then(psModule.load) | ||
256 | .catch(psModule.reject) | ||
257 | ; | ||
258 | } | 279 | } |
259 | else if (cache.compilationFinished) { | 280 | else if (cache.compilationFinished) { |
260 | debugVerbose('compilation is already finished, loading module %s', psModule.name); | 281 | debugVerbose('compilation is already finished, loading module %s', psModule.name); |
@@ -292,7 +313,8 @@ module.exports = function purescriptLoader(source, map) { | |||
292 | ) | 313 | ) |
293 | .then(() => | 314 | .then(() => |
294 | Promise.map(cache.deferred, psModule => | 315 | Promise.map(cache.deferred, psModule => |
295 | toJavaScript(psModule).then(psModule.load) | 316 | toJavaScript(psModule) |
317 | .then(psModule.load) | ||
296 | ) | 318 | ) |
297 | ) | 319 | ) |
298 | .catch(error => { | 320 | .catch(error => { |