UNPKG

1.83 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.configLoader = exports.loadConfig = void 0;
4var TsConfigLoader2 = require("./tsconfig-loader");
5var path = require("path");
6function loadConfig(cwd) {
7 if (cwd === void 0) { cwd = process.cwd(); }
8 return configLoader({ cwd: cwd });
9}
10exports.loadConfig = loadConfig;
11function configLoader(_a) {
12 var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader2.tsConfigLoader : _b;
13 if (explicitParams) {
14 var absoluteBaseUrl = path.isAbsolute(explicitParams.baseUrl)
15 ? explicitParams.baseUrl
16 : path.join(cwd, explicitParams.baseUrl);
17 return {
18 resultType: "success",
19 configFileAbsolutePath: "",
20 baseUrl: explicitParams.baseUrl,
21 absoluteBaseUrl: absoluteBaseUrl,
22 paths: explicitParams.paths,
23 mainFields: explicitParams.mainFields,
24 addMatchAll: explicitParams.addMatchAll,
25 };
26 }
27 // Load tsconfig and create path matching function
28 var loadResult = tsConfigLoader({
29 cwd: cwd,
30 getEnv: function (key) { return process.env[key]; },
31 });
32 if (!loadResult.tsConfigPath) {
33 return {
34 resultType: "failed",
35 message: "Couldn't find tsconfig.json",
36 };
37 }
38 return {
39 resultType: "success",
40 configFileAbsolutePath: loadResult.tsConfigPath,
41 baseUrl: loadResult.baseUrl,
42 absoluteBaseUrl: path.resolve(path.dirname(loadResult.tsConfigPath), loadResult.baseUrl || ""),
43 paths: loadResult.paths || {},
44 addMatchAll: loadResult.baseUrl !== undefined,
45 };
46}
47exports.configLoader = configLoader;
48//# sourceMappingURL=config-loader.js.map
\No newline at end of file