@inquirer/core 10.1.9 → 10.1.10

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 (42) hide show
  1. package/README.md +10 -0
  2. package/dist/commonjs/index.d.ts +13 -13
  3. package/dist/commonjs/index.js +20 -20
  4. package/dist/commonjs/lib/Separator.d.ts +1 -1
  5. package/dist/commonjs/lib/create-prompt.js +15 -15
  6. package/dist/commonjs/lib/hook-engine.js +3 -3
  7. package/dist/commonjs/lib/make-theme.d.ts +1 -1
  8. package/dist/commonjs/lib/make-theme.js +2 -2
  9. package/dist/commonjs/lib/pagination/lines.js +2 -2
  10. package/dist/commonjs/lib/pagination/use-pagination.d.ts +2 -2
  11. package/dist/commonjs/lib/pagination/use-pagination.js +9 -9
  12. package/dist/commonjs/lib/screen-manager.js +4 -4
  13. package/dist/commonjs/lib/use-effect.js +3 -3
  14. package/dist/commonjs/lib/use-keypress.d.ts +1 -1
  15. package/dist/commonjs/lib/use-keypress.js +6 -6
  16. package/dist/commonjs/lib/use-memo.js +2 -2
  17. package/dist/commonjs/lib/use-prefix.d.ts +1 -1
  18. package/dist/commonjs/lib/use-prefix.js +7 -7
  19. package/dist/commonjs/lib/use-ref.js +2 -2
  20. package/dist/commonjs/lib/use-state.js +3 -3
  21. package/dist/commonjs/lib/utils.js +2 -2
  22. package/dist/esm/index.d.ts +13 -13
  23. package/dist/esm/index.js +12 -12
  24. package/dist/esm/lib/Separator.d.ts +1 -1
  25. package/dist/esm/lib/create-prompt.js +5 -5
  26. package/dist/esm/lib/hook-engine.js +1 -1
  27. package/dist/esm/lib/make-theme.d.ts +1 -1
  28. package/dist/esm/lib/make-theme.js +1 -1
  29. package/dist/esm/lib/pagination/lines.js +1 -1
  30. package/dist/esm/lib/pagination/use-pagination.d.ts +2 -2
  31. package/dist/esm/lib/pagination/use-pagination.js +4 -4
  32. package/dist/esm/lib/screen-manager.js +1 -1
  33. package/dist/esm/lib/use-effect.js +1 -1
  34. package/dist/esm/lib/use-keypress.d.ts +1 -1
  35. package/dist/esm/lib/use-keypress.js +3 -3
  36. package/dist/esm/lib/use-memo.js +1 -1
  37. package/dist/esm/lib/use-prefix.d.ts +1 -1
  38. package/dist/esm/lib/use-prefix.js +3 -3
  39. package/dist/esm/lib/use-ref.js +1 -1
  40. package/dist/esm/lib/use-state.js +1 -1
  41. package/dist/esm/lib/utils.js +1 -1
  42. package/package.json +5 -5
package/README.md CHANGED
@@ -4,6 +4,16 @@ The `@inquirer/core` package is the library enabling the creation of Inquirer pr
4
4
 
5
5
  It aims to implements a lightweight API similar to React hooks - but without JSX.
6
6
 
