diff options
author | eric thul <thul.eric@gmail.com> | 2017-04-23 14:00:35 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2017-04-23 18:20:22 -0400 |
commit | 7f0547d4e02d927e766de340152a2f75b659d889 (patch) | |
tree | d9dd41f5902d81f73ad64772b34291887f4b4fdf /src/bundle.js | |
parent | 1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9 (diff) | |
download | purs-loader-7f0547d4e02d927e766de340152a2f75b659d889.tar.gz purs-loader-7f0547d4e02d927e766de340152a2f75b659d889.tar.zst purs-loader-7f0547d4e02d927e766de340152a2f75b659d889.zip |
Refactoring cache usage
Diffstat (limited to 'src/bundle.js')
-rw-r--r-- | src/bundle.js | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/bundle.js b/src/bundle.js index 6627ffe..3f55f01 100644 --- a/src/bundle.js +++ b/src/bundle.js | |||
@@ -12,12 +12,10 @@ const debug = require('debug')('purs-loader'); | |||
12 | 12 | ||
13 | const dargs = require('./dargs'); | 13 | const dargs = require('./dargs'); |
14 | 14 | ||
15 | module.exports = function bundle(options, cache) { | 15 | module.exports = function bundle(options, bundleModules) { |
16 | if (cache.bundle) return Promise.resolve(cache.bundle) | ||
17 | |||
18 | const stdout = [] | 16 | const stdout = [] |
19 | 17 | ||
20 | const stderr = cache.bundle = [] | 18 | const stderr = [] |
21 | 19 | ||
22 | const bundleCommand = options.pscBundle || 'purs'; | 20 | const bundleCommand = options.pscBundle || 'purs'; |
23 | 21 | ||
@@ -27,9 +25,9 @@ module.exports = function bundle(options, cache) { | |||
27 | namespace: options.bundleNamespace, | 25 | namespace: options.bundleNamespace, |
28 | }, options.pscBundleArgs))); | 26 | }, options.pscBundleArgs))); |
29 | 27 | ||
30 | cache.bundleModules.forEach(name => bundleArgs.push('--module', name)) | 28 | bundleModules.forEach(name => bundleArgs.push('--module', name)) |
31 | 29 | ||
32 | debug('spawning bundler %s %o', bundleCommand, bundleArgs); | 30 | debug('bundle: %s %o', bundleCommand, bundleArgs); |
33 | 31 | ||
34 | return (new Promise((resolve, reject) => { | 32 | return (new Promise((resolve, reject) => { |
35 | debug('bundling PureScript...') | 33 | debug('bundling PureScript...') |
@@ -45,15 +43,16 @@ module.exports = function bundle(options, cache) { | |||
45 | 43 | ||
46 | if (code !== 0) { | 44 | if (code !== 0) { |
47 | const errorMessage = stderr.join(''); | 45 | const errorMessage = stderr.join(''); |
46 | |||
48 | if (errorMessage.length) { | 47 | if (errorMessage.length) { |
49 | psModule.emitError(errorMessage); | 48 | psModule.emitError(errorMessage); |
50 | } | 49 | } |
51 | return reject(new Error('bundling failed')) | ||
52 | } | ||
53 | 50 | ||
54 | cache.bundle = stderr | 51 | reject(new Error('bundling failed')) |
55 | 52 | } | |
56 | resolve(fs.appendFileAsync(options.bundleOutput, `module.exports = ${options.bundleNamespace}`)) | 53 | else { |
54 | resolve(fs.appendFileAsync(options.bundleOutput, `module.exports = ${options.bundleNamespace}`)) | ||
55 | } | ||
57 | }) | 56 | }) |
58 | })) | 57 | })) |
59 | }; | 58 | }; |