@inquirer/prompts 7.0.1 → 7.2.0

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.
Files changed (2) hide show
  1. package/README.md +30 -0
  2. package/package.json +14 -14
package/README.md CHANGED
@@ -227,6 +227,36 @@ promise.cancel();
227
227
 
228
228
  # Recipes
229
229
 
230
+ ## Handling `ctrl+c` gracefully
231
+
232
+ When a user press `ctrl+c` to exit a prompt, Inquirer rejects the prompt promise. This is the expected behavior in order to allow your program to teardown/cleanup its environment. When using `async/await`, rejected promises throw their error. When unhandled, those errors print their stack trace in your user's terminal.
233
+
234
+ ```
235
+ ExitPromptError: User force closed the prompt with 0 null
236
+ at file://example/packages/core/dist/esm/lib/create-prompt.js:55:20
237
+ at Emitter.emit (file://example/node_modules/signal-exit/dist/mjs/index.js:67:19)
238
+ at #processEmit (file://example/node_modules/signal-exit/dist/mjs/index.js:236:27)
239
+ at #process.emit (file://example/node_modules/signal-exit/dist/mjs/index.js:187:37)
240
+ at process.callbackTrampoline (node:internal/async_hooks:130:17)
241
+ ```
242
+
243
+ This isn't a great UX, which is why we highly recommend you to handle those errors gracefully.
244
+
245
+ First option is to wrap your scripts in `try/catch`; like [we do in our demo program](https://github.com/SBoudrias/Inquirer.js/blob/649e78147cbb6390a162ff842d4b21d53a233472/packages/demo/src/index.ts#L89-L95). Or handle the error in your CLI framework mechanism; for example [`Clipanion catch` method](https://mael.dev/clipanion/docs/errors#custom-error-handling).
246
+
247
+ Lastly, you could handle the error globally with an event listener and silence it.
248
+
249
+ ```ts
250
+ process.on('uncaughtException', (error) => {
251
+ if (error instanceof Error && error.name === 'ExitPromptError') {
252
+ console.log('👋 until next time!');
253
+ } else {
254
+ // Rethrow unknown errors
255
+ throw error;
256
+ }
257
+ });
258
+ ```
259
+
230
260
  ## Get answers in an object
231
261
 
232
262
  When asking many questions, you might not want to keep one variable per answer everywhere. In which case, you can put the answer inside an object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/prompts",
3
- "version": "7.0.1",
3
+ "version": "7.2.0",
4
4
  "description": "Inquirer prompts, combined in a single package",
5
5
  "keywords": [
6
6
  "answer",
@@ -76,20 +76,20 @@
76
76
  "tsc": "tshy"
77
77
  },
78
78
  "dependencies": {
79
- "@inquirer/checkbox": "^4.0.1",
80
- "@inquirer/confirm": "^5.0.1",
81
- "@inquirer/editor": "^4.0.1",
82
- "@inquirer/expand": "^4.0.1",
83
- "@inquirer/input": "^4.0.1",
84
- "@inquirer/number": "^3.0.1",
85
- "@inquirer/password": "^4.0.1",
86
- "@inquirer/rawlist": "^4.0.1",
87
- "@inquirer/search": "^3.0.1",
88
- "@inquirer/select": "^4.0.1"
79
+ "@inquirer/checkbox": "^4.0.3",
80
+ "@inquirer/confirm": "^5.1.0",
81
+ "@inquirer/editor": "^4.2.0",
82
+ "@inquirer/expand": "^4.0.3",
83
+ "@inquirer/input": "^4.1.0",
84
+ "@inquirer/number": "^3.0.3",
85
+ "@inquirer/password": "^4.0.3",
86
+ "@inquirer/rawlist": "^4.0.3",
87
+ "@inquirer/search": "^3.0.3",
88
+ "@inquirer/select": "^4.0.3"
89
89
  },
90
90
  "devDependencies": {
91
- "@arethetypeswrong/cli": "^0.16.4",
92
- "@inquirer/type": "^3.0.0",
91
+ "@arethetypeswrong/cli": "^0.17.0",
92
+ "@inquirer/type": "^3.0.1",
93
93
  "@repo/tsconfig": "workspace:*",
94
94
  "tshy": "^3.0.2"
95
95
  },
@@ -108,5 +108,5 @@
108
108
  "peerDependencies": {
109
109
  "@types/node": ">=18"
110
110
  },
111
- "gitHead": "da3dd749325495266025f2dbdb339a812da468f8"
111
+ "gitHead": "5713287885155c0081fca4190c17c18c598d9602"
112
112
  }