source: frontend/node_modules/tsconfig-paths/lib/register.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: 3.3 KB
Line 
1"use strict";
2var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4 if (ar || !(i in from)) {
5 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6 ar[i] = from[i];
7 }
8 }
9 return to.concat(ar || Array.prototype.slice.call(from));
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12exports.register = void 0;
13var match_path_sync_1 = require("./match-path-sync");
14var config_loader_1 = require("./config-loader");
15var options_1 = require("./options");
16var noOp = function () { return void 0; };
17function getCoreModules(builtinModules) {
18 builtinModules = builtinModules || [
19 "assert",
20 "buffer",
21 "child_process",
22 "cluster",
23 "crypto",
24 "dgram",
25 "dns",
26 "domain",
27 "events",
28 "fs",
29 "http",
30 "https",
31 "net",
32 "os",
33 "path",
34 "punycode",
35 "querystring",
36 "readline",
37 "stream",
38 "string_decoder",
39 "tls",
40 "tty",
41 "url",
42 "util",
43 "v8",
44 "vm",
45 "zlib",
46 ];
47 var coreModules = {};
48 for (var _i = 0, builtinModules_1 = builtinModules; _i < builtinModules_1.length; _i++) {
49 var module_1 = builtinModules_1[_i];
50 coreModules[module_1] = true;
51 }
52 return coreModules;
53}
54/**
55 * Installs a custom module load function that can adhere to paths in tsconfig.
56 * Returns a function to undo paths registration.
57 */
58function register(explicitParams) {
59 var configLoaderResult = (0, config_loader_1.configLoader)({
60 cwd: options_1.options.cwd,
61 explicitParams: explicitParams,
62 });
63 if (configLoaderResult.resultType === "failed") {
64 console.warn("".concat(configLoaderResult.message, ". tsconfig-paths will be skipped"));
65 return noOp;
66 }
67 var matchPath = (0, match_path_sync_1.createMatchPath)(configLoaderResult.absoluteBaseUrl, configLoaderResult.paths, configLoaderResult.mainFields, configLoaderResult.addMatchAll);
68 // Patch node's module loading
69 // tslint:disable-next-line:no-require-imports variable-name
70 var Module = require("module");
71 var originalResolveFilename = Module._resolveFilename;
72 var coreModules = getCoreModules(Module.builtinModules);
73 // tslint:disable-next-line:no-any
74 Module._resolveFilename = function (request, _parent) {
75 var isCoreModule = coreModules.hasOwnProperty(request);
76 if (!isCoreModule) {
77 var found = matchPath(request);
78 if (found) {
79 var modifiedArguments = __spreadArray([found], [].slice.call(arguments, 1), true); // Passes all arguments. Even those that is not specified above.
80 // tslint:disable-next-line:no-invalid-this
81 return originalResolveFilename.apply(this, modifiedArguments);
82 }
83 }
84 // tslint:disable-next-line:no-invalid-this
85 return originalResolveFilename.apply(this, arguments);
86 };
87 return function () {
88 // Return node's module loading to original state.
89 Module._resolveFilename = originalResolveFilename;
90 };
91}
92exports.register = register;
93//# sourceMappingURL=register.js.map
Note: See TracBrowser for help on using the repository browser.