source: frontend/node_modules/tsconfig-paths/lib/mapping-entry.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[9af201e]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getAbsoluteMappingEntries = void 0;
4var path = require("path");
5/**
6 * Converts an absolute baseUrl and paths to an array of absolute mapping entries.
7 * The array is sorted by longest prefix.
8 * Having an array with entries allows us to keep a sorting order rather than
9 * sort by keys each time we use the mappings.
10 * @param absoluteBaseUrl
11 * @param paths
12 * @param addMatchAll
13 */
14function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
15 // Resolve all paths to absolute form once here, and sort them by
16 // longest prefix once here, this saves time on each request later.
17 // We need to put them in an array to preserve the sorting order.
18 var sortedKeys = sortByLongestPrefix(Object.keys(paths));
19 var absolutePaths = [];
20 for (var _i = 0, sortedKeys_1 = sortedKeys; _i < sortedKeys_1.length; _i++) {
21 var key = sortedKeys_1[_i];
22 absolutePaths.push({
23 pattern: key,
24 paths: paths[key].map(function (pathToResolve) {
25 return path.join(absoluteBaseUrl, pathToResolve);
26 }),
27 });
28 }
29 // If there is no match-all path specified in the paths section of tsconfig, then try to match
30 // all paths relative to baseUrl, this is how typescript works.
31 if (!paths["*"] && addMatchAll) {
32 absolutePaths.push({
33 pattern: "*",
34 paths: ["".concat(absoluteBaseUrl.replace(/\/$/, ""), "/*")],
35 });
36 }
37 return absolutePaths;
38}
39exports.getAbsoluteMappingEntries = getAbsoluteMappingEntries;
40/**
41 * Sort path patterns.
42 * If a module name can be matched with multiple patterns then pattern with the longest prefix will be picked.
43 */
44function sortByLongestPrefix(arr) {
45 return arr
46 .concat()
47 .sort(function (a, b) { return getPrefixLength(b) - getPrefixLength(a); });
48}
49function getPrefixLength(pattern) {
50 var prefixLength = pattern.indexOf("*");
51 return pattern.substr(0, prefixLength).length;
52}
53//# sourceMappingURL=mapping-entry.js.map
Note: See TracBrowser for help on using the repository browser.