load-config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.loadConfig = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const cosmiconfig_1 = require("cosmiconfig");
  9. const cosmiconfig_typescript_loader_1 = __importDefault(require("@endemolshinegroup/cosmiconfig-typescript-loader"));
  10. async function loadConfig(cwd, configPath) {
  11. const moduleName = 'commitlint';
  12. const explorer = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
  13. searchPlaces: [
  14. // cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),
  15. // we need to manually merge default searchPlaces from https://github.com/davidtheclark/cosmiconfig#searchplaces
  16. 'package.json',
  17. `.${moduleName}rc`,
  18. `.${moduleName}rc.json`,
  19. `.${moduleName}rc.yaml`,
  20. `.${moduleName}rc.yml`,
  21. `.${moduleName}rc.js`,
  22. `.${moduleName}rc.cjs`,
  23. `${moduleName}.config.js`,
  24. `${moduleName}.config.cjs`,
  25. // files supported by TypescriptLoader
  26. `.${moduleName}rc.ts`,
  27. `${moduleName}.config.ts`,
  28. ],
  29. loaders: {
  30. '.ts': cosmiconfig_typescript_loader_1.default,
  31. },
  32. });
  33. const explicitPath = configPath ? path_1.default.resolve(cwd, configPath) : undefined;
  34. const explore = explicitPath ? explorer.load : explorer.search;
  35. const searchPath = explicitPath ? explicitPath : cwd;
  36. const local = await explore(searchPath);
  37. if (local) {
  38. return local;
  39. }
  40. return null;
  41. }
  42. exports.loadConfig = loadConfig;
  43. //# sourceMappingURL=load-config.js.map