index.cjs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  7. var __export = (target, all) => {
  8. for (var name in all)
  9. __defProp(target, name, { get: all[name], enumerable: true });
  10. };
  11. var __copyProps = (to, from, except, desc) => {
  12. if (from && typeof from === "object" || typeof from === "function") {
  13. for (let key of __getOwnPropNames(from))
  14. if (!__hasOwnProp.call(to, key) && key !== except)
  15. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  16. }
  17. return to;
  18. };
  19. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  20. // src/index.ts
  21. var src_exports = {};
  22. __export(src_exports, {
  23. ListrInquirerPromptAdapter: () => ListrInquirerPromptAdapter
  24. });
  25. module.exports = __toCommonJS(src_exports);
  26. // src/prompt.ts
  27. var import_listr2 = require("listr2");
  28. var ListrInquirerPromptAdapter = class extends import_listr2.ListrPromptAdapter {
  29. static {
  30. __name(this, "ListrInquirerPromptAdapter");
  31. }
  32. prompt;
  33. /**
  34. * Get the current running instance of `inquirer`.
  35. */
  36. get instance() {
  37. return this.prompt;
  38. }
  39. /**
  40. * Create a new prompt with `inquirer`.
  41. */
  42. async run(prompt, ...[config, context]) {
  43. context ??= {};
  44. context.output ??= this.wrapper.stdout(import_listr2.ListrTaskEventType.PROMPT);
  45. this.reportStarted();
  46. this.task.on(import_listr2.ListrTaskEventType.STATE, (event) => {
  47. if (event === import_listr2.ListrTaskState.SKIPPED && this.prompt) {
  48. this.cancel();
  49. }
  50. });
  51. this.prompt = prompt(config, context);
  52. let result;
  53. try {
  54. result = await this.prompt;
  55. this.reportCompleted();
  56. } catch (e) {
  57. this.reportFailed();
  58. throw e;
  59. }
  60. return result;
  61. }
  62. /**
  63. * Cancel the ongoing prompt.
  64. */
  65. cancel() {
  66. if (!this.prompt) {
  67. return;
  68. }
  69. this.reportFailed();
  70. this.prompt.cancel();
  71. }
  72. };
  73. // Annotate the CommonJS export names for ESM import in node:
  74. 0 && (module.exports = {
  75. ListrInquirerPromptAdapter
  76. });