const dargs = require('./dargs');
+const utils = require('./utils');
+
const spawn = require('cross-spawn').sync
const eol = require('os').EOL
CACHE_VAR.warnings.push(warning);
}
},
- emitError: error => {
- if (error.length) {
- CACHE_VAR.errors.push(error);
+ emitError: pscMessage => {
+ if (pscMessage.length) {
+ const matchErrorsSeparator = /\n(?=Error)/;
+ const errors = pscMessage.split(matchErrorsSeparator);
+ for (const error of errors) {
+ const matchErrLocation = /at (.+\.purs) line (\d+), column (\d+) - line (\d+), column (\d+)/;
+ const [, filename] = matchErrLocation.exec(error) || [];
+ if (!filename) continue;
+
+ const baseModulePath = path.join(this.rootContext, filename);
+ this.addDependency(baseModulePath);
+
+ const matchErrModuleName = /in module ((?:\w+\.)*\w+)/;
+ const [, baseModuleName] = matchErrModuleName.exec(error) || [];
+ if (!baseModuleName) continue;
+
+ const matchMissingModuleName = /Module ((?:\w+\.)*\w+) was not found/;
+ const matchMissingImportFromModuleName = /Cannot import value \w+ from module ((?:\w+\.)*\w+)/;
+ for (const re of [matchMissingModuleName, matchMissingImportFromModuleName]) {
+ const [, targetModuleName] = re.exec(error) || [];
+ if (targetModuleName) {
+ const resolved = utils.resolvePursModule({
+ baseModulePath,
+ baseModuleName,
+ targetModuleName
+ });
+ this.addDependency(resolved);
+ }
+ }
+ }
+
+ CACHE_VAR.errors.push(pscMessage);
}
}
}
--- /dev/null
+const path = require('path');
+
+const repeat = (value, times) =>
+ times <= 0 ? [] : [value, ...repeat(value, times - 1)];
+const diffPursModuleNames = (from, target, parts) => {
+ if (!from.length) return parts.concat(target);
+ if (!target.length) return parts.concat(repeat('..', from.length));
+ const [head_from, ...tail_from] = from;
+ const [head_target, ...tail_target] = target;
+ return head_from === head_target
+ ? diffPursModuleNames(tail_from, tail_target, parts)
+ : parts.concat(repeat('..', from.length), target);
+};
+exports.resolvePursModule = ({ baseModulePath, baseModuleName, targetModuleName }) => {
+ const parts = diffPursModuleNames(
+ baseModuleName.split('.'),
+ targetModuleName.split('.'),
+ []);
+ return parts.length
+ ? path.resolve(baseModulePath,
+ `${path.join(...parts)}.purs`)
+ : baseModulePath;
+};