config-loader.js 2.0 KB

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