@inquirer/core 7.0.2 → 7.1.0

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/dist/cjs/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  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
+ __exportStar(require('./lib/errors.js'), exports);
19
20
  var use_prefix_mjs_1 = require('./lib/use-prefix.js');
20
21
  Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_mjs_1.usePrefix; } });
21
22
  var use_state_mjs_1 = require('./lib/use-state.js');
@@ -33,6 +33,7 @@ const mute_stream_1 = __importDefault(require("mute-stream"));
33
33
  const signal_exit_1 = require("signal-exit");
34
34
  const screen_manager_mjs_1 = __importDefault(require('./screen-manager.js'));
35
35
  const hook_engine_mjs_1 = require('./hook-engine.js');
36
+ const errors_mjs_1 = require('./errors.js');
36
37
  function createPrompt(view) {
37
38
  const prompt = (config, context) => {
38
39
  var _a, _b;
@@ -55,7 +56,7 @@ function createPrompt(view) {
55
56
  }
56
57
  const removeExitListener = (0, signal_exit_1.onExit)((code, signal) => {
57
58
  onExit();
58
- reject(new Error(`User force closed the prompt with ${code} ${signal}`));
59
+ reject(new errors_mjs_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
59
60
  });
60
61
  function onExit() {
61
62
  try {
@@ -78,7 +79,7 @@ function createPrompt(view) {
78
79
  }
79
80
  cancel = () => {
80
81
  onExit();
81
- reject(new Error('Prompt was canceled'));
82
+ reject(new errors_mjs_1.CancelPromptError());
82
83
  };
83
84
  function done(value) {
84
85
  // Delay execution to let time to the hookCleanup functions to registers.
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.HookError = exports.ExitPromptError = exports.CancelPromptError = void 0;
4
+ class CancelPromptError extends Error {
5
+ constructor() {
6
+ super(...arguments);
7
+ Object.defineProperty(this, "message", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: 'Prompt was canceled'
12
+ });
13
+ }
14
+ }
15
+ exports.CancelPromptError = CancelPromptError;
16
+ class ExitPromptError extends Error {
17
+ }
18
+ exports.ExitPromptError = ExitPromptError;
19
+ class HookError extends Error {
20
+ }
21
+ exports.HookError = HookError;
22
+ class ValidationError extends Error {
23
+ }
24
+ exports.ValidationError = ValidationError;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.effectScheduler = exports.handleChange = exports.withPointer = exports.withUpdates = exports.readline = exports.withHooks = void 0;
4
4
  const node_async_hooks_1 = require("node:async_hooks");
5
+ const errors_mjs_1 = require('./errors.js');
5
6
  const hookStorage = new node_async_hooks_1.AsyncLocalStorage();
6
7
  function createStore(rl) {
7
8
  const store = {
@@ -26,7 +27,7 @@ exports.withHooks = withHooks;
26
27
  function getStore() {
27
28
  const store = hookStorage.getStore();
28
29
  if (!store) {
29
- throw new Error('[Inquirer] Hook functions can only be called from within a prompt');
30
+ throw new errors_mjs_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
30
31
  }
31
32
  return store;
32
33
  }
@@ -83,7 +84,7 @@ exports.effectScheduler = {
83
84
  (_b = (_a = store.hooksCleanup)[index]) === null || _b === void 0 ? void 0 : _b.call(_a);
84
85
  const cleanFn = cb(readline());
85
86
  if (cleanFn != null && typeof cleanFn !== 'function') {
86
- throw new Error('useEffect return value must be a cleanup function or nothing.');
87
+ throw new errors_mjs_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
87
88
  }
88
89
  store.hooksCleanup[index] = cleanFn;
89
90
  });
@@ -1,4 +1,5 @@
1
1
  export * from './lib/key.js';
2
+ export * from './lib/errors.js';
2
3
  export { usePrefix } from './lib/use-prefix.js';
3
4
  export { useState } from './lib/use-state.js';
4
5
  export { useEffect } from './lib/use-effect.js';
@@ -0,0 +1,9 @@
1
+ export declare class CancelPromptError extends Error {
2
+ message: string;
3
+ }
4
+ export declare class ExitPromptError extends Error {
5
+ }
6
+ export declare class HookError extends Error {
7
+ }
8
+ export declare class ValidationError extends Error {
9
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './lib/key.mjs';
2
+ export * from './lib/errors.mjs';
2
3
  export { usePrefix } from './lib/use-prefix.mjs';
3
4
  export { useState } from './lib/use-state.mjs';
4
5
  export { useEffect } from './lib/use-effect.mjs';
@@ -4,6 +4,7 @@ import MuteStream from 'mute-stream';
4
4
  import { onExit as onSignalExit } from 'signal-exit';
5
5
  import ScreenManager from './screen-manager.mjs';
6
6
  import { withHooks, effectScheduler } from './hook-engine.mjs';
7
+ import { CancelPromptError, ExitPromptError } from './errors.mjs';
7
8
  export function createPrompt(view) {
8
9
  const prompt = (config, context) => {
9
10
  // Default `input` to stdin
@@ -25,7 +26,7 @@ export function createPrompt(view) {
25
26
  }
26
27
  const removeExitListener = onSignalExit((code, signal) => {
27
28
  onExit();
28
- reject(new Error(`User force closed the prompt with ${code} ${signal}`));
29
+ reject(new ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
29
30
  });
30
31
  function onExit() {
31
32
  try {
@@ -48,7 +49,7 @@ export function createPrompt(view) {
48
49
  }
49
50
  cancel = () => {
50
51
  onExit();
51
- reject(new Error('Prompt was canceled'));
52
+ reject(new CancelPromptError());
52
53
  };
53
54
  function done(value) {
54
55
  // Delay execution to let time to the hookCleanup functions to registers.
@@ -0,0 +1,9 @@
1
+ export class CancelPromptError extends Error {
2
+ message = 'Prompt was canceled';
3
+ }
4
+ export class ExitPromptError extends Error {
5
+ }
6
+ export class HookError extends Error {
7
+ }
8
+ export class ValidationError extends Error {
9
+ }
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
2
+ import { HookError, ValidationError } from './errors.mjs';
2
3
  const hookStorage = new AsyncLocalStorage();
3
4
  function createStore(rl) {
4
5
  const store = {
@@ -22,7 +23,7 @@ export function withHooks(rl, cb) {
22
23
  function getStore() {
23
24
  const store = hookStorage.getStore();
24
25
  if (!store) {
25
- throw new Error('[Inquirer] Hook functions can only be called from within a prompt');
26
+ throw new HookError('[Inquirer] Hook functions can only be called from within a prompt');
26
27
  }
27
28
  return store;
28
29
  }
@@ -74,7 +75,7 @@ export const effectScheduler = {
74
75
  store.hooksCleanup[index]?.();
75
76
  const cleanFn = cb(readline());
76
77
  if (cleanFn != null && typeof cleanFn !== 'function') {
77
- throw new Error('useEffect return value must be a cleanup function or nothing.');
78
+ throw new ValidationError('useEffect return value must be a cleanup function or nothing.');
78
79
  }
79
80
  store.hooksCleanup[index] = cleanFn;
80
81
  });
@@ -1,4 +1,5 @@
1
1
  export * from './lib/key.mjs';
2
+ export * from './lib/errors.mjs';
2
3
  export { usePrefix } from './lib/use-prefix.mjs';
3
4
  export { useState } from './lib/use-state.mjs';
4
5
  export { useEffect } from './lib/use-effect.mjs';
@@ -0,0 +1,9 @@
1
+ export declare class CancelPromptError extends Error {
2
+ message: string;
3
+ }
4
+ export declare class ExitPromptError extends Error {
5
+ }
6
+ export declare class HookError extends Error {
7
+ }
8
+ export declare class ValidationError extends Error {
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -57,9 +57,9 @@
57
57
  "license": "MIT",
58
58
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
59
59
  "dependencies": {
60
- "@inquirer/type": "^1.2.0",
60
+ "@inquirer/type": "^1.2.1",
61
61
  "@types/mute-stream": "^0.0.4",
62
- "@types/node": "^20.11.25",
62
+ "@types/node": "^20.11.26",
63
63
  "@types/wrap-ansi": "^3.0.0",
64
64
  "ansi-escapes": "^4.3.2",
65
65
  "chalk": "^4.1.2",
@@ -73,12 +73,13 @@
73
73
  "wrap-ansi": "^6.2.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@inquirer/testing": "^2.1.12"
76
+ "@inquirer/testing": "^2.1.13"
77
77
  },
78
78
  "scripts": {
79
79
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
80
80
  "tsc:esm": "rm -rf dist/esm && tsc -p ./tsconfig.json",
81
- "tsc:cjs": "rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs"
81
+ "tsc:cjs": "rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs",
82
+ "attw": "attw --pack"
82
83
  },
83
84
  "publishConfig": {
84
85
  "access": "public"
@@ -95,5 +96,5 @@
95
96
  }
96
97
  }
97
98
  },
98
- "gitHead": "85fba2337df29f689d058a9260df163af89caa98"
99
+ "gitHead": "2de191afab92c1a214dfe268c80109014803f11b"
99
100
  }