From f9d5f2faaa11b31661de1a1fcdad4ab51e8ef5fe Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Mon, 3 Dec 2018 11:37:46 +0100 Subject: Watch failed modules and their dependencies on compilation error --- src/utils.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/utils.js (limited to 'src/utils.js') diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..0ab00eb --- /dev/null +++ b/src/utils.js @@ -0,0 +1,23 @@ +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; +}; -- cgit v1.2.3