diff options
author | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2018-12-03 11:37:46 +0100 |
---|---|---|
committer | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2018-12-03 11:57:30 +0100 |
commit | f9d5f2faaa11b31661de1a1fcdad4ab51e8ef5fe (patch) | |
tree | 7021319353b6c8af625563936deacc21a4311fe5 /src/utils.js | |
parent | 9dcf21578cb7e415e9670cd076182ee3c9b67a6b (diff) | |
download | purs-loader-f9d5f2faaa11b31661de1a1fcdad4ab51e8ef5fe.tar.gz purs-loader-f9d5f2faaa11b31661de1a1fcdad4ab51e8ef5fe.tar.zst purs-loader-f9d5f2faaa11b31661de1a1fcdad4ab51e8ef5fe.zip |
Watch failed modules and their dependencies on compilation error
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 23 |
1 files changed, 23 insertions, 0 deletions
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 @@ | |||
1 | const path = require('path'); | ||
2 | |||
3 | const repeat = (value, times) => | ||
4 | times <= 0 ? [] : [value, ...repeat(value, times - 1)]; | ||
5 | const diffPursModuleNames = (from, target, parts) => { | ||
6 | if (!from.length) return parts.concat(target); | ||
7 | if (!target.length) return parts.concat(repeat('..', from.length)); | ||
8 | const [head_from, ...tail_from] = from; | ||
9 | const [head_target, ...tail_target] = target; | ||
10 | return head_from === head_target | ||
11 | ? diffPursModuleNames(tail_from, tail_target, parts) | ||
12 | : parts.concat(repeat('..', from.length), target); | ||
13 | }; | ||
14 | exports.resolvePursModule = ({ baseModulePath, baseModuleName, targetModuleName }) => { | ||
15 | const parts = diffPursModuleNames( | ||
16 | baseModuleName.split('.'), | ||
17 | targetModuleName.split('.'), | ||
18 | []); | ||
19 | return parts.length | ||
20 | ? path.resolve(baseModulePath, | ||
21 | `${path.join(...parts)}.purs`) | ||
22 | : baseModulePath; | ||
23 | }; | ||