@inquirer/core 4.1.0 → 5.0.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.
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Separator = void 0;
4
- const chalk_1 = require("chalk");
5
- const figures_1 = require("figures");
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const figures_1 = __importDefault(require("figures"));
6
9
  /**
7
10
  * Separator object
8
11
  * Used to space/separate choices group
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,19 +31,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
32
  });
10
33
  };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
11
37
  Object.defineProperty(exports, "__esModule", { value: true });
12
38
  exports.createPrompt = void 0;
13
- const readline = require("node:readline");
39
+ const readline = __importStar(require("node:readline"));
14
40
  const type_1 = require("@inquirer/type");
15
- const mute_stream_1 = require("mute-stream");
41
+ const mute_stream_1 = __importDefault(require("mute-stream"));
16
42
  const signal_exit_1 = require("signal-exit");
17
- const screen_manager_mjs_1 = require('./screen-manager.js');
43
+ const screen_manager_mjs_1 = __importDefault(require('./screen-manager.js'));
18
44
  const hook_engine_mjs_1 = require('./hook-engine.js');
19
45
  // Take an AsyncPromptConfig and resolves all it's values.
20
46
  function getPromptConfig(config) {
21
47
  return __awaiter(this, void 0, void 0, function* () {
22
48
  const message = typeof config.message === 'function' ? config.message() : config.message;
23
- return Object.assign(Object.assign({ validate: () => true }, config), { message: yield message });
49
+ return Object.assign(Object.assign({}, config), { message: yield message });
24
50
  });
25
51
  }
26
52
  function createPrompt(view) {
@@ -94,7 +94,9 @@ exports.effectScheduler = {
94
94
  store.hooksEffect.forEach((effect) => {
95
95
  effect();
96
96
  });
97
+ // Warning: Clean the hooks before exiting the `withUpdates` block.
98
+ // Failure to do so means an updates would hit the same effects again.
99
+ store.hooksEffect.length = 0;
97
100
  })();
98
- store.hooksEffect.length = 0;
99
101
  },
100
102
  };
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const cli_width_1 = require("cli-width");
4
- const strip_ansi_1 = require("strip-ansi");
5
- const ansi_escapes_1 = require("ansi-escapes");
6
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
7
+ const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
6
8
  const utils_mjs_1 = require('./utils.js');
7
9
  const height = (content) => content.split('\n').length;
8
10
  const lastLine = (content) => { var _a; return (_a = content.split('\n').pop()) !== null && _a !== void 0 ? _a : ''; };
@@ -54,7 +56,7 @@ class ScreenManager {
54
56
  this.rl.setPrompt(prompt);
55
57
  // SetPrompt will change cursor position, now we can get correct value
56
58
  this.cursorPos = this.rl.getCursorPos();
57
- const width = (0, cli_width_1.default)({ defaultWidth: 80, output: this.rl.output });
59
+ const width = (0, utils_mjs_1.readlineWidth)();
58
60
  content = (0, utils_mjs_1.breakLines)(content, width);
59
61
  bottomContent = (0, utils_mjs_1.breakLines)(bottomContent, width);
60
62
  // Manually insert an extra line if we're at the end of the line.
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.usePagination = void 0;
4
- const chalk_1 = require("chalk");
5
- const cli_width_1 = require("cli-width");
7
+ const chalk_1 = __importDefault(require("chalk"));
6
8
  const utils_mjs_1 = require('./utils.js');
7
- const hook_engine_mjs_1 = require('./hook-engine.js');
8
9
  const use_ref_mjs_1 = require('./use-ref.js');
9
10
  function usePagination(output, { active, pageSize = 7, }) {
10
- const rl = (0, hook_engine_mjs_1.readline)();
11
11
  const state = (0, use_ref_mjs_1.useRef)({
12
12
  pointer: 0,
13
13
  lastIndex: 0,
14
14
  });
15
- const width = (0, cli_width_1.default)({ defaultWidth: 80, output: rl.output });
15
+ const width = (0, utils_mjs_1.readlineWidth)();
16
16
  const lines = (0, utils_mjs_1.breakLines)(output, width).split('\n');
17
17
  // Make sure there's enough lines to paginate
18
18
  if (lines.length <= pageSize) {
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.usePrefix = void 0;
4
- const chalk_1 = require("chalk");
5
- const spinners = require("cli-spinners");
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const cli_spinners_1 = __importDefault(require("cli-spinners"));
6
9
  const use_state_mjs_1 = require('./use-state.js');
7
10
  const use_effect_mjs_1 = require('./use-effect.js');
8
- const spinner = spinners.dots;
11
+ const spinner = cli_spinners_1.default.dots;
9
12
  function usePrefix(isLoading = false) {
10
13
  const [tick, setTick] = (0, use_state_mjs_1.useState)(0);
11
14
  (0, use_effect_mjs_1.useEffect)(() => {
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.breakLines = void 0;
4
- const wrap_ansi_1 = require("wrap-ansi");
6
+ exports.readlineWidth = exports.breakLines = void 0;
7
+ const cli_width_1 = __importDefault(require("cli-width"));
8
+ const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
9
+ const hook_engine_mjs_1 = require('./hook-engine.js');
5
10
  /**
6
11
  * Force line returns at specific width. This function is ANSI code friendly and it'll
7
12
  * ignore invisible codes during width calculation.
@@ -9,10 +14,20 @@ const wrap_ansi_1 = require("wrap-ansi");
9
14
  * @param {number} width
10
15
  * @return {string}
11
16
  */
