@inquirer/core 10.1.10 → 10.1.12
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.
|
@@ -46,6 +46,7 @@ const promise_polyfill_ts_1 = require("./promise-polyfill.js");
|
|
|
46
46
|
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
47
47
|
const errors_ts_1 = require("./errors.js");
|
|
48
48
|
function getCallSites() {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
49
50
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
50
51
|
let result = [];
|
|
51
52
|
try {
|
|
@@ -94,6 +95,12 @@ function createPrompt(view) {
|
|
|
94
95
|
cleanups.add((0, signal_exit_1.onExit)((code, signal) => {
|
|
95
96
|
reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
96
97
|
}));
|
|
98
|
+
// SIGINT must be explicitly handled by the prompt so the ExitPromptError can be handled.
|
|
99
|
+
// Otherwise, the prompt will stop and in some scenarios never resolve.
|
|
100
|
+
// Ref issue #1741
|
|
101
|
+
const sigint = () => reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
102
|
+
rl.on('SIGINT', sigint);
|
|
103
|
+
cleanups.add(() => rl.removeListener('SIGINT', sigint));
|
|
97
104
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
98
105
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
99
106
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useState = useState;
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
4
5
|
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
5
6
|
function useState(defaultValue) {
|
|
6
7
|
return (0, hook_engine_ts_1.withPointer)((pointer) => {
|
|
7
|
-
const
|
|
8
|
+
const setState = node_async_hooks_1.AsyncResource.bind(function setState(newValue) {
|
|
8
9
|
// Noop if the value is still the same.
|
|
9
10
|
if (pointer.get() !== newValue) {
|
|
10
11
|
pointer.set(newValue);
|
|
11
12
|
// Trigger re-render
|
|
12
13
|
(0, hook_engine_ts_1.handleChange)();
|
|
13
14
|
}
|
|
14
|
-
};
|
|
15
|
+
});
|
|
15
16
|
if (pointer.initialized) {
|
|
16
|
-
return [pointer.get(),
|
|
17
|
+
return [pointer.get(), setState];
|
|
17
18
|
}
|
|
18
19
|
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
19
20
|
pointer.set(value);
|
|
20
|
-
return [value,
|
|
21
|
+
return [value, setState];
|
|
21
22
|
});
|
|
22
23
|
}
|
|
@@ -7,6 +7,7 @@ import { PromisePolyfill } from "./promise-polyfill.js";
|
|
|
7
7
|
import { withHooks, effectScheduler } from "./hook-engine.js";
|
|
8
8
|
import { AbortPromptError, CancelPromptError, ExitPromptError } from "./errors.js";
|
|
9
9
|
function getCallSites() {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
10
11
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
11
12
|
let result = [];
|
|
12
13
|
try {
|
|
@@ -55,6 +56,12 @@ export function createPrompt(view) {
|
|
|
55
56
|
cleanups.add(onSignalExit((code, signal) => {
|
|
56
57
|
reject(new ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
57
58
|
}));
|
|
59
|
+
// SIGINT must be explicitly handled by the prompt so the ExitPromptError can be handled.
|
|
60
|
+
// Otherwise, the prompt will stop and in some scenarios never resolve.
|
|
61
|
+
// Ref issue #1741
|
|
62
|
+
const sigint = () => reject(new ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
63
|
+
rl.on('SIGINT', sigint);
|
|
64
|
+
cleanups.add(() => rl.removeListener('SIGINT', sigint));
|
|
58
65
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
59
66
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
60
67
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { AsyncResource } from 'node:async_hooks';
|
|
1
2
|
import { withPointer, handleChange } from "./hook-engine.js";
|
|
2
3
|
export function useState(defaultValue) {
|
|
3
4
|
return withPointer((pointer) => {
|
|
4
|
-
const
|
|
5
|
+
const setState = AsyncResource.bind(function setState(newValue) {
|
|
5
6
|
// Noop if the value is still the same.
|
|
6
7
|
if (pointer.get() !== newValue) {
|
|
7
8
|
pointer.set(newValue);
|
|
8
9
|
// Trigger re-render
|
|
9
10
|
handleChange();
|
|
10
11
|
}
|
|
11
|
-
};
|
|
12
|
+
});
|
|
12
13
|
if (pointer.initialized) {
|
|
13
|
-
return [pointer.get(),
|
|
14
|
+
return [pointer.get(), setState];
|
|
14
15
|
}
|
|
15
16
|
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
16
17
|
pointer.set(value);
|
|
17
|
-
return [value,
|
|
18
|
+
return [value, setState];
|
|
18
19
|
});
|
|
19
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.12",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"tsc": "tshy"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@inquirer/figures": "^1.0.
|
|
78
|
-
"@inquirer/type": "^3.0.
|
|
77
|
+
"@inquirer/figures": "^1.0.12",
|
|
78
|
+
"@inquirer/type": "^3.0.7",
|
|
79
79
|
"ansi-escapes": "^4.3.2",
|
|
80
80
|
"cli-width": "^4.1.0",
|
|
81
81
|
"mute-stream": "^2.0.0",
|
|
@@ -84,9 +84,8 @@
|
|
|
84
84
|
"yoctocolors-cjs": "^2.1.2"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@arethetypeswrong/cli": "^0.
|
|
88
|
-
"@inquirer/testing": "^2.1.
|
|
89
|
-
"@repo/tsconfig": "workspace:*",
|
|
87
|
+
"@arethetypeswrong/cli": "^0.18.1",
|
|
88
|
+
"@inquirer/testing": "^2.1.47",
|
|
90
89
|
"@types/mute-stream": "^0.0.4",
|
|
91
90
|
"@types/node": "^22.14.0",
|
|
92
91
|
"@types/wrap-ansi": "^3.0.0",
|
|
@@ -115,5 +114,5 @@
|
|
|
115
114
|
".": "./src/index.ts"
|
|
116
115
|
}
|
|
117
116
|
},
|
|
118
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "85d4642b4a7a2229ea60167fc7cc25fe6fea2f18"
|
|
119
118
|
}
|