aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js59
1 files changed, 55 insertions, 4 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 3c73fc6..5767fc2 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,5 +1,7 @@
1'use strict'; 1'use strict';
2 2
3var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4
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; }; }(); 5var _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 6
5function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } 7function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
@@ -54,11 +56,60 @@ var diffPursModuleNames = function diffPursModuleNames(from, target, parts) {
54 56
55 return head_from === head_target ? diffPursModuleNames(tail_from, tail_target, parts) : parts.concat(repeat('..', from.length), target); 57 return head_from === head_target ? diffPursModuleNames(tail_from, tail_target, parts) : parts.concat(repeat('..', from.length), target);
56}; 58};
57exports.resolvePursModule = function (_ref) {
58 var baseModulePath = _ref.baseModulePath,
59 baseModuleName = _ref.baseModuleName,
60 targetModuleName = _ref.targetModuleName;
61 59
60var normalizeRewriteRuleDest = function normalizeRewriteRuleDest(_ref) {
61 var dest = _ref.dest,
62 moduleName = _ref.moduleName;
63 return typeof dest === 'function' ? dest(moduleName) : dest;
64};
65var rewrite = function rewrite(_ref2) {
66 var rules = _ref2.rules,
67 moduleName = _ref2.moduleName;
68
69 var moduleNameParts = moduleName.split('.');
70 var _iteratorNormalCompletion = true;
71 var _didIteratorError = false;
72 var _iteratorError = undefined;
73
74 try {
75 for (var _iterator = Object.entries(rules)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
76 var _step$value = _slicedToArray(_step.value, 2),
77 rule = _step$value[0],
78 dest = _step$value[1];
79
80 var ruleParts = rule.split('.');
81 var matched = ruleParts.every(function (part, i) {
82 return part === '*' || part === moduleNameParts[i];
83 });
84 if (!matched) continue;
85 var rest = moduleNameParts.slice(ruleParts.length);
86 var base = normalizeRewriteRuleDest({ dest: dest, moduleName: moduleName });
87 return path.join.apply(path, [base].concat(_toConsumableArray(rest))) + '.purs';
88 }
89 } catch (err) {
90 _didIteratorError = true;
91 _iteratorError = err;
92 } finally {
93 try {
94 if (!_iteratorNormalCompletion && _iterator.return) {
95 _iterator.return();
96 }
97 } finally {
98 if (_didIteratorError) {
99 throw _iteratorError;
100 }
101 }
102 }
103};
104
105exports.resolvePursModule = function (_ref3) {
106 var baseModulePath = _ref3.baseModulePath,
107 baseModuleName = _ref3.baseModuleName,
108 rewriteRules = _ref3.rewriteRules,
109 targetModuleName = _ref3.targetModuleName;
110
111 var rewrittenModulePath = rewrite({ rules: rewriteRules, moduleName: targetModuleName });
112 if (rewrittenModulePath) return rewrittenModulePath;
62 var parts = diffPursModuleNames(baseModuleName.split('.'), targetModuleName.split('.'), []); 113 var parts = diffPursModuleNames(baseModuleName.split('.'), targetModuleName.split('.'), []);
63 return parts.length ? path.resolve(baseModulePath, path.join.apply(path, _toConsumableArray(parts)) + '.purs') : baseModulePath; 114 return parts.length ? path.resolve(baseModulePath, path.join.apply(path, _toConsumableArray(parts)) + '.purs') : baseModulePath;
64}; 115};