1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getAbsoluteMappingEntries = void 0;
|
4 | var path = require("path");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
|
16 |
|
17 |
|
18 |
|
19 | var sortedKeys = sortByLongestPrefix(Object.keys(paths));
|
20 | var absolutePaths = [];
|
21 | for (var _i = 0, sortedKeys_1 = sortedKeys; _i < sortedKeys_1.length; _i++) {
|
22 | var key = sortedKeys_1[_i];
|
23 | absolutePaths.push({
|
24 | pattern: key,
|
25 | paths: paths[key].map(function (pathToResolve) {
|
26 | return path.resolve(absoluteBaseUrl, pathToResolve);
|
27 | }),
|
28 | });
|
29 | }
|
30 |
|
31 |
|
32 | if (!paths["*"] && addMatchAll) {
|
33 | absolutePaths.push({
|
34 | pattern: "*",
|
35 | paths: ["".concat(absoluteBaseUrl.replace(/\/$/, ""), "/*")],
|
36 | });
|
37 | }
|
38 | return absolutePaths;
|
39 | }
|
40 | exports.getAbsoluteMappingEntries = getAbsoluteMappingEntries;
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | function sortByLongestPrefix(arr) {
|
46 | return arr
|
47 | .concat()
|
48 | .sort(function (a, b) { return getPrefixLength(b) - getPrefixLength(a); });
|
49 | }
|
50 | function getPrefixLength(pattern) {
|
51 | var prefixLength = pattern.indexOf("*");
|
52 | return pattern.substr(0, prefixLength).length;
|
53 | }
|
54 |
|
\ | No newline at end of file |