7
+ # Special Thanks
8
+
9
+ <div align="center" markdown="1">
10
+
11
+ [![Graphite](https://github.com/user-attachments/assets/53db40ca-2254-481a-a094-6597f8716e29)](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)<br>
12
+
13
+ ### [Graphite is the AI developer productivity platform helping teams on GitHub ship higher quality software, faster](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)
14
+
15
+ </div>
16
+
7
17
  # Installation
8
18
 
9
19
  <table>
@@ -1,13 +1,13 @@
1
- export * from './lib/key.js';
2
- export * from './lib/errors.js';
3
- export { usePrefix } from './lib/use-prefix.js';
4
- export { useState } from './lib/use-state.js';
5
- export { useEffect } from './lib/use-effect.js';
6
- export { useMemo } from './lib/use-memo.js';
7
- export { useRef } from './lib/use-ref.js';
8
- export { useKeypress } from './lib/use-keypress.js';
9
- export { makeTheme } from './lib/make-theme.js';
10
- export type { Theme, Status } from './lib/theme.js';
11
- export { usePagination } from './lib/pagination/use-pagination.js';
12
- export { createPrompt } from './lib/create-prompt.js';
13
- export { Separator } from './lib/Separator.js';
1
+ export * from './lib/key.ts';
2
+ export * from './lib/errors.ts';
3
+ export { usePrefix } from './lib/use-prefix.ts';
4
+ export { useState } from './lib/use-state.ts';
5
+ export { useEffect } from './lib/use-effect.ts';
6
+ export { useMemo } from './lib/use-memo.ts';
7
+ export { useRef } from './lib/use-ref.ts';
8
+ export { useKeypress } from './lib/use-keypress.ts';
9
+ export { makeTheme } from './lib/make-theme.ts';
10
+ export type { Theme, Status } from './lib/theme.ts';
11
+ export { usePagination } from './lib/pagination/use-pagination.ts';
12
+ export { createPrompt } from './lib/create-prompt.ts';
13
+ export { Separator } from './lib/Separator.ts';
@@ -17,23 +17,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
18
18
  __exportStar(require("./lib/key.js"), exports);
19
19
  __exportStar(require("./lib/errors.js"), exports);
20
- var use_prefix_js_1 = require("./lib/use-prefix.js");
21
- Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_js_1.usePrefix; } });
22
- var use_state_js_1 = require("./lib/use-state.js");
23
- Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return use_state_js_1.useState; } });
24
- var use_effect_js_1 = require("./lib/use-effect.js");
25
- Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_js_1.useEffect; } });
26
- var use_memo_js_1 = require("./lib/use-memo.js");
27
- Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_js_1.useMemo; } });
28
- var use_ref_js_1 = require("./lib/use-ref.js");
29
- Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_js_1.useRef; } });
30
- var use_keypress_js_1 = require("./lib/use-keypress.js");
31
- Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_js_1.useKeypress; } });
32
- var make_theme_js_1 = require("./lib/make-theme.js");
33
- Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_js_1.makeTheme; } });
34
- var use_pagination_js_1 = require("./lib/pagination/use-pagination.js");
35
- Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_js_1.usePagination; } });
36
- var create_prompt_js_1 = require("./lib/create-prompt.js");
37
- Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return create_prompt_js_1.createPrompt; } });
38
- var Separator_js_1 = require("./lib/Separator.js");
39
- Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return Separator_js_1.Separator; } });
20
+ var use_prefix_ts_1 = require("./lib/use-prefix.js");
21
+ Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_ts_1.usePrefix; } });
22
+ var use_state_ts_1 = require("./lib/use-state.js");
23
+ Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return use_state_ts_1.useState; } });
24
+ var use_effect_ts_1 = require("./lib/use-effect.js");
25
+ Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_ts_1.useEffect; } });
26
+ var use_memo_ts_1 = require("./lib/use-memo.js");
27
+ Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_ts_1.useMemo; } });
28
+ var use_ref_ts_1 = require("./lib/use-ref.js");
29
+ Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_ts_1.useRef; } });
30
+ var use_keypress_ts_1 = require("./lib/use-keypress.js");
31
+ Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_ts_1.useKeypress; } });
32
+ var make_theme_ts_1 = require("./lib/make-theme.js");
33
+ Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_ts_1.makeTheme; } });
34
+ var use_pagination_ts_1 = require("./lib/pagination/use-pagination.js");
35
+ Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_ts_1.usePagination; } });
36
+ var create_prompt_ts_1 = require("./lib/create-prompt.js");
37
+ Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return create_prompt_ts_1.createPrompt; } });
38
+ var Separator_ts_1 = require("./lib/Separator.js");
39
+ Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return Separator_ts_1.Separator; } });
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export declare class Separator {
6
6
  readonly separator: string;
7
- readonly type = "separator";
7
+ readonly type: string;
8
8
  constructor(separator?: string);
9
9
  static isSeparator(choice: unknown): choice is Separator;
10
10
  }
@@ -41,10 +41,10 @@ const readline = __importStar(require("node:readline"));
41
41
  const node_async_hooks_1 = require("node:async_hooks");
42
42
  const mute_stream_1 = __importDefault(require("mute-stream"));
43
43
  const signal_exit_1 = require("signal-exit");
44
- const screen_manager_js_1 = __importDefault(require("./screen-manager.js"));
45
- const promise_polyfill_js_1 = require("./promise-polyfill.js");
46
- const hook_engine_js_1 = require("./hook-engine.js");
47
- const errors_js_1 = require("./errors.js");
44
+ const screen_manager_ts_1 = __importDefault(require("./screen-manager.js"));
45
+ const promise_polyfill_ts_1 = require("./promise-polyfill.js");
46
+ const hook_engine_ts_1 = require("./hook-engine.js");
47
+ const errors_ts_1 = require("./errors.js");
48
48
  function getCallSites() {
49
49
  const _prepareStackTrace = Error.prepareStackTrace;
50
50
  let result = [];
@@ -79,11 +79,11 @@ function createPrompt(view) {
79
79
  input,
80
80
  output,
81
81
  });
