aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--index.js40
1 files changed, 23 insertions, 17 deletions
diff --git a/index.js b/index.js
index b06aed0..5f41361 100644
--- a/index.js
+++ b/index.js
@@ -61,12 +61,12 @@ module.exports = function purescriptLoader(source, map) {
61 61
62 // add psc warnings to webpack compilation warnings 62 // add psc warnings to webpack compilation warnings
63 this._compiler.plugin('after-compile', function (compilation, callback) { 63 this._compiler.plugin('after-compile', function (compilation, callback) {
64 if (options.warnings && cache.warnings && cache.warnings.length) { 64 if (options.warnings && cache.warnings) {
65 compilation.warnings.unshift('PureScript compilation:\n' + cache.warnings.join('')); 65 compilation.warnings.unshift('PureScript compilation:\n' + cache.warnings);
66 } 66 }
67 67
68 if (cache.errors && cache.errors.length) { 68 if (cache.errors) {
69 compilation.errors.unshift('PureScript compilation:\n' + cache.errors.join('\n')); 69 compilation.errors.unshift('PureScript compilation:\n' + cache.errors);
70 } 70 }
71 71
72 callback(); 72 callback();
@@ -89,6 +89,8 @@ module.exports = function purescriptLoader(source, map) {
89 cache: cache 89 cache: cache
90 }; 90 };
91 91
92 debug('loader called', psModule.name);
93
92 if (options.bundle) { 94 if (options.bundle) {
93 cache.bundleModules.push(psModule.name); 95 cache.bundleModules.push(psModule.name);
94 } 96 }
@@ -97,7 +99,7 @@ module.exports = function purescriptLoader(source, map) {
97 return connectIdeServer(psModule).then(rebuild).then(toJavaScript).then(psModule.load).catch(psModule.reject); 99 return connectIdeServer(psModule).then(rebuild).then(toJavaScript).then(psModule.load).catch(psModule.reject);
98 } 100 }
99 101
100 if (cache.compilation && cache.compilation.length) { 102 if (cache.compilationFinished) {
101 return toJavaScript(psModule).then(psModule.load).catch(psModule.reject); 103 return toJavaScript(psModule).then(psModule.load).catch(psModule.reject);
102 } 104 }
103 105
@@ -105,7 +107,7 @@ module.exports = function purescriptLoader(source, map) {
105 // references to compiled output are valid. 107 // references to compiled output are valid.
106 cache.deferred.push(psModule); 108 cache.deferred.push(psModule);
107 109
108 if (!cache.compilation) { 110 if (!cache.compilationStarted) {
109 return compile(psModule).then(function () { 111 return compile(psModule).then(function () {
110 return Promise.map(cache.deferred, function (psModule) { 112 return Promise.map(cache.deferred, function (psModule) {
111 if (_typeof(cache.ideServer) === 'object') cache.ideServer.kill(); 113 if (_typeof(cache.ideServer) === 'object') cache.ideServer.kill();
@@ -127,7 +129,7 @@ function toJavaScript(psModule) {
127 var bundlePath = path.resolve(options.bundleOutput); 129 var bundlePath = path.resolve(options.bundleOutput);
128 var jsPath = cache.bundle ? bundlePath : psModule.jsPath; 130 var jsPath = cache.bundle ? bundlePath : psModule.jsPath;
129 131
130 debug('loading JavaScript for', psModule.srcPath); 132 debug('loading JavaScript for', psModule.name);
131 133
132 return Promise.props({ 134 return Promise.props({
133 js: fs.readFileAsync(jsPath, 'utf8'), 135 js: fs.readFileAsync(jsPath, 'utf8'),
@@ -157,11 +159,9 @@ function compile(psModule) {
157 var cache = psModule.cache; 159 var cache = psModule.cache;
158 var stderr = []; 160 var stderr = [];
159 161
160 if (cache.compilation) return Promise.resolve(cache.compilation); 162 if (cache.compilationStarted) return Promise.resolve(psModule);
161 163
162 cache.compilation = []; 164 cache.compilationStarted = true;
163 cache.warnings = [];
164 cache.errors = [];
165 165
166 var args = dargs(Object.assign({ 166 var args = dargs(Object.assign({
167 _: options.src, 167 _: options.src,
@@ -176,17 +176,21 @@ function compile(psModule) {
176 176
177 var compilation = spawn(options.psc, args); 177 var compilation = spawn(options.psc, args);
178 178
179 compilation.stdout.on('data', function (data) {
180 return stderr.push(data.toString());
181 });
179 compilation.stderr.on('data', function (data) { 182 compilation.stderr.on('data', function (data) {
180 return stderr.push(data.toString()); 183 return stderr.push(data.toString());
181 }); 184 });
182 185
183 compilation.on('close', function (code) { 186 compilation.on('close', function (code) {
184 console.log('Finished compiling PureScript.'); 187 console.log('Finished compiling PureScript.');
188 cache.compilationFinished = true;
185 if (code !== 0) { 189 if (code !== 0) {
186 cache.compilation = cache.errors = stderr; 190 cache.errors = stderr.join('');
187 reject(true); 191 reject(true);
188 } else { 192 } else {
189 cache.compilation = cache.warnings = stderr; 193 cache.warnings = stderr.join('');
190 resolve(psModule); 194 resolve(psModule);
191 } 195 }
192 }); 196 });
@@ -240,10 +244,10 @@ function rebuild(psModule) {
240 return reject('psc-ide rebuild failed'); 244 return reject('psc-ide rebuild failed');
241 }); 245 });
242 } 246 }
243 cache.errors = compileMessages; 247 cache.errors = compileMessages.join('\n');
244 reject('psc-ide rebuild failed'); 248 reject('psc-ide rebuild failed');
245 } else { 249 } else {
246 cache.warnings = compileMessages; 250 cache.warnings = compileMessages.join('\n');
247 resolve(psModule); 251 resolve(psModule);
248 } 252 }
249 }); 253 });
@@ -348,7 +352,7 @@ function bundle(options, cache) {
348 }); 352 });
349 compilation.on('close', function (code) { 353 compilation.on('close', function (code) {
350 if (code !== 0) { 354 if (code !== 0) {
351 cache.errors.concat(stderr); 355 cache.errors = (cache.errors || '') + stderr.join('');
352 return reject(true); 356 return reject(true);
353 } 357 }
354 cache.bundle = stderr; 358 cache.bundle = stderr;
@@ -467,6 +471,8 @@ function dargs(obj) {
467 return args.push(arg, v); 471 return args.push(arg, v);
468 });else args.push(arg, obj[key]); 472 });else args.push(arg, obj[key]);
469 473
470 return args; 474 return args.filter(function (arg) {
475 return typeof arg !== 'boolean';
476 });
471 }, []); 477 }, []);
472} 478}