@inquirer/core 10.0.1 → 10.1.1

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.
package/README.md CHANGED
@@ -296,7 +296,7 @@ export default createPrompt<string, PromptConfig>((config, done) => {
296
296
  });
297
297
  ```
298
298
 
299
- The [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/theme/packages/core/src/lib/theme.mts):
299
+ The [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/core/src/lib/theme.ts):
300
300
 
301
301
  ```ts
302
302
  type DefaultTheme = {
@@ -321,14 +321,14 @@ type DefaultTheme = {
321
321
 
322
322
  You can refer to any `@inquirer/prompts` prompts for real examples:
323
323
 
324
- - [Confirm Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/confirm/src/index.mts)
325
- - [Input Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/input/src/index.mts)
326
- - [Password Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/password/src/index.mts)
327
- - [Editor Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/editor/src/index.mts)
328
- - [Select Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/select/src/index.mts)
329
- - [Checkbox Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/checkbox/src/index.mts)
330
- - [Rawlist Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/rawlist/src/index.mts)
331
- - [Expand Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/expand/src/index.mts)
324
+ - [Confirm Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/confirm/src/index.ts)
325
+ - [Input Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/input/src/index.ts)
326
+ - [Password Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/password/src/index.ts)
327
+ - [Editor Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/editor/src/index.ts)
328
+ - [Select Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/select/src/index.ts)
329
+ - [Checkbox Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/checkbox/src/index.ts)
330
+ - [Rawlist Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/rawlist/src/index.ts)
331
+ - [Expand Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/expand/src/index.ts)
332
332
 
333
333
  ```ts
334
334
  import colors from 'yoctocolors';
@@ -35,7 +35,26 @@ const screen_manager_js_1 = __importDefault(require("./screen-manager.js"));
35
35
  const promise_polyfill_js_1 = require("./promise-polyfill.js");
36
36
  const hook_engine_js_1 = require("./hook-engine.js");
37
37
  const errors_js_1 = require("./errors.js");
38
+ function getCallSites() {
39
+ const _prepareStackTrace = Error.prepareStackTrace;
40
+ try {
41
+ let result = [];
42
+ Error.prepareStackTrace = (_, callSites) => {
43
+ const callSitesWithoutCurrent = callSites.slice(1);
44
+ result = callSitesWithoutCurrent;
45
+ return callSitesWithoutCurrent;
46
+ };
47
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions, unicorn/error-message
48
+ new Error().stack;
49
+ return result;
50
+ }
51
+ finally {
52
+ Error.prepareStackTrace = _prepareStackTrace;
53
+ }
54
+ }
38
55
  function createPrompt(view) {
56
+ const callSites = getCallSites();
57
+ const callerFilename = callSites[1]?.getFileName?.();
39
58
  const prompt = (config, context = {}) => {
40
59
  // Default `input` to stdin
41
60
  const { input = process.stdin, signal } = context;
@@ -83,6 +102,11 @@ function createPrompt(view) {
83
102
  const nextView = view(config, (value) => {
84
103
  setImmediate(() => resolve(value));
85
104
  });
105
+ // Typescript won't allow this, but not all users rely on typescript.
106
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
107
+ if (nextView === undefined) {
108
+ throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
109
+ }
86
110
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
87
111
  screen.render(content, bottomContent);
88
112
  hook_engine_js_1.effectScheduler.run();
@@ -6,8 +6,9 @@ import type { Prettify } from '@inquirer/type';
6
6
  * - `'idle'`: The prompt is loaded and currently waiting for the user to
7
7
  * submit an answer.
8
8
  * - `'done'`: The user has submitted an answer and the prompt is finished.
9
+ * - `string`: Any other string: The prompt is in a custom state.
9
10
  */
10
- export type Status = 'loading' | 'idle' | 'done';
11
+ export type Status = 'loading' | 'idle' | 'done' | (string & {});
11
12
  type DefaultTheme = {
12
13
  /**
13
14
  * Prefix to prepend to the message. If a function is provided, it will be
@@ -35,5 +35,5 @@ function usePrefix({ status = 'idle', theme, }) {
35
35
  }
36
36
  // There's a delay before we show the loader. So we want to ignore `loading` here, and pass idle instead.
37
37
  const iconName = status === 'loading' ? 'idle' : status;
38
- return typeof prefix === 'string' ? prefix : prefix[iconName];
38
+ return typeof prefix === 'string' ? prefix : (prefix[iconName] ?? prefix['idle']);
39
39
  }
@@ -6,7 +6,26 @@ 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
+ function getCallSites() {
10
+ const _prepareStackTrace = Error.prepareStackTrace;
11
+ try {
12
+ let result = [];
13
+ Error.prepareStackTrace = (_, callSites) => {
14
+ const callSitesWithoutCurrent = callSites.slice(1);
15
+ result = callSitesWithoutCurrent;
16
+ return callSitesWithoutCurrent;
17
+ };
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions, unicorn/error-message
19
+ new Error().stack;
20
+ return result;
21
+ }
22
+ finally {
23
+ Error.prepareStackTrace = _prepareStackTrace;
24
+ }
25
+ }
9
26
  export function createPrompt(view) {
27
+ const callSites = getCallSites();
28
+ const callerFilename = callSites[1]?.getFileName?.();
10
29
  const prompt = (config, context = {}) => {
11
30
  // Default `input` to stdin
12
31
  const { input = process.stdin, signal } = context;
@@ -54,6 +73,11 @@ export function createPrompt(view) {
54
73
  const nextView = view(config, (value) => {
55
74
  setImmediate(() => resolve(value));
56
75
  });
76
+ // Typescript won't allow this, but not all users rely on typescript.
77
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
78
+ if (nextView === undefined) {
79
+ throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
80
+ }
57
81
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
58
82
  screen.render(content, bottomContent);
59
83
  effectScheduler.run();
@@ -6,8 +6,9 @@ import type { Prettify } from '@inquirer/type';
6
6
  * - `'idle'`: The prompt is loaded and currently waiting for the user to
7
7
  * submit an answer.
8
8
  * - `'done'`: The user has submitted an answer and the prompt is finished.
9
+ * - `string`: Any other string: The prompt is in a custom state.
9
10
  */
10
- export type Status = 'loading' | 'idle' | 'done';
11
+ export type Status = 'loading' | 'idle' | 'done' | (string & {});
11
12
  type DefaultTheme = {
12
13
  /**
13
14
  * Prefix to prepend to the message. If a function is provided, it will be
@@ -32,5 +32,5 @@ export function usePrefix({ status = 'idle', theme, }) {
32
32
  }
33
33
  // There's a delay before we show the loader. So we want to ignore `loading` here, and pass idle instead.
34
34
  const iconName = status === 'loading' ? 'idle' : status;
35
- return typeof prefix === 'string' ? prefix : prefix[iconName];
35
+ return typeof prefix === 'string' ? prefix : (prefix[iconName] ?? prefix['idle']);
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "10.0.1",
3
+ "version": "10.1.1",
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.7",
78
- "@inquirer/type": "^3.0.0",
77
+ "@inquirer/figures": "^1.0.8",
78
+ "@inquirer/type": "^3.0.1",
79
79
  "ansi-escapes": "^4.3.2",
80
80
  "cli-width": "^4.1.0",
81
81
  "mute-stream": "^2.0.0",
@@ -85,11 +85,11 @@
85
85
  "yoctocolors-cjs": "^2.1.2"
86
86
  },
87
87
  "devDependencies": {
88
- "@arethetypeswrong/cli": "^0.16.4",
89
- "@inquirer/testing": "^2.1.36",
88
+ "@arethetypeswrong/cli": "^0.17.0",
89
+ "@inquirer/testing": "^2.1.38",
90
90
  "@repo/tsconfig": "workspace:*",
91
91
  "@types/mute-stream": "^0.0.4",
92
- "@types/node": "^22.8.0",
92
+ "@types/node": "^22.10.1",
93
93
  "@types/wrap-ansi": "^3.0.0",
94
94
  "tshy": "^3.0.2"
95
95
  },
@@ -108,5 +108,5 @@
108
108
  ".": "./src/index.ts"
109
109
  }
110
110
  },
111
- "gitHead": "da3dd749325495266025f2dbdb339a812da468f8"
111
+ "gitHead": "5713287885155c0081fca4190c17c18c598d9602"
112
112
  }