@inquirer/core 11.1.7 → 11.1.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.
|
@@ -6,11 +6,12 @@ import ScreenManager from "./screen-manager.js";
|
|
|
6
6
|
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
|
+
import path from 'node:path';
|
|
9
10
|
// Capture the real setImmediate at module load time so it works even when test
|
|
10
11
|
// frameworks mock timers with vi.useFakeTimers() or similar.
|
|
11
12
|
const nativeSetImmediate = globalThis.setImmediate;
|
|
12
13
|
function getCallSites() {
|
|
13
|
-
//
|
|
14
|
+
// oxlint-disable-next-line typescript/unbound-method
|
|
14
15
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
15
16
|
let result = [];
|
|
16
17
|
try {
|
|
@@ -43,6 +44,7 @@ export function createPrompt(view) {
|
|
|
43
44
|
// to the terminal before the first render. ScreenManager will unmute/mute
|
|
44
45
|
// the output around each render call as needed.
|
|
45
46
|
output.mute();
|
|
47
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
46
48
|
const rl = readline.createInterface({
|
|
47
49
|
terminal: true,
|
|
48
50
|
input,
|
|
@@ -85,15 +87,28 @@ export function createPrompt(view) {
|
|
|
85
87
|
const checkCursorPos = () => screen.checkCursorPos();
|
|
86
88
|
rl.input.on('keypress', checkCursorPos);
|
|
87
89
|
cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
|
|
90
|
+
let pendingDone = null;
|
|
88
91
|
cycle(() => {
|
|
92
|
+
let effectsSettled = false;
|
|
89
93
|
try {
|
|
90
94
|
const nextView = view(config, (value) => {
|
|
91
|
-
|
|
95
|
+
if (effectsSettled) {
|
|
96
|
+
// After the cycle completes (async validation path), the "done"
|
|
97
|
+
// render already flushed via setStatus → handleChange, so resolve
|
|
98
|
+
// immediately.
|
|
99
|
+
resolve(value);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
pendingDone = { value };
|
|
103
|
+
}
|
|
92
104
|
});
|
|
93
105
|
// Typescript won't allow this, but not all users rely on typescript.
|
|
94
106
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
95
107
|
if (nextView === undefined) {
|
|
96
|
-
|
|
108
|
+
let callerFilename = callSites[1]?.getFileName();
|
|
109
|
+
if (callerFilename && !callerFilename.startsWith('file://')) {
|
|
110
|
+
callerFilename = path.resolve(callerFilename);
|
|
111
|
+
}
|
|
97
112
|
throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
|
|
98
113
|
}
|
|
99
114
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -103,6 +118,12 @@ export function createPrompt(view) {
|
|
|
103
118
|
catch (error) {
|
|
104
119
|
reject(error);
|
|
105
120
|
}
|
|
121
|
+
effectsSettled = true;
|
|
122
|
+
if (pendingDone !== null) {
|
|
123
|
+
const { value } = pendingDone;
|
|
124
|
+
pendingDone = null;
|
|
125
|
+
resolve(value);
|
|
126
|
+
}
|
|
106
127
|
});
|
|
107
128
|
};
|
|
108
129
|
// Proper Readable streams (like process.stdin) may have OS-level buffered
|
package/dist/lib/hook-engine.js
CHANGED
package/dist/lib/make-theme.js
CHANGED
|
@@ -19,9 +19,11 @@ function deepMerge(...objects) {
|
|
|
19
19
|
: value;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
22
23
|
return output;
|
|
23
24
|
}
|
|
24
25
|
export function makeTheme(...themes) {
|
|
26
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
25
27
|
const themesToMerge = [
|
|
26
28
|
defaultTheme,
|
|
27
29
|
...themes.filter((theme) => theme != null),
|
package/dist/lib/use-state.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { AsyncResource } from 'node:async_hooks';
|
|
2
2
|
import { withPointer, handleChange } from "./hook-engine.js";
|
|
3
|
+
function isFactory(value) {
|
|
4
|
+
return typeof value === 'function';
|
|
5
|
+
}
|
|
3
6
|
export function useState(defaultValue) {
|
|
4
7
|
return withPointer((pointer) => {
|
|
5
8
|
const setState = AsyncResource.bind(function setState(newValue) {
|
|
@@ -13,7 +16,7 @@ export function useState(defaultValue) {
|
|
|
13
16
|
if (pointer.initialized) {
|
|
14
17
|
return [pointer.get(), setState];
|
|
15
18
|
}
|
|
16
|
-
const value =
|
|
19
|
+
const value = isFactory(defaultValue) ? defaultValue() : defaultValue;
|
|
17
20
|
pointer.set(value);
|
|
18
21
|
return [value, setState];
|
|
19
22
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.8",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"tsc": "tsc"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@inquirer/ansi": "^2.0.
|
|
71
|
-
"@inquirer/figures": "^2.0.
|
|
72
|
-
"@inquirer/type": "^4.0.
|
|
70
|
+
"@inquirer/ansi": "^2.0.5",
|
|
71
|
+
"@inquirer/figures": "^2.0.5",
|
|
72
|
+
"@inquirer/type": "^4.0.5",
|
|
73
73
|
"cli-width": "^4.1.0",
|
|
74
74
|
"fast-wrap-ansi": "^0.2.0",
|
|
75
75
|
"mute-stream": "^3.0.0",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@types/mute-stream": "^0.0.4",
|
|
80
|
-
"@types/node": "^25.
|
|
81
|
-
"typescript": "^
|
|
80
|
+
"@types/node": "^25.5.2",
|
|
81
|
+
"typescript": "^6.0.2"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@types/node": ">=18"
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
},
|
|
94
94
|
"main": "./dist/index.js",
|
|
95
95
|
"types": "./dist/index.d.ts",
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "e68fe01d65359e083581c48c4a18cd8f97d88842"
|
|
97
97
|
}
|