blob: 8b5d87ffb99571805ac7f7ce5fe9732cfcb514ce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
'use strict';
const Promise = require('bluebird');
const spawn = require('cross-spawn');
const debug = require('debug')('purs-loader');
const dargs = require('./dargs');
module.exports = function compile(psModule) {
const options = psModule.options
const cache = psModule.cache
const stderr = []
const compileCommand = options.psc || 'purs';
const compileArgs = (options.psc ? [] : [ 'compile' ]).concat(dargs(Object.assign({
_: options.src,
output: options.output,
}, options.pscArgs)))
debug('spawning compiler %s %o', compileCommand, compileArgs)
return new Promise((resolve, reject) => {
debug('compiling PureScript...')
const compilation = spawn(compileCommand, compileArgs)
compilation.stderr.on('data', data => {
stderr.push(data.toString());
});
compilation.on('close', code => {
debug('finished compiling PureScript.')
if (code !== 0) {
const errorMessage = stderr.join('');
if (errorMessage.length) {
psModule.emitError(errorMessage);
}
if (options.watch) {
resolve(psModule);
}
else {
reject(new Error('compilation failed'))
}
} else {
const warningMessage = stderr.join('');
if (options.warnings && warningMessage.length) {
psModule.emitWarning(warningMessage);
}
resolve(psModule)
}
})
});
};
|