load-parser-opts.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.loadParserOpts = void 0;
  4. async function loadParserOpts(parserName, pendingParser) {
  5. // Await for the module, loaded with require
  6. const parser = await pendingParser;
  7. // Await parser opts if applicable
  8. if (typeof parser === 'object' &&
  9. typeof parser.parserOpts === 'object' &&
  10. typeof parser.parserOpts.then === 'function') {
  11. return (await parser.parserOpts).parserOpts;
  12. }
  13. // Create parser opts from factory
  14. if (typeof parser === 'object' &&
  15. typeof parser.parserOpts === 'function' &&
  16. parserName.startsWith('conventional-changelog-')) {
  17. return await new Promise((resolve) => {
  18. const result = parser.parserOpts((_, opts) => {
  19. resolve(opts.parserOpts);
  20. });
  21. // If result has data or a promise, the parser doesn't support factory-init
  22. // due to https://github.com/nodejs/promises-debugging/issues/16 it just quits, so let's use this fallback
  23. if (result) {
  24. Promise.resolve(result).then((opts) => {
  25. resolve(opts.parserOpts);
  26. });
  27. }
  28. });
  29. }
  30. // Pull nested paserOpts, might happen if overwritten with a module in main config
  31. if (typeof parser === 'object' &&
  32. typeof parser.parserOpts === 'object' &&
  33. typeof parser.parserOpts.parserOpts === 'object') {
  34. return parser.parserOpts.parserOpts;
  35. }
  36. return parser.parserOpts;
  37. }
  38. exports.loadParserOpts = loadParserOpts;
  39. //# sourceMappingURL=load-parser-opts.js.map