config-loader.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. function loadConfig(cwd) {
  7. if (cwd === void 0) { cwd = process.cwd(); }
  8. return configLoader({ cwd: cwd });
  9. }
  10. exports.loadConfig = loadConfig;
  11. function 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. }
  47. exports.configLoader = configLoader;
  48. //# sourceMappingURL=config-loader.js.map