aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/utils.js
diff options
context:
space:
mode:
authorCyril Sobierajewicz <cyril.sobierajewicz@fretlink.com>2018-12-03 16:07:05 +0100
committerCyril Sobierajewicz <cyril.sobierajewicz@fretlink.com>2018-12-03 16:07:05 +0100
commitd3f40b6f0b0f507308f8dfd91e9cf6d4745dbce8 (patch)
treed2239387b964c107986f0b5b92ed5bd2e0d0a673 /lib/utils.js
parent5c2f4e966ffec127ec561431187886c9053b01b9 (diff)
downloadpurs-loader-d3f40b6f0b0f507308f8dfd91e9cf6d4745dbce8.tar.gz
purs-loader-d3f40b6f0b0f507308f8dfd91e9cf6d4745dbce8.tar.zst
purs-loader-d3f40b6f0b0f507308f8dfd91e9cf6d4745dbce8.zip
Build v3.3.1
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js
new file mode 100644
index 0000000..ebee1d1
--- /dev/null
+++ b/lib/utils.js
@@ -0,0 +1,63 @@
1'use strict';
2
3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
6
7function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
8
9function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
11function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
12
13function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
14
15var path = require('path');
16
17exports.PscError = function (_Error) {
18 _inherits(PscError, _Error);
19
20 function PscError(message, modules) {
21 _classCallCheck(this, PscError);
22
23 var _this = _possibleConstructorReturn(this, (PscError.__proto__ || Object.getPrototypeOf(PscError)).call(this, message));
24
25 _this.modules = modules;
26 return _this;
27 }
28
29 _createClass(PscError, null, [{
30 key: 'name',
31 get: function get() {
32 return 'PscError';
33 }
34 }]);
35
36 return PscError;
37}(Error);
38
39var repeat = function repeat(value, times) {
40 return times <= 0 ? [] : [value].concat(_toConsumableArray(repeat(value, times - 1)));
41};
42var diffPursModuleNames = function diffPursModuleNames(from, target, parts) {
43 if (!from.length) return parts.concat(target);
44 if (!target.length) return parts.concat(repeat('..', from.length));
45
46 var _from = _toArray(from),
47 head_from = _from[0],
48 tail_from = _from.slice(1);
49
50 var _target = _toArray(target),
51 head_target = _target[0],
52 tail_target = _target.slice(1);
53
54 return head_from === head_target ? diffPursModuleNames(tail_from, tail_target, parts) : parts.concat(repeat('..', from.length), target);
55};
56exports.resolvePursModule = function (_ref) {
57 var baseModulePath = _ref.baseModulePath,
58 baseModuleName = _ref.baseModuleName,
59 targetModuleName = _ref.targetModuleName;
60
61 var parts = diffPursModuleNames(baseModuleName.split('.'), targetModuleName.split('.'), []);
62 return parts.length ? path.resolve(baseModulePath, path.join.apply(path, _toConsumableArray(parts)) + '.purs') : baseModulePath;
63}; \ No newline at end of file