12
- const breakLines = (content, width) => content
13
- .split('\n')
14
- .flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
15
- .split('\n')
16
- .map((str) => str.trimEnd()))
17
- .join('\n');
17
+ function breakLines(content, width) {
18
+ return content
19
+ .split('\n')
20
+ .flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
21
+ .split('\n')
22
+ .map((str) => str.trimEnd()))
23
+ .join('\n');
24
+ }
18
25
  exports.breakLines = breakLines;
26
+ /**
27
+ * Returns the width of the active readline, or 80 as default value.
28
+ * @returns {number}
29
+ */
30
+ function readlineWidth() {
31
+ return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_mjs_1.readline)().output });
32
+ }
33
+ exports.readlineWidth = readlineWidth;
@@ -5,6 +5,6 @@ export { useEffect } from './lib/use-effect.js';
5
5
  export { useRef } from './lib/use-ref.js';
6
6
  export { useKeypress } from './lib/use-keypress.js';
7
7
  export { usePagination } from './lib/use-pagination.js';
8
- export { createPrompt, type AsyncPromptConfig } from './lib/create-prompt.js';
8
+ export { createPrompt, type PromptConfig, type AsyncPromptConfig, } from './lib/create-prompt.js';
9
9
  export { Separator } from './lib/Separator.js';
10
10
  export { type InquirerReadline } from './lib/read-line.type.js';
@@ -1,11 +1,11 @@
1
- import { type Prompt } from '@inquirer/type';
1
+ import { type Prompt, type Prettify } from '@inquirer/type';
2
2
  export type AsyncPromptConfig = {
3
3
  message: string | Promise<string> | (() => Promise<string>);
4
- validate?: (value: string) => boolean | string | Promise<string | boolean>;
5
4
  };
5
+ export type PromptConfig<Config> = Prettify<AsyncPromptConfig & Config>;
6
6
  type ResolvedPromptConfig = {
7
7
  message: string;
8
- validate: (value: string) => boolean | string | Promise<string | boolean>;
9
8
  };
10
- export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: (config: Config & ResolvedPromptConfig, done: (value: Value) => void) => string | [string, string | undefined]): Prompt<Value, Config>;
9
+ type ViewFunction<Value, Config> = (config: Prettify<Config & ResolvedPromptConfig>, done: (value: Value) => void) => string | [string, string | undefined];
10
+ export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
11
11
  export {};
@@ -5,4 +5,9 @@
5
5
  * @param {number} width
6
6
  * @return {string}
7
7
  */
