@inquirer/core 9.0.7 → 9.0.8
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.
|
@@ -59,13 +59,16 @@ function createPrompt(view) {
|
|
|
59
59
|
onExit();
|
|
60
60
|
reject(new errors_mjs_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
61
61
|
});
|
|
62
|
-
const
|
|
62
|
+
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => {
|
|
63
63
|
try {
|
|
64
64
|
hook_engine_mjs_1.effectScheduler.clearAll();
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
67
|
reject(error);
|
|
68
68
|
}
|
|
69
|
+
});
|
|
70
|
+
function onExit() {
|
|
71
|
+
hooksCleanup();
|
|
69
72
|
if (context === null || context === void 0 ? void 0 : context.clearPromptOnDone) {
|
|
70
73
|
screen.clean();
|
|
71
74
|
}
|
|
@@ -75,7 +78,8 @@ function createPrompt(view) {
|
|
|
75
78
|
screen.done();
|
|
76
79
|
removeExitListener();
|
|
77
80
|
rl.input.removeListener('keypress', checkCursorPos);
|
|
78
|
-
|
|
81
|
+
rl.removeListener('close', hooksCleanup);
|
|
82
|
+
}
|
|
79
83
|
cancel = () => {
|
|
80
84
|
onExit();
|
|
81
85
|
reject(new errors_mjs_1.CancelPromptError());
|
|
@@ -105,6 +109,10 @@ function createPrompt(view) {
|
|
|
105
109
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
106
110
|
// by a state change sets the cursor to the right position.
|
|
107
111
|
rl.input.on('keypress', checkCursorPos);
|
|
112
|
+
// The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
|
|
113
|
+
// triggers after the process is done (which happens after timeouts are done triggering.)
|
|
114
|
+
// We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
|
|
115
|
+
rl.on('close', hooksCleanup);
|
|
108
116
|
});
|
|
109
117
|
});
|
|
110
118
|
answer.cancel = cancel;
|
|
@@ -8,11 +8,15 @@ function useKeypress(userHandler) {
|
|
|
8
8
|
const signal = (0, use_ref_mjs_1.useRef)(userHandler);
|
|
9
9
|
signal.current = userHandler;
|
|
10
10
|
(0, use_effect_mjs_1.useEffect)((rl) => {
|
|
11
|
+
let ignore = false;
|
|
11
12
|
const handler = (0, hook_engine_mjs_1.withUpdates)((_input, event) => {
|
|
13
|
+
if (ignore)
|
|
14
|
+
return;
|
|
12
15
|
signal.current(event, rl);
|
|
13
16
|
});
|
|
14
17
|
rl.input.on('keypress', handler);
|
|
15
18
|
return () => {
|
|
19
|
+
ignore = true;
|
|
16
20
|
rl.input.removeListener('keypress', handler);
|
|
17
21
|
};
|
|
18
22
|
}, []);
|
|
@@ -29,13 +29,16 @@ export function createPrompt(view) {
|
|
|
29
29
|
onExit();
|
|
30
30
|
reject(new ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
31
31
|
});
|
|
32
|
-
const
|
|
32
|
+
const hooksCleanup = AsyncResource.bind(() => {
|
|
33
33
|
try {
|
|
34
34
|
effectScheduler.clearAll();
|
|
35
35
|
}
|
|
36
36
|
catch (error) {
|
|
37
37
|
reject(error);
|
|
38
38
|
}
|
|
39
|
+
});
|
|
40
|
+
function onExit() {
|
|
41
|
+
hooksCleanup();
|
|
39
42
|
if (context?.clearPromptOnDone) {
|
|
40
43
|
screen.clean();
|
|
41
44
|
}
|
|
@@ -45,7 +48,8 @@ export function createPrompt(view) {
|
|
|
45
48
|
screen.done();
|
|
46
49
|
removeExitListener();
|
|
47
50
|
rl.input.removeListener('keypress', checkCursorPos);
|
|
48
|
-
|
|
51
|
+
rl.removeListener('close', hooksCleanup);
|
|
52
|
+
}
|
|
49
53
|
cancel = () => {
|
|
50
54
|
onExit();
|
|
51
55
|
reject(new CancelPromptError());
|
|
@@ -75,6 +79,10 @@ export function createPrompt(view) {
|
|
|
75
79
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
76
80
|
// by a state change sets the cursor to the right position.
|
|
77
81
|
rl.input.on('keypress', checkCursorPos);
|
|
82
|
+
// The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
|
|
83
|
+
// triggers after the process is done (which happens after timeouts are done triggering.)
|
|
84
|
+
// We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
|
|
85
|
+
rl.on('close', hooksCleanup);
|
|
78
86
|
});
|
|
79
87
|
});
|
|
80
88
|
answer.cancel = cancel;
|
|
@@ -5,11 +5,15 @@ export function useKeypress(userHandler) {
|
|
|
5
5
|
const signal = useRef(userHandler);
|
|
6
6
|
signal.current = userHandler;
|
|
7
7
|
useEffect((rl) => {
|
|
8
|
+
let ignore = false;
|
|
8
9
|
const handler = withUpdates((_input, event) => {
|
|
10
|
+
if (ignore)
|
|
11
|
+
return;
|
|
9
12
|
signal.current(event, rl);
|
|
10
13
|
});
|
|
11
14
|
rl.input.on('keypress', handler);
|
|
12
15
|
return () => {
|
|
16
|
+
ignore = true;
|
|
13
17
|
rl.input.removeListener('keypress', handler);
|
|
14
18
|
};
|
|
15
19
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.8",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"sideEffects": false,
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "8be69de6107bed7d85a7f2bfe99353d106d9c3bf"
|
|
100
100
|
}
|