config-loader.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.configLoader = exports.loadConfig = void 0;
  4. var TsConfigLoader2 = require("./tsconfig-loader");
  5. var path = require("path");
  6. var options_1 = require("./options");
  7. function loadConfig(cwd) {
  8. if (cwd === void 0) { cwd = options_1.options.cwd; }
  9. return configLoader({ cwd: cwd });
  10. }
  11. exports.loadConfig = loadConfig;
  12. function configLoader(_a) {
  13. var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader2.tsConfigLoader : _b;
  14. if (explicitParams) {
  15. // tslint:disable-next-line:no-shadowed-variable
  16. var absoluteBaseUrl_1 = path.isAbsolute(explicitParams.baseUrl)
  17. ? explicitParams.baseUrl
  18. : path.join(cwd, explicitParams.baseUrl);
  19. return {
  20. resultType: "success",
  21. configFileAbsolutePath: "",
  22. baseUrl: explicitParams.baseUrl,
  23. absoluteBaseUrl: absoluteBaseUrl_1,
  24. paths: explicitParams.paths,
  25. mainFields: explicitParams.mainFields,
  26. addMatchAll: explicitParams.addMatchAll,
  27. };
  28. }
  29. // Load tsconfig and create path matching function
  30. var loadResult = tsConfigLoader({
  31. cwd: cwd,
  32. getEnv: function (key) { return process.env[key]; },
  33. });
  34. if (!loadResult.tsConfigPath) {
  35. return {
  36. resultType: "failed",
  37. message: "Couldn't find tsconfig.json",
  38. };
  39. }
  40. if (!loadResult.baseUrl) {
  41. return {
  42. resultType: "failed",
  43. message: "Missing baseUrl in compilerOptions",
  44. };
  45. }
  46. var tsConfigDir = path.dirname(loadResult.tsConfigPath);
  47. var absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);
  48. return {
  49. resultType: "success",
  50. configFileAbsolutePath: loadResult.tsConfigPath,
  51. baseUrl: loadResult.baseUrl,
  52. absoluteBaseUrl: absoluteBaseUrl,
  53. paths: loadResult.paths || {},
  54. };
  55. }
  56. exports.configLoader = configLoader;
  57. //# sourceMappingURL=config-loader.js.map