8
- export declare const breakLines: (content: string, width: number) => string;
8
+ export declare function breakLines(content: string, width: number): string;
9
+ /**
10
+ * Returns the width of the active readline, or 80 as default value.
11
+ * @returns {number}
12
+ */
13
+ export declare function readlineWidth(): number;
@@ -5,5 +5,5 @@ export { useEffect } from './lib/use-effect.mjs';
5
5
  export { useRef } from './lib/use-ref.mjs';
6
6
  export { useKeypress } from './lib/use-keypress.mjs';
7
7
  export { usePagination } from './lib/use-pagination.mjs';
8
- export { createPrompt } from './lib/create-prompt.mjs';
8
+ export { createPrompt, } from './lib/create-prompt.mjs';
9
9
  export { Separator } from './lib/Separator.mjs';
@@ -8,7 +8,6 @@ import { withHooks, effectScheduler } from './hook-engine.mjs';
8
8
  async function getPromptConfig(config) {
9
9
  const message = typeof config.message === 'function' ? config.message() : config.message;
10
10
  return {
11
- validate: () => true,
12
11
  ...config,
13
12
  message: await message,
14
13
  };
@@ -85,7 +85,9 @@ export const effectScheduler = {
85
85
  store.hooksEffect.forEach((effect) => {
86
86
  effect();
87
87
  });
88
+ // Warning: Clean the hooks before exiting the `withUpdates` block.
89
+ // Failure to do so means an updates would hit the same effects again.
90
+ store.hooksEffect.length = 0;
88
91
  })();
89
- store.hooksEffect.length = 0;
90
92
  },
91
93
  };
@@ -1,7 +1,6 @@
1
- import cliWidth from 'cli-width';
2
1
  import stripAnsi from 'strip-ansi';
3
2
  import ansiEscapes from 'ansi-escapes';
4
- import { breakLines } from './utils.mjs';
3
+ import { breakLines, readlineWidth } from './utils.mjs';
5
4
  const height = (content) => content.split('\n').length;
6
5
  const lastLine = (content) => content.split('\n').pop() ?? '';
7
6
  export default class ScreenManager {
@@ -33,7 +32,7 @@ export default class ScreenManager {
33
32
  this.rl.setPrompt(prompt);
34
33
  // SetPrompt will change cursor position, now we can get correct value
35
34
  this.cursorPos = this.rl.getCursorPos();
36
- const width = cliWidth({ defaultWidth: 80, output: this.rl.output });
35
+ const width = readlineWidth();
37
36
  content = breakLines(content, width);
38
37
  bottomContent = breakLines(bottomContent, width);
39
38
  // Manually insert an extra line if we're at the end of the line.
@@ -1,15 +1,12 @@
1
1
  import chalk from 'chalk';
2
- import cliWidth from 'cli-width';
3
- import { breakLines } from './utils.mjs';
4
- import { readline } from './hook-engine.mjs';
2
+ import { breakLines, readlineWidth } from './utils.mjs';
5
3
  import { useRef } from './use-ref.mjs';
6
4
  export function usePagination(output, { active, pageSize = 7, }) {
7
- const rl = readline();
8
5
  const state = useRef({
9
6
  pointer: 0,
10
7
  lastIndex: 0,
11
8
  });
12
- const width = cliWidth({ defaultWidth: 80, output: rl.output });
9
+ const width = readlineWidth();
13
10
  const lines = breakLines(output, width).split('\n');
14
11
  // Make sure there's enough lines to paginate
15
12
  if (lines.length <= pageSize) {
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import * as spinners from 'cli-spinners';
2
+ import spinners from 'cli-spinners';
3
3
  import { useState } from './use-state.mjs';
4
4
  import { useEffect } from './use-effect.mjs';
5
5
  const spinner = spinners.dots;
@@ -1,4 +1,6 @@
1
+ import cliWidth from 'cli-width';
1
2
  import wrapAnsi from 'wrap-ansi';
3
+ import { readline } from './hook-engine.mjs';
2
4
  /**
3
5
  * Force line returns at specific width. This function is ANSI code friendly and it'll
4
6
  * ignore invisible codes during width calculation.
@@ -6,9 +8,18 @@ import wrapAnsi from 'wrap-ansi';
6
8
  * @param {number} width
7
9
  * @return {string}
8
10
  */
9
- export const breakLines = (content, width) => content
10
- .split('\n')
11
- .flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true })
12
- .split('\n')
13
- .map((str) => str.trimEnd()))
14
- .join('\n');
11
+ export function breakLines(content, width) {
12
+ return content
13
+ .split('\n')
14
+ .flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true })
15
+ .split('\n')
16
+ .map((str) => str.trimEnd()))
17
+ .join('\n');
18
+ }
19
+ /**
20
+ * Returns the width of the active readline, or 80 as default value.
21
+ * @returns {number}
22
+ */
23
+ export function readlineWidth() {
24
+ return cliWidth({ defaultWidth: 80, output: readline().output });
25
+ }
@@ -5,6 +5,6 @@ export { useEffect } from './lib/use-effect.mjs';
5
5
  export { useRef } from './lib/use-ref.mjs';
