@inquirer/core 3.1.2 → 4.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 +17 -265
- package/dist/cjs/lib/Separator.js +2 -5
- package/dist/cjs/lib/create-prompt.js +111 -0
- package/dist/cjs/lib/hook-engine.js +100 -0
- package/dist/cjs/lib/read-line.type.js +2 -0
- package/dist/cjs/lib/screen-manager.js +3 -6
- package/dist/cjs/lib/use-effect.js +15 -0
- package/dist/cjs/lib/use-keypress.js +20 -0
- package/dist/cjs/lib/use-pagination.js +34 -0
- package/dist/cjs/lib/{prefix.js → use-prefix.js} +7 -9
- package/dist/cjs/lib/use-ref.js +8 -0
- package/dist/cjs/lib/use-state.js +28 -0
- package/dist/cjs/lib/utils.js +2 -5
- package/dist/cjs/types/index.d.ts +9 -36
- package/dist/cjs/types/lib/create-prompt.d.ts +11 -0
- package/dist/cjs/types/lib/hook-engine.d.ts +24 -0
- package/dist/cjs/types/lib/key.d.ts +1 -2
- package/dist/cjs/types/lib/read-line.type.d.ts +9 -0
- package/dist/cjs/types/lib/screen-manager.d.ts +1 -1
- package/dist/cjs/types/lib/use-effect.d.ts +2 -0
- package/dist/cjs/types/lib/use-keypress.d.ts +3 -0
- package/dist/cjs/types/lib/use-pagination.d.ts +4 -0
- package/dist/cjs/types/lib/use-ref.d.ts +3 -0
- package/dist/cjs/types/lib/use-state.d.ts +3 -0
- package/dist/esm/index.mjs +8 -241
- package/dist/esm/lib/create-prompt.mjs +99 -0
- package/dist/esm/lib/hook-engine.mjs +91 -0
- package/dist/esm/lib/read-line.type.mjs +1 -0
- package/dist/esm/lib/use-effect.mjs +11 -0
- package/dist/esm/lib/use-keypress.mjs +16 -0
- package/dist/esm/lib/use-pagination.mjs +30 -0
- package/dist/esm/lib/{prefix.mjs → use-prefix.mjs} +3 -2
- package/dist/esm/lib/use-ref.mjs +4 -0
- package/dist/esm/lib/use-state.mjs +24 -0
- package/dist/esm/lib/utils.mjs +1 -1
- package/dist/esm/types/index.d.mts +9 -36
- package/dist/esm/types/lib/create-prompt.d.mts +11 -0
- package/dist/esm/types/lib/hook-engine.d.mts +24 -0
- package/dist/esm/types/lib/key.d.mts +1 -2
- package/dist/esm/types/lib/read-line.type.d.mts +9 -0
- package/dist/esm/types/lib/screen-manager.d.mts +1 -1
- package/dist/esm/types/lib/use-effect.d.mts +2 -0
- package/dist/esm/types/lib/use-keypress.d.mts +3 -0
- package/dist/esm/types/lib/use-pagination.d.mts +4 -0
- package/dist/esm/types/lib/use-ref.d.mts +3 -0
- package/dist/esm/types/lib/use-state.d.mts +3 -0
- package/package.json +9 -9
- package/dist/cjs/lib/options.js +0 -19
- package/dist/cjs/types/lib/options.d.ts +0 -2
- package/dist/esm/lib/options.mjs +0 -8
- package/dist/esm/types/lib/options.d.mts +0 -2
- /package/dist/cjs/types/lib/{prefix.d.ts → use-prefix.d.ts} +0 -0
- /package/dist/esm/types/lib/{prefix.d.mts → use-prefix.d.mts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import spinners from 'cli-spinners';
|
|
3
|
-
import { useState
|
|
2
|
+
import * as spinners from 'cli-spinners';
|
|
3
|
+
import { useState } from './use-state.mjs';
|
|
4
|
+
import { useEffect } from './use-effect.mjs';
|
|
4
5
|
const spinner = spinners.dots;
|
|
5
6
|
export function usePrefix(isLoading = false) {
|
|
6
7
|
const [tick, setTick] = useState(0);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { withPointer, handleChange } from './hook-engine.mjs';
|
|
2
|
+
export function useState(defaultValue) {
|
|
3
|
+
return withPointer((pointer) => {
|
|
4
|
+
if (!pointer.initialized) {
|
|
5
|
+
if (typeof defaultValue === 'function') {
|
|
6
|
+
pointer.set(defaultValue());
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
pointer.set(defaultValue);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [
|
|
13
|
+
pointer.get(),
|
|
14
|
+
(newValue) => {
|
|
15
|
+
// Noop if the value is still the same.
|
|
16
|
+
if (pointer.get() !== newValue) {
|
|
17
|
+
pointer.set(newValue);
|
|
18
|
+
// Trigger re-render
|
|
19
|
+
handleChange();
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
});
|
|
24
|
+
}
|
package/dist/esm/lib/utils.mjs
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import * as readline from 'node:readline';
|
|
4
|
-
import { type Prompt } from '@inquirer/type';
|
|
5
|
-
import MuteStream from 'mute-stream';
|
|
6
|
-
export { usePrefix } from './lib/prefix.mjs';
|
|
7
1
|
export * from './lib/key.mjs';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
type NotFunction<T> = T extends Function ? never : T;
|
|
19
|
-
export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
|
|
20
|
-
export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: unknown[]): void;
|
|
21
|
-
export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void): void;
|
|
22
|
-
export declare function useRef<Value>(val: Value): {
|
|
23
|
-
current: Value;
|
|
24
|
-
};
|
|
25
|
-
export declare function usePagination(output: string, { active, pageSize, }: {
|
|
26
|
-
active: number;
|
|
27
|
-
pageSize?: number;
|
|
28
|
-
}): string;
|
|
29
|
-
export type AsyncPromptConfig = {
|
|
30
|
-
message: string | Promise<string> | (() => Promise<string>);
|
|
31
|
-
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
32
|
-
};
|
|
33
|
-
export type ResolvedPromptConfig = {
|
|
34
|
-
message: string;
|
|
35
|
-
validate: (value: string) => boolean | string | Promise<string | boolean>;
|
|
36
|
-
};
|
|
37
|
-
export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: (config: Config & ResolvedPromptConfig, done: (value: Value) => void) => string | [string, string | undefined]): Prompt<Value, Config>;
|
|
2
|
+
export { usePrefix } from './lib/use-prefix.mjs';
|
|
3
|
+
export { useState } from './lib/use-state.mjs';
|
|
4
|
+
export { useEffect } from './lib/use-effect.mjs';
|
|
5
|
+
export { useRef } from './lib/use-ref.mjs';
|
|
6
|
+
export { useKeypress } from './lib/use-keypress.mjs';
|
|
7
|
+
export { usePagination } from './lib/use-pagination.mjs';
|
|
8
|
+
export { createPrompt, type AsyncPromptConfig } from './lib/create-prompt.mjs';
|
|
9
|
+
export { Separator } from './lib/Separator.mjs';
|
|
10
|
+
export { type InquirerReadline } from './lib/read-line.type.mjs';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Prompt } from '@inquirer/type';
|
|
2
|
+
export type AsyncPromptConfig = {
|
|
3
|
+
message: string | Promise<string> | (() => Promise<string>);
|
|
4
|
+
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
5
|
+
};
|
|
6
|
+
type ResolvedPromptConfig = {
|
|
7
|
+
message: string;
|
|
8
|
+
validate: (value: string) => boolean | string | Promise<string | boolean>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: (config: Config & ResolvedPromptConfig, done: (value: Value) => void) => string | [string, string | undefined]): Prompt<Value, Config>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InquirerReadline } from './read-line.type.mjs';
|
|
2
|
+
type HookStore = {
|
|
3
|
+
rl: InquirerReadline;
|
|
4
|
+
hooks: any[];
|
|
5
|
+
hooksCleanup: Array<void | (() => void)>;
|
|
6
|
+
hooksEffect: Array<() => void>;
|
|
7
|
+
index: number;
|
|
8
|
+
handleChange: () => void;
|
|
9
|
+
};
|
|
10
|
+
type Pointer = {
|
|
11
|
+
get(): any;
|
|
12
|
+
set(value: any): void;
|
|
13
|
+
initialized: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function withHooks(rl: InquirerReadline, cb: (store: HookStore) => void): void;
|
|
16
|
+
export declare function readline(): InquirerReadline;
|
|
17
|
+
export declare function withUpdates<T extends (...args: any) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
18
|
+
export declare function withPointer<Value>(cb: (pointer: Pointer) => Value): Value;
|
|
19
|
+
export declare function handleChange(): void;
|
|
20
|
+
export declare const effectScheduler: {
|
|
21
|
+
queue(cb: (readline: InquirerReadline) => void): void;
|
|
22
|
+
run(): void;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type KeypressEvent = {
|
|
1
|
+
export type KeypressEvent = {
|
|
2
2
|
name: string;
|
|
3
3
|
ctrl: boolean;
|
|
4
4
|
};
|
|
@@ -8,4 +8,3 @@ export declare const isSpaceKey: (key: KeypressEvent) => boolean;
|
|
|
8
8
|
export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
|
|
9
9
|
export declare const isNumberKey: (key: KeypressEvent) => boolean;
|
|
10
10
|
export declare const isEnterKey: (key: KeypressEvent) => boolean;
|
|
11
|
-
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import * as readline from 'node:readline';
|
|
4
|
+
import MuteStream from 'mute-stream';
|
|
5
|
+
export type InquirerReadline = readline.ReadLine & {
|
|
6
|
+
output: MuteStream;
|
|
7
|
+
input: NodeJS.ReadableStream;
|
|
8
|
+
clearLine: (dir: 0 | 1 | -1) => void;
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14.18.0"
|
|
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.1.
|
|
60
|
+
"@inquirer/type": "^1.1.3",
|
|
61
61
|
"@types/mute-stream": "^0.0.1",
|
|
62
|
-
"@types/node": "^20.
|
|
62
|
+
"@types/node": "^20.6.0",
|
|
63
63
|
"@types/wrap-ansi": "^3.0.0",
|
|
64
64
|
"ansi-escapes": "^4.3.2",
|
|
65
65
|
"chalk": "^4.1.2",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"figures": "^3.2.0",
|
|
69
69
|
"mute-stream": "^1.0.0",
|
|
70
70
|
"run-async": "^3.0.0",
|
|
71
|
+
"signal-exit": "^4.1.0",
|
|
71
72
|
"strip-ansi": "^6.0.1",
|
|
72
73
|
"wrap-ansi": "^6.2.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@inquirer/testing": "^2.1.
|
|
76
|
+
"@inquirer/testing": "^2.1.5"
|
|
76
77
|
},
|
|
77
78
|
"scripts": {
|
|
78
|
-
"tsc": "yarn run
|
|
79
|
-
"
|
|
80
|
-
"tsc:
|
|
81
|
-
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs"
|
|
79
|
+
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
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"
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"access": "public"
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "f5c544a8ded1c7dfb6ac8364759955e8f2ecfb0c"
|
|
99
99
|
}
|
package/dist/cjs/lib/options.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPromptConfig = void 0;
|
|
13
|
-
function getPromptConfig(option) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const message = typeof option.message === 'function' ? option.message() : option.message;
|
|
16
|
-
return Object.assign(Object.assign({ validate: () => true }, option), { message: yield message });
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
exports.getPromptConfig = getPromptConfig;
|
package/dist/esm/lib/options.mjs
DELETED
|
File without changes
|
|
File without changes
|