aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bundle.js')
-rw-r--r--src/bundle.js21
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
13const dargs = require('./dargs'); 13const dargs = require('./dargs');
14 14
15module.exports = function bundle(options, cache) { 15module.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};