6
6
  export { useKeypress } from './lib/use-keypress.mjs';
7
7
  export { usePagination } from './lib/use-pagination.mjs';
8
- export { createPrompt, type AsyncPromptConfig } from './lib/create-prompt.mjs';
8
+ export { createPrompt, type PromptConfig, type AsyncPromptConfig, } from './lib/create-prompt.mjs';
9
9
  export { Separator } from './lib/Separator.mjs';
10
10
  export { type InquirerReadline } from './lib/read-line.type.mjs';
@@ -1,11 +1,11 @@
1
- import { type Prompt } from '@inquirer/type';
1
+ import { type Prompt, type Prettify } from '@inquirer/type';
2
2
  export type AsyncPromptConfig = {
3
3
  message: string | Promise<string> | (() => Promise<string>);
4
- validate?: (value: string) => boolean | string | Promise<string | boolean>;
5
4
  };
5
+ export type PromptConfig<Config> = Prettify<AsyncPromptConfig & Config>;
6
6
  type ResolvedPromptConfig = {
7
7
  message: string;
8
- validate: (value: string) => boolean | string | Promise<string | boolean>;
9
8
  };
10
- export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: (config: Config & ResolvedPromptConfig, done: (value: Value) => void) => string | [string, string | undefined]): Prompt<Value, Config>;
9
+ type ViewFunction<Value, Config> = (config: Prettify<Config & ResolvedPromptConfig>, done: (value: Value) => void) => string | [string, string | undefined];
10
+ export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
11
11
  export {};
@@ -5,4 +5,9 @@
5
5
  * @param {number} width
6
6
  * @return {string}
7
7
  */
8
- export declare const breakLines: (content: string, width: number) => string;
8
+ export declare function breakLines(content: string, width: number): string;
9
+ /**
10
+ * Returns the width of the active readline, or 80 as default value.
11
+ * @returns {number}
12
+ */
13
+ export declare function readlineWidth(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "4.1.0",
3
+ "version": "5.0.1",
4
4
  "engines": {
5
5
  "node": ">=14.18.0"
6
6
  },
@@ -57,13 +57,13 @@
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.1.3",
60
+ "@inquirer/type": "^1.1.5",
61
61
  "@types/mute-stream": "^0.0.1",
62
- "@types/node": "^20.6.0",
62
+ "@types/node": "^20.6.5",
63
63
  "@types/wrap-ansi": "^3.0.0",
64
64
  "ansi-escapes": "^4.3.2",
65
65
  "chalk": "^4.1.2",
66
- "cli-spinners": "^2.9.0",
66
+ "cli-spinners": "^2.9.1",
67
67
  "cli-width": "^4.1.0",
68
68
  "figures": "^3.2.0",
69
69
  "mute-stream": "^1.0.0",
@@ -73,7 +73,7 @@
73
73
  "wrap-ansi": "^6.2.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@inquirer/testing": "^2.1.5"
76
+ "@inquirer/testing": "^2.1.7"
77
77
  },
78
78
  "scripts": {
79
79
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -95,5 +95,5 @@
95
95
  }
96
96
  }
97
97
  },
98
- "gitHead": "f5c544a8ded1c7dfb6ac8364759955e8f2ecfb0c"
98
+ "gitHead": "85784061d702778bc9dd48ca08f09ee9976b06ee"
99
99
  }