aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Psc.js15
-rw-r--r--src/PscIde.js12
-rw-r--r--src/index.js17
3 files changed, 23 insertions, 21 deletions
diff --git a/src/Psc.js b/src/Psc.js
index 437eb91..8fe8437 100644
--- a/src/Psc.js
+++ b/src/Psc.js
@@ -40,10 +40,16 @@ function compile(psModule) {
40 debug('finished compiling PureScript.') 40 debug('finished compiling PureScript.')
41 cache.compilationFinished = true 41 cache.compilationFinished = true
42 if (code !== 0) { 42 if (code !== 0) {
43 cache.errors = stderr.join('') 43 const errorMessage = stderr.join('');
44 if (errorMessage.length) {
45 psModule.emitError(errorMessage);
46 }
44 reject(new Error('compilation failed')) 47 reject(new Error('compilation failed'))
45 } else { 48 } else {
46 cache.warnings = stderr.join('') 49 const warningMessage = stderr.join('');
50 if (options.warnings && warningMessage.length) {
51 psModule.emitWarning(warningMessage);
52 }
47 resolve(psModule) 53 resolve(psModule)
48 } 54 }
49 }) 55 })
@@ -83,7 +89,10 @@ function bundle(options, cache) {
83 compilation.on('close', code => { 89 compilation.on('close', code => {
84 debug('finished bundling PureScript.') 90 debug('finished bundling PureScript.')
85 if (code !== 0) { 91 if (code !== 0) {
86 cache.errors = (cache.errors || '') + stderr.join('') 92 const errorMessage = stderr.join('');
93 if (errorMessage.length) {
94 psModule.emitError(errorMessage);
95 }
87 return reject(new Error('bundling failed')) 96 return reject(new Error('bundling failed'))
88 } 97 }
89 cache.bundle = stderr 98 cache.bundle = stderr
diff --git a/src/PscIde.js b/src/PscIde.js
index 2e105be..27b49f6 100644
--- a/src/PscIde.js
+++ b/src/PscIde.js
@@ -156,11 +156,17 @@ function rebuild(psModule) {
156 .then(resolve) 156 .then(resolve)
157 .catch(() => resolve(psModule)) 157 .catch(() => resolve(psModule))
158 } 158 }
159 cache.errors = compileMessages.join('\n') 159 const errorMessage = compileMessages.join('\n');
160 if (errorMessage.length) {
161 psModule.emitError(errorMessage);
162 }
160 resolve(psModule); 163 resolve(psModule);
161 } else { 164 } else {
162 cache.warnings = compileMessages.join('\n') 165 const warningMessage = compileMessages.join('\n');
163 resolve(psModule) 166 if (options.warnings && warningMessage.length) {
167 psModule.emitWarning(warningMessage);
168 }
169 resolve(psModule);
164 } 170 }
165 }) 171 })
166 }) 172 })
diff --git a/src/index.js b/src/index.js
index f3b2fde..7c29650 100644
--- a/src/index.js
+++ b/src/index.js
@@ -62,21 +62,6 @@ module.exports = function purescriptLoader(source, map) {
62 psModuleMap: cache.psModuleMap 62 psModuleMap: cache.psModuleMap
63 } 63 }
64 }) 64 })
65
66 // add psc warnings to webpack compilation warnings
67 this._compiler.plugin('after-compile', (compilation, callback) => {
68 if (options.warnings && cache.warnings) {
69 compilation.warnings.unshift(`PureScript compilation:\n${cache.warnings}`)
70 cache.warnings = null;
71 }
72
73 if (cache.errors) {
74 compilation.errors.unshift(`PureScript compilation:\n${cache.errors}`)
75 cache.errors = null;
76 }
77
78 callback()
79 })
80 } 65 }
81 66
82 const psModuleName = PsModuleMap.match(source) 67 const psModuleName = PsModuleMap.match(source)
@@ -89,6 +74,8 @@ module.exports = function purescriptLoader(source, map) {
89 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')), 74 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')),
90 options: options, 75 options: options,
91 cache: cache, 76 cache: cache,
77 emitWarning: warning => this.emitWarning(warning),
78 emitError: error => this.emitError(error)
92 } 79 }
93 80
94 debug('loader called', psModule.name) 81 debug('loader called', psModule.name)