@optique/inquirer 1.0.0-dev.560 → 1.0.0-dev.562

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -42,6 +42,9 @@ function getPromptFunctions() {
42
42
  const override = globalThis[promptFunctionsOverrideSymbol];
43
43
  return override ?? defaultPromptFunctions;
44
44
  }
45
+ function isExitPromptError(error) {
46
+ return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
47
+ }
45
48
  /**
46
49
  * Wraps a parser with an interactive Inquirer.js prompt fallback.
47
50
  *
@@ -83,97 +86,105 @@ function prompt(parser, config) {
83
86
  let promptCache = null;
84
87
  async function executePrompt() {
85
88
  const prompts = getPromptFunctions();
86
- if ("prompter" in cfg && cfg.prompter != null) {
87
- const value = await cfg.prompter();
88
- if (cfg.type === "number" && value === void 0) return {
89
- success: false,
90
- error: __optique_core_message.message`No number provided.`
91
- };
92
- return {
93
- success: true,
94
- value
95
- };
96
- }
97
- switch (cfg.type) {
98
- case "confirm": return {
99
- success: true,
100
- value: await prompts.confirm({
101
- message: cfg.message,
102
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
103
- })
104
- };
105
- case "number": {
106
- const numResult = await prompts.number({
107
- message: cfg.message,
108
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
109
- ...cfg.min !== void 0 ? { min: cfg.min } : {},
110
- ...cfg.max !== void 0 ? { max: cfg.max } : {},
111
- ...cfg.step !== void 0 ? { step: cfg.step } : {}
112
- });
113
- if (numResult === void 0) return {
89
+ try {
90
+ if ("prompter" in cfg && cfg.prompter != null) {
91
+ const value = await cfg.prompter();
92
+ if (cfg.type === "number" && value === void 0) return {
114
93
  success: false,
115
94
  error: __optique_core_message.message`No number provided.`
116
95
  };
117
96
  return {
118
97
  success: true,
119
- value: numResult
98
+ value
120
99
  };
121
100
  }
122
- case "input": return {
123
- success: true,
124
- value: await prompts.input({
125
- message: cfg.message,
126
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
127
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
128
- })
129
- };
130
- case "password": return {
131
- success: true,
132
- value: await prompts.password({
133
- message: cfg.message,
134
- ...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
135
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
136
- })
137
- };
138
- case "editor": return {
139
- success: true,
140
- value: await prompts.editor({
141
- message: cfg.message,
142
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
143
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
144
- })
145
- };
146
- case "select": return {
147
- success: true,
148
- value: await prompts.select({
149
- message: cfg.message,
150
- choices: normalizeChoices(cfg.choices),
151
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
152
- })
153
- };
154
- case "rawlist": return {
155
- success: true,
156
- value: await prompts.rawlist({
157
- message: cfg.message,
158
- choices: normalizeChoices(cfg.choices),
159
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
160
- })
161
- };
162
- case "expand": return {
163
- success: true,
164
- value: await prompts.expand({
165
- message: cfg.message,
166
- choices: cfg.choices,
167
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
168
- })
169
- };
170
- case "checkbox": return {
171
- success: true,
172
- value: await prompts.checkbox({
173
- message: cfg.message,
174
- choices: normalizeChoices(cfg.choices)
175
- })
101
+ switch (cfg.type) {
102
+ case "confirm": return {
103
+ success: true,
104
+ value: await prompts.confirm({
105
+ message: cfg.message,
106
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
107
+ })
108
+ };
109
+ case "number": {
110
+ const numResult = await prompts.number({
111
+ message: cfg.message,
112
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
113
+ ...cfg.min !== void 0 ? { min: cfg.min } : {},
114
+ ...cfg.max !== void 0 ? { max: cfg.max } : {},
115
+ ...cfg.step !== void 0 ? { step: cfg.step } : {}
116
+ });
117
+ if (numResult === void 0) return {
118
+ success: false,
119
+ error: __optique_core_message.message`No number provided.`
120
+ };
121
+ return {
122
+ success: true,
123
+ value: numResult
124
+ };
125
+ }
126
+ case "input": return {
127
+ success: true,
128
+ value: await prompts.input({
129
+ message: cfg.message,
130
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
131
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
132
+ })
133
+ };
134
+ case "password": return {
135
+ success: true,
136
+ value: await prompts.password({
137
+ message: cfg.message,
138
+ ...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
139
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
140
+ })
141
+ };
142
+ case "editor": return {
143
+ success: true,
144
+ value: await prompts.editor({
145
+ message: cfg.message,
146
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
147
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
148
+ })
149
+ };
150
+ case "select": return {
151
+ success: true,
152
+ value: await prompts.select({
153
+ message: cfg.message,
154
+ choices: normalizeChoices(cfg.choices),
155
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
156
+ })
157
+ };
158
+ case "rawlist": return {
159
+ success: true,
160
+ value: await prompts.rawlist({
161
+ message: cfg.message,
162
+ choices: normalizeChoices(cfg.choices),
163
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
164
+ })
165
+ };
166
+ case "expand": return {
167
+ success: true,
168
+ value: await prompts.expand({
169
+ message: cfg.message,
170
+ choices: cfg.choices,
171
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
172
+ })
173
+ };
174
+ case "checkbox": return {
175
+ success: true,
176
+ value: await prompts.checkbox({
177
+ message: cfg.message,
178
+ choices: normalizeChoices(cfg.choices)
179
+ })
180
+ };
181
+ }
182
+ } catch (error) {
183
+ if (isExitPromptError(error)) return {
184
+ success: false,
185
+ error: __optique_core_message.message`Prompt cancelled.`
176
186
  };
187
+ throw error;
177
188
  }
178
189
  }
179
190
  return {
package/dist/index.js CHANGED
@@ -19,6 +19,9 @@ function getPromptFunctions() {
19
19
  const override = globalThis[promptFunctionsOverrideSymbol];
20
20
  return override ?? defaultPromptFunctions;
21
21
  }
22
+ function isExitPromptError(error) {
23
+ return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
24
+ }
22
25
  /**
23
26
  * Wraps a parser with an interactive Inquirer.js prompt fallback.
24
27
  *
@@ -60,97 +63,105 @@ function prompt(parser, config) {
60
63
  let promptCache = null;
61
64
  async function executePrompt() {
62
65
  const prompts = getPromptFunctions();
63
- if ("prompter" in cfg && cfg.prompter != null) {
64
- const value = await cfg.prompter();
65
- if (cfg.type === "number" && value === void 0) return {
66
- success: false,
67
- error: message`No number provided.`
68
- };
69
- return {
70
- success: true,
71
- value
72
- };
73
- }
74
- switch (cfg.type) {
75
- case "confirm": return {
76
- success: true,
77
- value: await prompts.confirm({
78
- message: cfg.message,
79
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
80
- })
81
- };
82
- case "number": {
83
- const numResult = await prompts.number({
84
- message: cfg.message,
85
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
86
- ...cfg.min !== void 0 ? { min: cfg.min } : {},
87
- ...cfg.max !== void 0 ? { max: cfg.max } : {},
88
- ...cfg.step !== void 0 ? { step: cfg.step } : {}
89
- });
90
- if (numResult === void 0) return {
66
+ try {
67
+ if ("prompter" in cfg && cfg.prompter != null) {
68
+ const value = await cfg.prompter();
69
+ if (cfg.type === "number" && value === void 0) return {
91
70
  success: false,
92
71
  error: message`No number provided.`
93
72
  };
94
73
  return {
95
74
  success: true,
96
- value: numResult
75
+ value
97
76
  };
98
77
  }
99
- case "input": return {
100
- success: true,
101
- value: await prompts.input({
102
- message: cfg.message,
103
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
104
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
105
- })
106
- };
107
- case "password": return {
108
- success: true,
109
- value: await prompts.password({
110
- message: cfg.message,
111
- ...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
112
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
113
- })
114
- };
115
- case "editor": return {
116
- success: true,
117
- value: await prompts.editor({
118
- message: cfg.message,
119
- ...cfg.default !== void 0 ? { default: cfg.default } : {},
120
- ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
121
- })
122
- };
123
- case "select": return {
124
- success: true,
125
- value: await prompts.select({
126
- message: cfg.message,
127
- choices: normalizeChoices(cfg.choices),
128
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
129
- })
130
- };
131
- case "rawlist": return {
132
- success: true,
133
- value: await prompts.rawlist({
134
- message: cfg.message,
135
- choices: normalizeChoices(cfg.choices),
136
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
137
- })
138
- };
139
- case "expand": return {
140
- success: true,
141
- value: await prompts.expand({
142
- message: cfg.message,
143
- choices: cfg.choices,
144
- ...cfg.default !== void 0 ? { default: cfg.default } : {}
145
- })
146
- };
147
- case "checkbox": return {
148
- success: true,
149
- value: await prompts.checkbox({
150
- message: cfg.message,
151
- choices: normalizeChoices(cfg.choices)
152
- })
78
+ switch (cfg.type) {
79
+ case "confirm": return {
80
+ success: true,
81
+ value: await prompts.confirm({
82
+ message: cfg.message,
83
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
84
+ })
85
+ };
86
+ case "number": {
87
+ const numResult = await prompts.number({
88
+ message: cfg.message,
89
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
90
+ ...cfg.min !== void 0 ? { min: cfg.min } : {},
91
+ ...cfg.max !== void 0 ? { max: cfg.max } : {},
92
+ ...cfg.step !== void 0 ? { step: cfg.step } : {}
93
+ });
94
+ if (numResult === void 0) return {
95
+ success: false,
96
+ error: message`No number provided.`
97
+ };
98
+ return {
99
+ success: true,
100
+ value: numResult
101
+ };
102
+ }
103
+ case "input": return {
104
+ success: true,
105
+ value: await prompts.input({
106
+ message: cfg.message,
107
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
108
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
109
+ })
110
+ };
111
+ case "password": return {
112
+ success: true,
113
+ value: await prompts.password({
114
+ message: cfg.message,
115
+ ...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
116
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
117
+ })
118
+ };
119
+ case "editor": return {
120
+ success: true,
121
+ value: await prompts.editor({
122
+ message: cfg.message,
123
+ ...cfg.default !== void 0 ? { default: cfg.default } : {},
124
+ ...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
125
+ })
126
+ };
127
+ case "select": return {
128
+ success: true,
129
+ value: await prompts.select({
130
+ message: cfg.message,
131
+ choices: normalizeChoices(cfg.choices),
132
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
133
+ })
134
+ };
135
+ case "rawlist": return {
136
+ success: true,
137
+ value: await prompts.rawlist({
138
+ message: cfg.message,
139
+ choices: normalizeChoices(cfg.choices),
140
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
141
+ })
142
+ };
143
+ case "expand": return {
144
+ success: true,
145
+ value: await prompts.expand({
146
+ message: cfg.message,
147
+ choices: cfg.choices,
148
+ ...cfg.default !== void 0 ? { default: cfg.default } : {}
149
+ })
150
+ };
151
+ case "checkbox": return {
152
+ success: true,
153
+ value: await prompts.checkbox({
154
+ message: cfg.message,
155
+ choices: normalizeChoices(cfg.choices)
156
+ })
157
+ };
158
+ }
159
+ } catch (error) {
160
+ if (isExitPromptError(error)) return {
161
+ success: false,
162
+ error: message`Prompt cancelled.`
153
163
  };
164
+ throw error;
154
165
  }
155
166
  }
156
167
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/inquirer",
3
- "version": "1.0.0-dev.560+6a1e896e",
3
+ "version": "1.0.0-dev.562+295508a4",
4
4
  "description": "Interactive prompt support for Optique via Inquirer.js",
5
5
  "keywords": [
6
6
  "CLI",
@@ -56,13 +56,13 @@
56
56
  "sideEffects": false,
57
57
  "dependencies": {
58
58
  "@inquirer/prompts": "^8.3.0",
59
- "@optique/core": "1.0.0-dev.560+6a1e896e"
59
+ "@optique/core": "1.0.0-dev.562+295508a4"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^20.19.9",
63
63
  "tsdown": "^0.13.0",
64
64
  "typescript": "^5.8.3",
65
- "@optique/env": "1.0.0-dev.560+6a1e896e"
65
+ "@optique/env": "1.0.0-dev.562+295508a4"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsdown",