aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/index.js b/src/index.js
index b151d82..fce6394 100644
--- a/src/index.js
+++ b/src/index.js
@@ -26,6 +26,8 @@ const sourceMaps = require('./source-maps');
26 26
27const dargs = require('./dargs'); 27const dargs = require('./dargs');
28 28
29const utils = require('./utils');
30
29const spawn = require('cross-spawn').sync 31const spawn = require('cross-spawn').sync
30 32
31const eol = require('os').EOL 33const eol = require('os').EOL
@@ -186,9 +188,38 @@ module.exports = function purescriptLoader(source, map) {
186 CACHE_VAR.warnings.push(warning); 188 CACHE_VAR.warnings.push(warning);
187 } 189 }
188 }, 190 },
189 emitError: error => { 191 emitError: pscMessage => {
190 if (error.length) { 192 if (pscMessage.length) {
191 CACHE_VAR.errors.push(error); 193 const matchErrorsSeparator = /\n(?=Error)/;
194 const errors = pscMessage.split(matchErrorsSeparator);
195 for (const error of errors) {
196 const matchErrLocation = /at (.+\.purs) line (\d+), column (\d+) - line (\d+), column (\d+)/;
197 const [, filename] = matchErrLocation.exec(error) || [];
198 if (!filename) continue;
199
200 const baseModulePath = path.join(this.rootContext, filename);
201 this.addDependency(baseModulePath);
202
203 const matchErrModuleName = /in module ((?:\w+\.)*\w+)/;
204 const [, baseModuleName] = matchErrModuleName.exec(error) || [];
205 if (!baseModuleName) continue;
206
207 const matchMissingModuleName = /Module ((?:\w+\.)*\w+) was not found/;
208 const matchMissingImportFromModuleName = /Cannot import value \w+ from module ((?:\w+\.)*\w+)/;
209 for (const re of [matchMissingModuleName, matchMissingImportFromModuleName]) {
210 const [, targetModuleName] = re.exec(error) || [];
211 if (targetModuleName) {
212 const resolved = utils.resolvePursModule({
213 baseModulePath,
214 baseModuleName,
215 targetModuleName
216 });
217 this.addDependency(resolved);
218 }
219 }
220 }
221
222 CACHE_VAR.errors.push(pscMessage);
192 } 223 }
193 } 224 }
194 } 225 }