@inquirer/core 11.1.7 → 11.1.9

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
- // eslint-disable-next-line @typescript-eslint/unbound-method
14
+ // oxlint-disable-next-line typescript/unbound-method
14
15
  const _prepareStackTrace = Error.prepareStackTrace;
15
16
  let result = [];
16
17
  try {
@@ -39,15 +40,17 @@ export function createPrompt(view) {
39
40
  // Add mute capabilities to the output
40
41
  const output = new MuteStream();
41
42
  output.pipe(context.output ?? process.stdout);
42
- // Pre-mute the output so that readline doesn't echo stale keystrokes
43
- // to the terminal before the first render. ScreenManager will unmute/mute
44
- // the output around each render call as needed.
45
- output.mute();
43
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
46
44
  const rl = readline.createInterface({
47
45
  terminal: true,
48
46
  input,
49
47
  output,
50
48
  });
49
+ // Mute the output after readline has initialized so readline can perform
50
+ // any terminal setup writes (e.g. Windows Console API initialization)
51
+ // before suppressing output. ScreenManager will unmute/mute around each
52
+ // render call as needed.
53
+ output.mute();
51
54
  const screen = new ScreenManager(rl);
52
55
  const { promise, resolve, reject } = PromisePolyfill.withResolver();
53
56
  const cancel = () => reject(new CancelPromptError());
@@ -85,15 +88,28 @@ export function createPrompt(view) {
85
88
  const checkCursorPos = () => screen.checkCursorPos();
86
89
  rl.input.on('keypress', checkCursorPos);
87
90
  cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
91
+ let pendingDone = null;
88
92
  cycle(() => {
93
+ let effectsSettled = false;
89
94
  try {
90
95
  const nextView = view(config, (value) => {
91
- setImmediate(() => resolve(value));
96
+ if (effectsSettled) {
97
+ // After the cycle completes (async validation path), the "done"
98
+ // render already flushed via setStatus → handleChange, so resolve
99
+ // immediately.
100
+ resolve(value);
101
+ }
102
+ else {
103
+ pendingDone = { value };
104
+ }
92
105
  });
93
106
  // Typescript won't allow this, but not all users rely on typescript.
94
107
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
95
108
  if (nextView === undefined) {
96
- const callerFilename = callSites[1]?.getFileName();
109
+ let callerFilename = callSites[1]?.getFileName();
110
+ if (callerFilename && !callerFilename.startsWith('file://')) {
111
+ callerFilename = path.resolve(callerFilename);
112
+ }
97
113
  throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
98
114
  }
99
115
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
@@ -103,6 +119,12 @@ export function createPrompt(view) {
103
119
  catch (error) {
104
120
  reject(error);
105
121
  }
122
+ effectsSettled = true;
123
+ if (pendingDone !== null) {
124
+ const { value } = pendingDone;
125
+ pendingDone = null;
126
+ resolve(value);
127
+ }
106
128
  });
107
129
  };
108
130
  // Proper Readable streams (like process.stdin) may have OS-level buffered
@@ -61,6 +61,7 @@ export function withPointer(cb) {
61
61
  const { index } = store;
62
62
  const pointer = {
63
63
  get() {
64
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
64
65
  return store.hooks[index];
65
66
  },
66
67
  set(value) {
@@ -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),
@@ -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 = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
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.7",
3
+ "version": "11.1.9",
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.4",
71
- "@inquirer/figures": "^2.0.4",
72
- "@inquirer/type": "^4.0.4",
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.0.2",
81
- "typescript": "^5.9.3"
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": "b218fcc4afe888a58957aa78c9a032f9bd2d60cb"
96
+ "gitHead": "35bda2afd31b4acca8f800259b9f7ca4e95a1d9d"
97
97
  }