82
- const screen = new screen_manager_js_1.default(rl);
83
- const { promise, resolve, reject } = promise_polyfill_js_1.PromisePolyfill.withResolver();
84
- const cancel = () => reject(new errors_js_1.CancelPromptError());
82
+ const screen = new screen_manager_ts_1.default(rl);
83
+ const { promise, resolve, reject } = promise_polyfill_ts_1.PromisePolyfill.withResolver();
84
+ const cancel = () => reject(new errors_ts_1.CancelPromptError());
85
85
  if (signal) {
86
- const abort = () => reject(new errors_js_1.AbortPromptError({ cause: signal.reason }));
86
+ const abort = () => reject(new errors_ts_1.AbortPromptError({ cause: signal.reason }));
87
87
  if (signal.aborted) {
88
88
  abort();
89
89
  return Object.assign(promise, { cancel });
@@ -92,7 +92,7 @@ function createPrompt(view) {
92
92
  cleanups.add(() => signal.removeEventListener('abort', abort));
93
93
  }
94
94
  cleanups.add((0, signal_exit_1.onExit)((code, signal) => {
95
- reject(new errors_js_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
95
+ reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
96
96
  }));
97
97
  // Re-renders only happen when the state change; but the readline cursor could change position
98
98
  // and that also requires a re-render (and a manual one because we mute the streams).
@@ -101,11 +101,11 @@ function createPrompt(view) {
101
101
  const checkCursorPos = () => screen.checkCursorPos();
102
102
  rl.input.on('keypress', checkCursorPos);
103
103
  cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
104
- return (0, hook_engine_js_1.withHooks)(rl, (cycle) => {
104
+ return (0, hook_engine_ts_1.withHooks)(rl, (cycle) => {
105
105
  // The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
106
106
  // triggers after the process is done (which happens after timeouts are done triggering.)
107
107
  // We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
108
- const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => hook_engine_js_1.effectScheduler.clearAll());
108
+ const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => hook_engine_ts_1.effectScheduler.clearAll());
109
109
  rl.on('close', hooksCleanup);
110
110
  cleanups.add(() => rl.removeListener('close', hooksCleanup));
111
111
  cycle(() => {
@@ -116,12 +116,12 @@ function createPrompt(view) {
116
116
  // Typescript won't allow this, but not all users rely on typescript.
117
117
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
118
118
  if (nextView === undefined) {
119
- const callerFilename = callSites[1]?.getFileName?.();
119
+ const callerFilename = callSites[1]?.getFileName();
120
120
  throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
121
121
  }
122
122
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
123
123
  screen.render(content, bottomContent);
124
- hook_engine_js_1.effectScheduler.run();
124
+ hook_engine_ts_1.effectScheduler.run();
125
125
  }
126
126
  catch (error) {
127
127
  reject(error);
@@ -129,10 +129,10 @@ function createPrompt(view) {
129
129
  });
130
130
  return Object.assign(promise
131
131
  .then((answer) => {
132
- hook_engine_js_1.effectScheduler.clearAll();
132
+ hook_engine_ts_1.effectScheduler.clearAll();
133
133
  return answer;
134
134
  }, (error) => {
135
- hook_engine_js_1.effectScheduler.clearAll();
135
+ hook_engine_ts_1.effectScheduler.clearAll();
136
136
  throw error;
137
137
  })
138
138
  // Wait for the promise to settle, then cleanup.
@@ -8,7 +8,7 @@ exports.withUpdates = withUpdates;
8
8
  exports.withPointer = withPointer;
9
9
  exports.handleChange = handleChange;
10
10
  const node_async_hooks_1 = require("node:async_hooks");
11
- const errors_js_1 = require("./errors.js");
11
+ const errors_ts_1 = require("./errors.js");
12
12
  const hookStorage = new node_async_hooks_1.AsyncLocalStorage();
13
13
  function createStore(rl) {
14
14
  const store = {
@@ -39,7 +39,7 @@ function withHooks(rl, cb) {
39
39
  function getStore() {
40
40
  const store = hookStorage.getStore();
41
41
  if (!store) {
42
- throw new errors_js_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
42
+ throw new errors_ts_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
43
43
  }
44
44
  return store;
45
45
  }
@@ -91,7 +91,7 @@ exports.effectScheduler = {
91
91
  store.hooksCleanup[index]?.();
92
92
  const cleanFn = cb(readline());
93
93
  if (cleanFn != null && typeof cleanFn !== 'function') {
94
- throw new errors_js_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
94
+ throw new errors_ts_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
95
95
  }
96
96
  store.hooksCleanup[index] = cleanFn;
97
97
  });
@@ -1,3 +1,3 @@
1
1
  import type { Prettify, PartialDeep } from '@inquirer/type';
2
- import { type Theme } from './theme.js';
2
+ import { type Theme } from './theme.ts';
3
3
  export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeTheme = makeTheme;
4
- const theme_js_1 = require("./theme.js");
4
+ const theme_ts_1 = require("./theme.js");
5
5
  function isPlainObject(value) {
6
6
  if (typeof value !== 'object' || value === null)
7
7
  return false;
@@ -26,7 +26,7 @@ function deepMerge(...objects) {
26
26
  }
27
27
  function makeTheme(...themes) {
28
28
  const themesToMerge = [
29
- theme_js_1.defaultTheme,
29
+ theme_ts_1.defaultTheme,
30
30
  ...themes.filter((theme) => theme != null),
31
31
  ];
32
32
  return deepMerge(...themesToMerge);
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lines = lines;
4
- const utils_js_1 = require("../utils.js");
4
+ const utils_ts_1 = require("../utils.js");
5
5
  function split(content, width) {
6
- return (0, utils_js_1.breakLines)(content, width).split('\n');
6
+ return (0, utils_ts_1.breakLines)(content, width).split('\n');
7
7
  }
8
8
  /**
9
9
  * Rotates an array of items by an integer number of positions.
@@ -1,6 +1,6 @@
1
1
  import type { Prettify } from '@inquirer/type';
2
- import { type Theme } from '../theme.js';
3
- import { type Layout } from './lines.js';
2
+ import { type Theme } from '../theme.ts';
3
+ import { type Layout } from './lines.ts';
4
4
  export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
5
5
  items: ReadonlyArray<T>;
6
6
  /** The index of the active item. */
@@ -1,30 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePagination = usePagination;
4
- const use_ref_js_1 = require("../use-ref.js");
5
- const utils_js_1 = require("../utils.js");
6
- const lines_js_1 = require("./lines.js");
7
- const position_js_1 = require("./position.js");
4
+ const use_ref_ts_1 = require("../use-ref.js");
5
+ const utils_ts_1 = require("../utils.js");
6
+ const lines_ts_1 = require("./lines.js");
7
+ const position_ts_1 = require("./position.js");
8
8
  function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
9
- const state = (0, use_ref_js_1.useRef)({ position: 0, lastActive: 0 });
9
+ const state = (0, use_ref_ts_1.useRef)({ position: 0, lastActive: 0 });
10
10
  const position = loop
11
- ? (0, position_js_1.infinite)({
11
+ ? (0, position_ts_1.infinite)({
12
12
  active,
13
13
  lastActive: state.current.lastActive,
14
14
  total: items.length,
15
15
  pageSize,
16
16
  pointer: state.current.position,
17
17
  })
18
- : (0, position_js_1.finite)({
18
+ : (0, position_ts_1.finite)({
19
19
  active,
20
20
  total: items.length,
21
21
  pageSize,
22
22
  });
23
23
  state.current.position = position;
24
24
  state.current.lastActive = active;
25
- return (0, lines_js_1.lines)({
25
+ return (0, lines_ts_1.lines)({
26
26
  items,
27
- width: (0, utils_js_1.readlineWidth)(),
27
+ width: (0, utils_ts_1.readlineWidth)(),
28
28
  renderItem,
29
29
  active,
30
30
  position,
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const node_util_1 = require("node:util");
7
7
  const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
8
- const utils_js_1 = require("./utils.js");
8
+ const utils_ts_1 = require("./utils.js");
9
9
  const height = (content) => content.split('\n').length;
10
10
  const lastLine = (content) => content.split('\n').pop() ?? '';
11
11
  function cursorDown(n) {
@@ -40,9 +40,9 @@ class ScreenManager {
40
40
  this.rl.setPrompt(prompt);
41
41
  // SetPrompt will change cursor position, now we can get correct value
42
42
  this.cursorPos = this.rl.getCursorPos();
43
- const width = (0, utils_js_1.readlineWidth)();
44
- content = (0, utils_js_1.breakLines)(content, width);
45
- bottomContent = (0, utils_js_1.breakLines)(bottomContent, width);
43
+ const width = (0, utils_ts_1.readlineWidth)();
44
+ content = (0, utils_ts_1.breakLines)(content, width);
45
+ bottomContent = (0, utils_ts_1.breakLines)(bottomContent, width);
46
46
  // Manually insert an extra line if we're at the end of the line.
47
47
  // This prevent the cursor from appearing at the beginning of the
48
48
  // current line.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useEffect = useEffect;
4
- const hook_engine_js_1 = require("./hook-engine.js");
4
+ const hook_engine_ts_1 = require("./hook-engine.js");
5
5
  function useEffect(cb, depArray) {
6
- (0, hook_engine_js_1.withPointer)((pointer) => {
6
+ (0, hook_engine_ts_1.withPointer)((pointer) => {
7
7
  const oldDeps = pointer.get();
8
8
  const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
9
9
  if (hasChanged) {
10
- hook_engine_js_1.effectScheduler.queue(cb);
10
+ hook_engine_ts_1.effectScheduler.queue(cb);
11
11
  }
12
12
  pointer.set(depArray);
13
13
  });
@@ -1,3 +1,3 @@
1
1
  import { type InquirerReadline } from '@inquirer/type';
2
- import { type KeypressEvent } from './key.js';
2
+ import { type KeypressEvent } from './key.ts';
3
3
  export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useKeypress = useKeypress;
4
- const use_ref_js_1 = require("./use-ref.js");
5
- const use_effect_js_1 = require("./use-effect.js");
6
- const hook_engine_js_1 = require("./hook-engine.js");
4
+ const use_ref_ts_1 = require("./use-ref.js");
5
+ const use_effect_ts_1 = require("./use-effect.js");
6
+ const hook_engine_ts_1 = require("./hook-engine.js");
7
7
  function useKeypress(userHandler) {
8
- const signal = (0, use_ref_js_1.useRef)(userHandler);
8
+ const signal = (0, use_ref_ts_1.useRef)(userHandler);
9
9
  signal.current = userHandler;
10
- (0, use_effect_js_1.useEffect)((rl) => {
10
+ (0, use_effect_ts_1.useEffect)((rl) => {
11
11
  let ignore = false;
12
- const handler = (0, hook_engine_js_1.withUpdates)((_input, event) => {
12
+ const handler = (0, hook_engine_ts_1.withUpdates)((_input, event) => {
13
13
  if (ignore)
14
14
  return;
15
15
  void signal.current(event, rl);
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMemo = useMemo;
4
- const hook_engine_js_1 = require("./hook-engine.js");
4
+ const hook_engine_ts_1 = require("./hook-engine.js");
5
5
  function useMemo(fn, dependencies) {
6
- return (0, hook_engine_js_1.withPointer)((pointer) => {
6
+ return (0, hook_engine_ts_1.withPointer)((pointer) => {
7
7
  const prev = pointer.get();
8
8
  if (!prev ||
9
9
  prev.dependencies.length !== dependencies.length ||
@@ -1,4 +1,4 @@
1
- import type { Theme, Status } from './theme.js';
1
+ import type { Theme, Status } from './theme.ts';
2
2
  export declare function usePrefix({ status, theme, }: {
3
3
  status?: Status;
4
4
  theme?: Theme;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePrefix = usePrefix;
4
4
  const node_async_hooks_1 = require("node:async_hooks");
5
- const use_state_js_1 = require("./use-state.js");
6
- const use_effect_js_1 = require("./use-effect.js");
7
- const make_theme_js_1 = require("./make-theme.js");
5
+ const use_state_ts_1 = require("./use-state.js");
6
+ const use_effect_ts_1 = require("./use-effect.js");
7
+ const make_theme_ts_1 = require("./make-theme.js");
8
8
  function usePrefix({ status = 'idle', theme, }) {
9
- const [showLoader, setShowLoader] = (0, use_state_js_1.useState)(false);
10
- const [tick, setTick] = (0, use_state_js_1.useState)(0);
11
- const { prefix, spinner } = (0, make_theme_js_1.makeTheme)(theme);
12
- (0, use_effect_js_1.useEffect)(() => {
9
+ const [showLoader, setShowLoader] = (0, use_state_ts_1.useState)(false);
10
+ const [tick, setTick] = (0, use_state_ts_1.useState)(0);
11
+ const { prefix, spinner } = (0, make_theme_ts_1.makeTheme)(theme);
12
+ (0, use_effect_ts_1.useEffect)(() => {
13
13
  if (status === 'loading') {
14
14
  let tickInterval;
15
15
  let inc = -1;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useRef = useRef;
4
- const use_state_js_1 = require("./use-state.js");
4
+ const use_state_ts_1 = require("./use-state.js");
5
5
  function useRef(val) {
6
- return (0, use_state_js_1.useState)({ current: val })[0];
6
+ return (0, use_state_ts_1.useState)({ current: val })[0];
7
7
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useState = useState;
4
- const hook_engine_js_1 = require("./hook-engine.js");
4
+ const hook_engine_ts_1 = require("./hook-engine.js");
5
5
  function useState(defaultValue) {
6
- return (0, hook_engine_js_1.withPointer)((pointer) => {
6
+ return (0, hook_engine_ts_1.withPointer)((pointer) => {
7
7
  const setFn = (newValue) => {
8
8
  // Noop if the value is still the same.
9
9
  if (pointer.get() !== newValue) {
10
10
  pointer.set(newValue);
11
11
  // Trigger re-render
12
- (0, hook_engine_js_1.handleChange)();
12
+ (0, hook_engine_ts_1.handleChange)();
13
13
  }
14
14
  };
15
15
  if (pointer.initialized) {
@@ -7,7 +7,7 @@ exports.breakLines = breakLines;
7
7
  exports.readlineWidth = readlineWidth;
8
8
  const cli_width_1 = __importDefault(require("cli-width"));
9
9
  const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
10
- const hook_engine_js_1 = require("./hook-engine.js");
10
+ const hook_engine_ts_1 = require("./hook-engine.js");
11
11
  /**
12
12
  * Force line returns at specific width. This function is ANSI code friendly and it'll
13
13
  * ignore invisible codes during width calculation.
@@ -28,5 +28,5 @@ function breakLines(content, width) {
28
28
  * @returns {number}
29
29
  */
30
30
  function readlineWidth() {
31
- return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_js_1.readline)().output });
31
+ return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_ts_1.readline)().output });
32
32
  }
@@ -1,13 +1,13 @@
1
- export * from './lib/key.js';
2
- export * from './lib/errors.js';
3
- export { usePrefix } from './lib/use-prefix.js';
4
- export { useState } from './lib/use-state.js';
5
- export { useEffect } from './lib/use-effect.js';
6
- export { useMemo } from './lib/use-memo.js';
7
- export { useRef } from './lib/use-ref.js';
8
- export { useKeypress } from './lib/use-keypress.js';
9
- export { makeTheme } from './lib/make-theme.js';
10
- export type { Theme, Status } from './lib/theme.js';
11
- export { usePagination } from './lib/pagination/use-pagination.js';
12
- export { createPrompt } from './lib/create-prompt.js';
13
- export { Separator } from './lib/Separator.js';
1
+ export * from './lib/key.ts';
2
+ export * from './lib/errors.ts';
3
+ export { usePrefix } from './lib/use-prefix.ts';
4
+ export { useState } from './lib/use-state.ts';
5
+ export { useEffect } from './lib/use-effect.ts';
6
+ export { useMemo } from './lib/use-memo.ts';
7
+ export { useRef } from './lib/use-ref.ts';
8
+ export { useKeypress } from './lib/use-keypress.ts';
9
+ export { makeTheme } from './lib/make-theme.ts';
10
+ export type { Theme, Status } from './lib/theme.ts';
11
+ export { usePagination } from './lib/pagination/use-pagination.ts';
12
+ export { createPrompt } from './lib/create-prompt.ts';
13
+ export { Separator } from './lib/Separator.ts';
package/dist/esm/index.js CHANGED
@@ -1,12 +1,12 @@
1
- export * from './lib/key.js';
2
- export * from './lib/errors.js';
3
- export { usePrefix } from './lib/use-prefix.js';
4
- export { useState } from './lib/use-state.js';
5
- export { useEffect } from './lib/use-effect.js';
6
- export { useMemo } from './lib/use-memo.js';
7
- export { useRef } from './lib/use-ref.js';
8
- export { useKeypress } from './lib/use-keypress.js';
9
- export { makeTheme } from './lib/make-theme.js';
10
- export { usePagination } from './lib/pagination/use-pagination.js';
11
- export { createPrompt } from './lib/create-prompt.js';
12
- export { Separator } from './lib/Separator.js';
1
+ export * from "./lib/key.js";
2
+ export * from "./lib/errors.js";
3
+ export { usePrefix } from "./lib/use-prefix.js";
4
+ export { useState } from "./lib/use-state.js";
5
+ export { useEffect } from "./lib/use-effect.js";
6
+ export { useMemo } from "./lib/use-memo.js";
7
+ export { useRef } from "./lib/use-ref.js";
8
+ export { useKeypress } from "./lib/use-keypress.js";
9
+ export { makeTheme } from "./lib/make-theme.js";
10
+ export { usePagination } from "./lib/pagination/use-pagination.js";
11
+ export { createPrompt } from "./lib/create-prompt.js";
12
+ export { Separator } from "./lib/Separator.js";
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export declare class Separator {
6
6
  readonly separator: string;
7
- readonly type = "separator";
7
+ readonly type: string;
8
8
  constructor(separator?: string);
9
9
  static isSeparator(choice: unknown): choice is Separator;
10
10
  }
@@ -2,10 +2,10 @@ import * as readline from 'node:readline';
2
2
  import { AsyncResource } from 'node:async_hooks';
3
3
  import MuteStream from 'mute-stream';
4
4
  import { onExit as onSignalExit } from 'signal-exit';
5
- import ScreenManager from './screen-manager.js';
6
- import { PromisePolyfill } from './promise-polyfill.js';
7
- import { withHooks, effectScheduler } from './hook-engine.js';
8
- import { AbortPromptError, CancelPromptError, ExitPromptError } from './errors.js';
5
+ import ScreenManager from "./screen-manager.js";
6
+ import { PromisePolyfill } from "./promise-polyfill.js";
7
+ import { withHooks, effectScheduler } from "./hook-engine.js";
8
+ import { AbortPromptError, CancelPromptError, ExitPromptError } from "./errors.js";
9
9
  function getCallSites() {
10
10
  const _prepareStackTrace = Error.prepareStackTrace;
11
11
  let result = [];
@@ -77,7 +77,7 @@ export function createPrompt(view) {
77
77
  // Typescript won't allow this, but not all users rely on typescript.
78
78
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
79
79
  if (nextView === undefined) {
80
- const callerFilename = callSites[1]?.getFileName?.();
80
+ const callerFilename = callSites[1]?.getFileName();
81
81
  throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
82
82
  }
83
83
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
@@ -1,6 +1,6 @@
1
1
  /* eslint @typescript-eslint/no-explicit-any: ["off"] */
2
2
  import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
3
- import { HookError, ValidationError } from './errors.js';
3
+ import { HookError, ValidationError } from "./errors.js";
4
4
  const hookStorage = new AsyncLocalStorage();
5
5
  function createStore(rl) {
6
6
  const store = {
@@ -1,3 +1,3 @@
1
1
  import type { Prettify, PartialDeep } from '@inquirer/type';
2
- import { type Theme } from './theme.js';
2
+ import { type Theme } from './theme.ts';
3
3
  export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
@@ -1,4 +1,4 @@
1
- import { defaultTheme } from './theme.js';
1
+ import { defaultTheme } from "./theme.js";
2
2
  function isPlainObject(value) {
3
3
  if (typeof value !== 'object' || value === null)
4
4
  return false;
@@ -1,4 +1,4 @@
1
- import { breakLines } from '../utils.js';
1
+ import { breakLines } from "../utils.js";
2
2
  function split(content, width) {
3
3
  return breakLines(content, width).split('\n');
4
4
  }
@@ -1,6 +1,6 @@
1
1
  import type { Prettify } from '@inquirer/type';
2
- import { type Theme } from '../theme.js';
3
- import { type Layout } from './lines.js';
2
+ import { type Theme } from '../theme.ts';
3
+ import { type Layout } from './lines.ts';
4
4
  export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
5
5
  items: ReadonlyArray<T>;
6
6
  /** The index of the active item. */
@@ -1,7 +1,7 @@
1
- import { useRef } from '../use-ref.js';
2
- import { readlineWidth } from '../utils.js';
3
- import { lines } from './lines.js';
4
- import { finite, infinite } from './position.js';
1
+ import { useRef } from "../use-ref.js";
2
+ import { readlineWidth } from "../utils.js";
3
+ import { lines } from "./lines.js";
4
+ import { finite, infinite } from "./position.js";
5
5
  export function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
6
6
  const state = useRef({ position: 0, lastActive: 0 });
7
7
  const position = loop
@@ -1,6 +1,6 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
2
  import ansiEscapes from 'ansi-escapes';
3
- import { breakLines, readlineWidth } from './utils.js';
3
+ import { breakLines, readlineWidth } from "./utils.js";
4
4
  const height = (content) => content.split('\n').length;
5
5
  const lastLine = (content) => content.split('\n').pop() ?? '';
6
6
  function cursorDown(n) {
@@ -1,4 +1,4 @@
1
- import { withPointer, effectScheduler } from './hook-engine.js';
1
+ import { withPointer, effectScheduler } from "./hook-engine.js";
2
2
  export function useEffect(cb, depArray) {
3
3
  withPointer((pointer) => {
4
4
  const oldDeps = pointer.get();
@@ -1,3 +1,3 @@
1
1
  import { type InquirerReadline } from '@inquirer/type';
2
- import { type KeypressEvent } from './key.js';
2
+ import { type KeypressEvent } from './key.ts';
3
3
  export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
@@ -1,6 +1,6 @@
1
- import { useRef } from './use-ref.js';
2
- import { useEffect } from './use-effect.js';
3
- import { withUpdates } from './hook-engine.js';
1
+ import { useRef } from "./use-ref.js";
2
+ import { useEffect } from "./use-effect.js";
3
+ import { withUpdates } from "./hook-engine.js";
4
4
  export function useKeypress(userHandler) {
5
5
  const signal = useRef(userHandler);
6
6
  signal.current = userHandler;
@@ -1,4 +1,4 @@
1
- import { withPointer } from './hook-engine.js';
1
+ import { withPointer } from "./hook-engine.js";
2
2
  export function useMemo(fn, dependencies) {
3
3
  return withPointer((pointer) => {
4
4
  const prev = pointer.get();
@@ -1,4 +1,4 @@
1
- import type { Theme, Status } from './theme.js';
1
+ import type { Theme, Status } from './theme.ts';
2
2
  export declare function usePrefix({ status, theme, }: {
3
3
  status?: Status;
4
4
  theme?: Theme;
@@ -1,7 +1,7 @@
1
1
  import { AsyncResource } from 'node:async_hooks';
2
- import { useState } from './use-state.js';
3
- import { useEffect } from './use-effect.js';
4
- import { makeTheme } from './make-theme.js';
2
+ import { useState } from "./use-state.js";
3
+ import { useEffect } from "./use-effect.js";
4
+ import { makeTheme } from "./make-theme.js";
5
5
  export function usePrefix({ status = 'idle', theme, }) {
6
6
  const [showLoader, setShowLoader] = useState(false);
7
7
  const [tick, setTick] = useState(0);
@@ -1,4 +1,4 @@
1
- import { useState } from './use-state.js';
1
+ import { useState } from "./use-state.js";
2
2
  export function useRef(val) {
3
3
  return useState({ current: val })[0];
4
4
  }
@@ -1,4 +1,4 @@
1
- import { withPointer, handleChange } from './hook-engine.js';
1
+ import { withPointer, handleChange } from "./hook-engine.js";
2
2
  export function useState(defaultValue) {
3
3
  return withPointer((pointer) => {
4
4
  const setFn = (newValue) => {
@@ -1,6 +1,6 @@
1
1
  import cliWidth from 'cli-width';
2
2
  import wrapAnsi from 'wrap-ansi';
3
- import { readline } from './hook-engine.js';
3
+ import { readline } from "./hook-engine.js";
4
4
  /**
5
5
  * Force line returns at specific width. This function is ANSI code friendly and it'll
6
6
  * ignore invisible codes during width calculation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "10.1.9",
3
+ "version": "10.1.10",
4
4
  "description": "Core Inquirer prompt API",
5
5
  "keywords": [
6
6
  "answer",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@inquirer/figures": "^1.0.11",
78
- "@inquirer/type": "^3.0.5",
78
+ "@inquirer/type": "^3.0.6",
79
79
  "ansi-escapes": "^4.3.2",
80
80
  "cli-width": "^4.1.0",
81
81
  "mute-stream": "^2.0.0",
@@ -85,10 +85,10 @@
85
85
  },
86
86
  "devDependencies": {
87
87
  "@arethetypeswrong/cli": "^0.17.4",
88
- "@inquirer/testing": "^2.1.45",
88
+ "@inquirer/testing": "^2.1.46",
89
89
  "@repo/tsconfig": "workspace:*",
90
90
  "@types/mute-stream": "^0.0.4",
91
- "@types/node": "^22.13.10",
91
+ "@types/node": "^22.14.0",
92
92
  "@types/wrap-ansi": "^3.0.0",
93
93
  "tshy": "^3.0.2"
94
94
  },
@@ -115,5 +115,5 @@
115
115
  ".": "./src/index.ts"
116
116
  }
117
117
  },
118
- "gitHead": "83508f90ca65d26abc1408e4209e4f8fc73e43fe"
118
+ "gitHead": "d367155a8d64d8b3e93f9c763adccf708aedc8a8"
119
119
  }