@inquirer/core 10.3.2 → 11.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.
- package/README.md +4 -4
- package/dist/{esm/lib → lib}/Separator.js +2 -2
- package/dist/{esm/lib → lib}/create-prompt.js +1 -1
- package/dist/{commonjs/lib → lib}/theme.d.ts +16 -16
- package/dist/lib/theme.js +21 -0
- package/package.json +14 -37
- package/dist/commonjs/index.js +0 -46
- package/dist/commonjs/lib/Separator.js +0 -28
- package/dist/commonjs/lib/create-prompt.js +0 -156
- package/dist/commonjs/lib/errors.js +0 -29
- package/dist/commonjs/lib/hook-engine.js +0 -118
- package/dist/commonjs/lib/key.js +0 -29
- package/dist/commonjs/lib/make-theme.js +0 -33
- package/dist/commonjs/lib/pagination/use-pagination.js +0 -124
- package/dist/commonjs/lib/promise-polyfill.js +0 -18
- package/dist/commonjs/lib/screen-manager.js +0 -82
- package/dist/commonjs/lib/theme.js +0 -27
- package/dist/commonjs/lib/use-effect.js +0 -14
- package/dist/commonjs/lib/use-keypress.js +0 -23
- package/dist/commonjs/lib/use-memo.js +0 -17
- package/dist/commonjs/lib/use-prefix.js +0 -38
- package/dist/commonjs/lib/use-ref.js +0 -7
- package/dist/commonjs/lib/use-state.js +0 -23
- package/dist/commonjs/lib/utils.js +0 -32
- package/dist/commonjs/package.json +0 -3
- package/dist/esm/index.d.ts +0 -13
- package/dist/esm/lib/Separator.d.ts +0 -10
- package/dist/esm/lib/create-prompt.d.ts +0 -4
- package/dist/esm/lib/errors.d.ts +0 -20
- package/dist/esm/lib/hook-engine.d.ts +0 -23
- package/dist/esm/lib/key.d.ts +0 -12
- package/dist/esm/lib/make-theme.d.ts +0 -3
- package/dist/esm/lib/pagination/use-pagination.d.ts +0 -16
- package/dist/esm/lib/promise-polyfill.d.ts +0 -7
- package/dist/esm/lib/screen-manager.d.ts +0 -14
- package/dist/esm/lib/theme.d.ts +0 -155
- package/dist/esm/lib/theme.js +0 -21
- package/dist/esm/lib/use-effect.d.ts +0 -2
- package/dist/esm/lib/use-keypress.d.ts +0 -3
- package/dist/esm/lib/use-memo.d.ts +0 -1
- package/dist/esm/lib/use-prefix.d.ts +0 -5
- package/dist/esm/lib/use-ref.d.ts +0 -6
- package/dist/esm/lib/use-state.d.ts +0 -4
- package/dist/esm/lib/utils.d.ts +0 -13
- package/dist/esm/package.json +0 -3
- /package/dist/{commonjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{esm/index.js → index.js} +0 -0
- /package/dist/{commonjs/lib → lib}/Separator.d.ts +0 -0
- /package/dist/{commonjs/lib → lib}/create-prompt.d.ts +0 -0
- /package/dist/{commonjs/lib → lib}/errors.d.ts +0 -0
- /package/dist/{esm/lib → lib}/errors.js +0 -0
- /package/dist/{commonjs/lib → lib}/hook-engine.d.ts +0 -0
- /package/dist/{esm/lib → lib}/hook-engine.js +0 -0
- /package/dist/{commonjs/lib → lib}/key.d.ts +0 -0
- /package/dist/{esm/lib → lib}/key.js +0 -0
- /package/dist/{commonjs/lib → lib}/make-theme.d.ts +0 -0
- /package/dist/{esm/lib → lib}/make-theme.js +0 -0
- /package/dist/{commonjs/lib → lib}/pagination/use-pagination.d.ts +0 -0
- /package/dist/{esm/lib → lib}/pagination/use-pagination.js +0 -0
- /package/dist/{commonjs/lib → lib}/promise-polyfill.d.ts +0 -0
- /package/dist/{esm/lib → lib}/promise-polyfill.js +0 -0
- /package/dist/{commonjs/lib → lib}/screen-manager.d.ts +0 -0
- /package/dist/{esm/lib → lib}/screen-manager.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-effect.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-effect.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-keypress.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-keypress.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-memo.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-memo.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-prefix.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-prefix.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-ref.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-ref.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-state.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-state.js +0 -0
- /package/dist/{commonjs/lib → lib}/utils.d.ts +0 -0
- /package/dist/{esm/lib → lib}/utils.js +0 -0
package/README.md
CHANGED
|
@@ -331,7 +331,7 @@ You can refer to any `@inquirer/prompts` prompts for real examples:
|
|
|
331
331
|
- [Expand Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/expand/src/index.ts)
|
|
332
332
|
|
|
333
333
|
```ts
|
|
334
|
-
import
|
|
334
|
+
import { styleText } from 'node:util';
|
|
335
335
|
import {
|
|
336
336
|
createPrompt,
|
|
337
337
|
useState,
|
|
@@ -361,12 +361,12 @@ const confirm = createPrompt<boolean, { message: string; default?: boolean }>(
|
|
|
361
361
|
let formattedValue = value;
|
|
362
362
|
let defaultValue = '';
|
|
363
363
|
if (status === 'done') {
|
|
364
|
-
formattedValue =
|
|
364
|
+
formattedValue = styleText('cyan', value);
|
|
365
365
|
} else {
|
|
366
|
-
defaultValue =
|
|
366
|
+
defaultValue = styleText('dim', config.default === false ? ' (y/N)' : ' (Y/n)');
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
const message =
|
|
369
|
+
const message = styleText('bold', config.message);
|
|
370
370
|
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
371
371
|
},
|
|
372
372
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
2
|
import figures from '@inquirer/figures';
|
|
3
3
|
/**
|
|
4
4
|
* Separator object
|
|
5
5
|
* Used to space/separate choices group
|
|
6
6
|
*/
|
|
7
7
|
export class Separator {
|
|
8
|
-
separator =
|
|
8
|
+
separator = styleText('dim', Array.from({ length: 15 }).join(figures.line));
|
|
9
9
|
type = 'separator';
|
|
10
10
|
constructor(separator) {
|
|
11
11
|
if (separator) {
|
|
@@ -16,7 +16,7 @@ function getCallSites() {
|
|
|
16
16
|
result = callSitesWithoutCurrent;
|
|
17
17
|
return callSitesWithoutCurrent;
|
|
18
18
|
};
|
|
19
|
-
//
|
|
19
|
+
// oxlint-disable-next-line no-unused-expressions
|
|
20
20
|
new Error().stack;
|
|
21
21
|
}
|
|
22
22
|
catch {
|
|
@@ -21,8 +21,8 @@ type DefaultTheme = {
|
|
|
21
21
|
*
|
|
22
22
|
* @defaultValue
|
|
23
23
|
* ```ts
|
|
24
|
-
* // import
|
|
25
|
-
* (status) => status === 'done' ?
|
|
24
|
+
* // import { styleText } from 'node:util';
|
|
25
|
+
* (status) => status === 'done' ? styleText('green', '✔') : styleText('blue', '?')
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
prefix: string | Prettify<Omit<Record<Status, string>, 'loading'>>;
|
|
@@ -64,8 +64,8 @@ type DefaultTheme = {
|
|
|
64
64
|
*
|
|
65
65
|
* @defaultValue
|
|
66
66
|
* ```ts
|
|
67
|
-
* // import
|
|
68
|
-
* (text) =>
|
|
67
|
+
* // import { styleText } from 'node:util';
|
|
68
|
+
* (text) => styleText('cyan', text)
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
answer: (text: string) => string;
|
|
@@ -78,8 +78,8 @@ type DefaultTheme = {
|
|
|
78
78
|
*
|
|
79
79
|
* @defaultValue
|
|
80
80
|
* ```ts
|
|
81
|
-
* // import
|
|
82
|
-
* (text, status) =>
|
|
81
|
+
* // import { styleText } from 'node:util';
|
|
82
|
+
* (text, status) => styleText('bold', text)
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
85
|
message: (text: string, status: Status) => string;
|
|
@@ -91,8 +91,8 @@ type DefaultTheme = {
|
|
|
91
91
|
*
|
|
92
92
|
* @defaultValue
|
|
93
93
|
* ```ts
|
|
94
|
-
* // import
|
|
95
|
-
* (text) =>
|
|
94
|
+
* // import { styleText } from 'node:util';
|
|
95
|
+
* (text) => styleText('red', `> ${text}`)
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
error: (text: string) => string;
|
|
@@ -104,8 +104,8 @@ type DefaultTheme = {
|
|
|
104
104
|
*
|
|
105
105
|
* @defaultValue
|
|
106
106
|
* ```ts
|
|
107
|
-
* // import
|
|
108
|
-
* (text) =>
|
|
107
|
+
* // import { styleText } from 'node:util';
|
|
108
|
+
* (text) => styleText('dim', `(${text})`)
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
defaultAnswer: (text: string) => string;
|
|
@@ -117,8 +117,8 @@ type DefaultTheme = {
|
|
|
117
117
|
*
|
|
118
118
|
* @defaultValue
|
|
119
119
|
* ```ts
|
|
120
|
-
* // import
|
|
121
|
-
* (text) =>
|
|
120
|
+
* // import { styleText } from 'node:util';
|
|
121
|
+
* (text) => styleText('dim', text)
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
124
124
|
help: (text: string) => string;
|
|
@@ -130,8 +130,8 @@ type DefaultTheme = {
|
|
|
130
130
|
*
|
|
131
131
|
* @defaultValue
|
|
132
132
|
* ```ts
|
|
133
|
-
* // import
|
|
134
|
-
* (text) =>
|
|
133
|
+
* // import { styleText } from 'node:util';
|
|
134
|
+
* (text) => styleText('cyan', text)
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
137
|
highlight: (text: string) => string;
|
|
@@ -143,8 +143,8 @@ type DefaultTheme = {
|
|
|
143
143
|
*
|
|
144
144
|
* @defaultValue
|
|
145
145
|
* ```ts
|
|
146
|
-
* // import
|
|
147
|
-
* (text) =>
|
|
146
|
+
* // import { styleText } from 'node:util';
|
|
147
|
+
* (text) => styleText('cyan', styleText('bold', `<${text}>`))
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
key: (text: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import figures from '@inquirer/figures';
|
|
3
|
+
export const defaultTheme = {
|
|
4
|
+
prefix: {
|
|
5
|
+
idle: styleText('blue', '?'),
|
|
6
|
+
done: styleText('green', figures.tick),
|
|
7
|
+
},
|
|
8
|
+
spinner: {
|
|
9
|
+
interval: 80,
|
|
10
|
+
frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map((frame) => styleText('yellow', frame)),
|
|
11
|
+
},
|
|
12
|
+
style: {
|
|
13
|
+
answer: (text) => styleText('cyan', text),
|
|
14
|
+
message: (text) => styleText('bold', text),
|
|
15
|
+
error: (text) => styleText('red', `> ${text}`),
|
|
16
|
+
defaultAnswer: (text) => styleText('dim', `(${text})`),
|
|
17
|
+
help: (text) => styleText('dim', text),
|
|
18
|
+
highlight: (text) => styleText('cyan', text),
|
|
19
|
+
key: (text) => styleText('cyan', styleText('bold', `<${text}>`)),
|
|
20
|
+
},
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -53,44 +53,30 @@
|
|
|
53
53
|
"exports": {
|
|
54
54
|
"./package.json": "./package.json",
|
|
55
55
|
".": {
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"default": "./dist/esm/index.js"
|
|
59
|
-
},
|
|
60
|
-
"require": {
|
|
61
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
62
|
-
"default": "./dist/commonjs/index.js"
|
|
63
|
-
}
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"default": "./dist/index.js"
|
|
64
58
|
}
|
|
65
59
|
},
|
|
66
|
-
"main": "./dist/commonjs/index.js",
|
|
67
|
-
"module": "./dist/esm/index.js",
|
|
68
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
69
60
|
"files": [
|
|
70
61
|
"dist"
|
|
71
62
|
],
|
|
72
63
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"tsc": "tshy"
|
|
64
|
+
"tsc": "tsc"
|
|
75
65
|
},
|
|
76
66
|
"dependencies": {
|
|
77
|
-
"@inquirer/ansi": "^
|
|
78
|
-
"@inquirer/figures": "^
|
|
79
|
-
"@inquirer/type": "^
|
|
67
|
+
"@inquirer/ansi": "^2.0.1",
|
|
68
|
+
"@inquirer/figures": "^2.0.1",
|
|
69
|
+
"@inquirer/type": "^4.0.1",
|
|
80
70
|
"cli-width": "^4.1.0",
|
|
81
|
-
"mute-stream": "^
|
|
71
|
+
"mute-stream": "^3.0.0",
|
|
82
72
|
"signal-exit": "^4.1.0",
|
|
83
|
-
"wrap-ansi": "^
|
|
84
|
-
"yoctocolors-cjs": "^2.1.3"
|
|
73
|
+
"wrap-ansi": "^9.0.2"
|
|
85
74
|
},
|
|
86
75
|
"devDependencies": {
|
|
87
|
-
"@
|
|
88
|
-
"@inquirer/testing": "^2.1.53",
|
|
89
|
-
"@repo/tsconfig": "0.0.0",
|
|
76
|
+
"@inquirer/testing": "^3.0.1",
|
|
90
77
|
"@types/mute-stream": "^0.0.4",
|
|
91
|
-
"@types/node": "^24.10.
|
|
92
|
-
"
|
|
93
|
-
"tshy": "^3.0.3"
|
|
78
|
+
"@types/node": "^24.10.1",
|
|
79
|
+
"typescript": "^5.9.3"
|
|
94
80
|
},
|
|
95
81
|
"peerDependencies": {
|
|
96
82
|
"@types/node": ">=18"
|
|
@@ -101,19 +87,10 @@
|
|
|
101
87
|
}
|
|
102
88
|
},
|
|
103
89
|
"engines": {
|
|
104
|
-
"node": ">=
|
|
90
|
+
"node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
|
|
105
91
|
},
|
|
106
92
|
"publishConfig": {
|
|
107
93
|
"access": "public"
|
|
108
94
|
},
|
|
109
|
-
"
|
|
110
|
-
"exclude": [
|
|
111
|
-
"src/**/*.test.ts"
|
|
112
|
-
],
|
|
113
|
-
"exports": {
|
|
114
|
-
"./package.json": "./package.json",
|
|
115
|
-
".": "./src/index.ts"
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
"gitHead": "4731a373881368e2f701c41adc67bc83244bf89f"
|
|
95
|
+
"gitHead": "cce79ce3b9bbdfb4dbb798078cf3b94b9adc7d1b"
|
|
119
96
|
}
|
package/dist/commonjs/index.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = exports.isEnterKey = exports.isNumberKey = exports.isTabKey = exports.isBackspaceKey = exports.isSpaceKey = exports.isDownKey = exports.isUpKey = void 0;
|
|
18
|
-
var key_ts_1 = require("./lib/key.js");
|
|
19
|
-
Object.defineProperty(exports, "isUpKey", { enumerable: true, get: function () { return key_ts_1.isUpKey; } });
|
|
20
|
-
Object.defineProperty(exports, "isDownKey", { enumerable: true, get: function () { return key_ts_1.isDownKey; } });
|
|
21
|
-
Object.defineProperty(exports, "isSpaceKey", { enumerable: true, get: function () { return key_ts_1.isSpaceKey; } });
|
|
22
|
-
Object.defineProperty(exports, "isBackspaceKey", { enumerable: true, get: function () { return key_ts_1.isBackspaceKey; } });
|
|
23
|
-
Object.defineProperty(exports, "isTabKey", { enumerable: true, get: function () { return key_ts_1.isTabKey; } });
|
|
24
|
-
Object.defineProperty(exports, "isNumberKey", { enumerable: true, get: function () { return key_ts_1.isNumberKey; } });
|
|
25
|
-
Object.defineProperty(exports, "isEnterKey", { enumerable: true, get: function () { return key_ts_1.isEnterKey; } });
|
|
26
|
-
__exportStar(require("./lib/errors.js"), exports);
|
|
27
|
-
var use_prefix_ts_1 = require("./lib/use-prefix.js");
|
|
28
|
-
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_ts_1.usePrefix; } });
|
|
29
|
-
var use_state_ts_1 = require("./lib/use-state.js");
|
|
30
|
-
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return use_state_ts_1.useState; } });
|
|
31
|
-
var use_effect_ts_1 = require("./lib/use-effect.js");
|
|
32
|
-
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_ts_1.useEffect; } });
|
|
33
|
-
var use_memo_ts_1 = require("./lib/use-memo.js");
|
|
34
|
-
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_ts_1.useMemo; } });
|
|
35
|
-
var use_ref_ts_1 = require("./lib/use-ref.js");
|
|
36
|
-
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_ts_1.useRef; } });
|
|
37
|
-
var use_keypress_ts_1 = require("./lib/use-keypress.js");
|
|
38
|
-
Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_ts_1.useKeypress; } });
|
|
39
|
-
var make_theme_ts_1 = require("./lib/make-theme.js");
|
|
40
|
-
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_ts_1.makeTheme; } });
|
|
41
|
-
var use_pagination_ts_1 = require("./lib/pagination/use-pagination.js");
|
|
42
|
-
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_ts_1.usePagination; } });
|
|
43
|
-
var create_prompt_ts_1 = require("./lib/create-prompt.js");
|
|
44
|
-
Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return create_prompt_ts_1.createPrompt; } });
|
|
45
|
-
var Separator_ts_1 = require("./lib/Separator.js");
|
|
46
|
-
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return Separator_ts_1.Separator; } });
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Separator = void 0;
|
|
7
|
-
const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
|
|
8
|
-
const figures_1 = __importDefault(require("@inquirer/figures"));
|
|
9
|
-
/**
|
|
10
|
-
* Separator object
|
|
11
|
-
* Used to space/separate choices group
|
|
12
|
-
*/
|
|
13
|
-
class Separator {
|
|
14
|
-
separator = yoctocolors_cjs_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line));
|
|
15
|
-
type = 'separator';
|
|
16
|
-
constructor(separator) {
|
|
17
|
-
if (separator) {
|
|
18
|
-
this.separator = separator;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
static isSeparator(choice) {
|
|
22
|
-
return Boolean(choice &&
|
|
23
|
-
typeof choice === 'object' &&
|
|
24
|
-
'type' in choice &&
|
|
25
|
-
choice.type === 'separator');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.Separator = Separator;
|
|
@@ -1,156 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.createPrompt = createPrompt;
|
|
40
|
-
const readline = __importStar(require("node:readline"));
|
|
41
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
42
|
-
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
43
|
-
const signal_exit_1 = require("signal-exit");
|
|
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
|
-
function getCallSites() {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
50
|
-
const _prepareStackTrace = Error.prepareStackTrace;
|
|
51
|
-
let result = [];
|
|
52
|
-
try {
|
|
53
|
-
Error.prepareStackTrace = (_, callSites) => {
|
|
54
|
-
const callSitesWithoutCurrent = callSites.slice(1);
|
|
55
|
-
result = callSitesWithoutCurrent;
|
|
56
|
-
return callSitesWithoutCurrent;
|
|
57
|
-
};
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
59
|
-
new Error().stack;
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
// An error will occur if the Node flag --frozen-intrinsics is used.
|
|
63
|
-
// https://nodejs.org/api/cli.html#--frozen-intrinsics
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
Error.prepareStackTrace = _prepareStackTrace;
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
function createPrompt(view) {
|
|
70
|
-
const callSites = getCallSites();
|
|
71
|
-
const prompt = (config, context = {}) => {
|
|
72
|
-
// Default `input` to stdin
|
|
73
|
-
const { input = process.stdin, signal } = context;
|
|
74
|
-
const cleanups = new Set();
|
|
75
|
-
// Add mute capabilities to the output
|
|
76
|
-
const output = new mute_stream_1.default();
|
|
77
|
-
output.pipe(context.output ?? process.stdout);
|
|
78
|
-
const rl = readline.createInterface({
|
|
79
|
-
terminal: true,
|
|
80
|
-
input,
|
|
81
|
-
output,
|
|
82
|
-
});
|
|
83
|
-
const screen = new screen_manager_ts_1.default(rl);
|
|
84
|
-
const { promise, resolve, reject } = promise_polyfill_ts_1.PromisePolyfill.withResolver();
|
|
85
|
-
const cancel = () => reject(new errors_ts_1.CancelPromptError());
|
|
86
|
-
if (signal) {
|
|
87
|
-
const abort = () => reject(new errors_ts_1.AbortPromptError({ cause: signal.reason }));
|
|
88
|
-
if (signal.aborted) {
|
|
89
|
-
abort();
|
|
90
|
-
return Object.assign(promise, { cancel });
|
|
91
|
-
}
|
|
92
|
-
signal.addEventListener('abort', abort);
|
|
93
|
-
cleanups.add(() => signal.removeEventListener('abort', abort));
|
|
94
|
-
}
|
|
95
|
-
cleanups.add((0, signal_exit_1.onExit)((code, signal) => {
|
|
96
|
-
reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
97
|
-
}));
|
|
98
|
-
// SIGINT must be explicitly handled by the prompt so the ExitPromptError can be handled.
|
|
99
|
-
// Otherwise, the prompt will stop and in some scenarios never resolve.
|
|
100
|
-
// Ref issue #1741
|
|
101
|
-
const sigint = () => reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
102
|
-
rl.on('SIGINT', sigint);
|
|
103
|
-
cleanups.add(() => rl.removeListener('SIGINT', sigint));
|
|
104
|
-
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
105
|
-
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
106
|
-
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
107
|
-
// by a state change sets the cursor to the right position.
|
|
108
|
-
const checkCursorPos = () => screen.checkCursorPos();
|
|
109
|
-
rl.input.on('keypress', checkCursorPos);
|
|
110
|
-
cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
|
|
111
|
-
return (0, hook_engine_ts_1.withHooks)(rl, (cycle) => {
|
|
112
|
-
// The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
|
|
113
|
-
// triggers after the process is done (which happens after timeouts are done triggering.)
|
|
114
|
-
// We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
|
|
115
|
-
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => hook_engine_ts_1.effectScheduler.clearAll());
|
|
116
|
-
rl.on('close', hooksCleanup);
|
|
117
|
-
cleanups.add(() => rl.removeListener('close', hooksCleanup));
|
|
118
|
-
cycle(() => {
|
|
119
|
-
try {
|
|
120
|
-
const nextView = view(config, (value) => {
|
|
121
|
-
setImmediate(() => resolve(value));
|
|
122
|
-
});
|
|
123
|
-
// Typescript won't allow this, but not all users rely on typescript.
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
125
|
-
if (nextView === undefined) {
|
|
126
|
-
const callerFilename = callSites[1]?.getFileName();
|
|
127
|
-
throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
|
|
128
|
-
}
|
|
129
|
-
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
130
|
-
screen.render(content, bottomContent);
|
|
131
|
-
hook_engine_ts_1.effectScheduler.run();
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
reject(error);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
return Object.assign(promise
|
|
138
|
-
.then((answer) => {
|
|
139
|
-
hook_engine_ts_1.effectScheduler.clearAll();
|
|
140
|
-
return answer;
|
|
141
|
-
}, (error) => {
|
|
142
|
-
hook_engine_ts_1.effectScheduler.clearAll();
|
|
143
|
-
throw error;
|
|
144
|
-
})
|
|
145
|
-
// Wait for the promise to settle, then cleanup.
|
|
146
|
-
.finally(() => {
|
|
147
|
-
cleanups.forEach((cleanup) => cleanup());
|
|
148
|
-
screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
|
|
149
|
-
output.end();
|
|
150
|
-
})
|
|
151
|
-
// Once cleanup is done, let the expose promise resolve/reject to the internal one.
|
|
152
|
-
.then(() => promise), { cancel });
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return prompt;
|
|
156
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.HookError = exports.ExitPromptError = exports.CancelPromptError = exports.AbortPromptError = void 0;
|
|
4
|
-
class AbortPromptError extends Error {
|
|
5
|
-
name = 'AbortPromptError';
|
|
6
|
-
message = 'Prompt was aborted';
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super();
|
|
9
|
-
this.cause = options?.cause;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.AbortPromptError = AbortPromptError;
|
|
13
|
-
class CancelPromptError extends Error {
|
|
14
|
-
name = 'CancelPromptError';
|
|
15
|
-
message = 'Prompt was canceled';
|
|
16
|
-
}
|
|
17
|
-
exports.CancelPromptError = CancelPromptError;
|
|
18
|
-
class ExitPromptError extends Error {
|
|
19
|
-
name = 'ExitPromptError';
|
|
20
|
-
}
|
|
21
|
-
exports.ExitPromptError = ExitPromptError;
|
|
22
|
-
class HookError extends Error {
|
|
23
|
-
name = 'HookError';
|
|
24
|
-
}
|
|
25
|
-
exports.HookError = HookError;
|
|
26
|
-
class ValidationError extends Error {
|
|
27
|
-
name = 'ValidationError';
|
|
28
|
-
}
|
|
29
|
-
exports.ValidationError = ValidationError;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint @typescript-eslint/no-explicit-any: ["off"] */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.effectScheduler = void 0;
|
|
5
|
-
exports.withHooks = withHooks;
|
|
6
|
-
exports.readline = readline;
|
|
7
|
-
exports.withUpdates = withUpdates;
|
|
8
|
-
exports.withPointer = withPointer;
|
|
9
|
-
exports.handleChange = handleChange;
|
|
10
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
11
|
-
const errors_ts_1 = require("./errors.js");
|
|
12
|
-
const hookStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
13
|
-
function createStore(rl) {
|
|
14
|
-
const store = {
|
|
15
|
-
rl,
|
|
16
|
-
hooks: [],
|
|
17
|
-
hooksCleanup: [],
|
|
18
|
-
hooksEffect: [],
|
|
19
|
-
index: 0,
|
|
20
|
-
handleChange() { },
|
|
21
|
-
};
|
|
22
|
-
return store;
|
|
23
|
-
}
|
|
24
|
-
// Run callback in with the hook engine setup.
|
|
25
|
-
function withHooks(rl, cb) {
|
|
26
|
-
const store = createStore(rl);
|
|
27
|
-
return hookStorage.run(store, () => {
|
|
28
|
-
function cycle(render) {
|
|
29
|
-
store.handleChange = () => {
|
|
30
|
-
store.index = 0;
|
|
31
|
-
render();
|
|
32
|
-
};
|
|
33
|
-
store.handleChange();
|
|
34
|
-
}
|
|
35
|
-
return cb(cycle);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
// Safe getStore utility that'll return the store or throw if undefined.
|
|
39
|
-
function getStore() {
|
|
40
|
-
const store = hookStorage.getStore();
|
|
41
|
-
if (!store) {
|
|
42
|
-
throw new errors_ts_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
|
|
43
|
-
}
|
|
44
|
-
return store;
|
|
45
|
-
}
|
|
46
|
-
function readline() {
|
|
47
|
-
return getStore().rl;
|
|
48
|
-
}
|
|
49
|
-
// Merge state updates happening within the callback function to avoid multiple renders.
|
|
50
|
-
function withUpdates(fn) {
|
|
51
|
-
const wrapped = (...args) => {
|
|
52
|
-
const store = getStore();
|
|
53
|
-
let shouldUpdate = false;
|
|
54
|
-
const oldHandleChange = store.handleChange;
|
|
55
|
-
store.handleChange = () => {
|
|
56
|
-
shouldUpdate = true;
|
|
57
|
-
};
|
|
58
|
-
const returnValue = fn(...args);
|
|
59
|
-
if (shouldUpdate) {
|
|
60
|
-
oldHandleChange();
|
|
61
|
-
}
|
|
62
|
-
store.handleChange = oldHandleChange;
|
|
63
|
-
return returnValue;
|
|
64
|
-
};
|
|
65
|
-
return node_async_hooks_1.AsyncResource.bind(wrapped);
|
|
66
|
-
}
|
|
67
|
-
function withPointer(cb) {
|
|
68
|
-
const store = getStore();
|
|
69
|
-
const { index } = store;
|
|
70
|
-
const pointer = {
|
|
71
|
-
get() {
|
|
72
|
-
return store.hooks[index];
|
|
73
|
-
},
|
|
74
|
-
set(value) {
|
|
75
|
-
store.hooks[index] = value;
|
|
76
|
-
},
|
|
77
|
-
initialized: index in store.hooks,
|
|
78
|
-
};
|
|
79
|
-
const returnValue = cb(pointer);
|
|
80
|
-
store.index++;
|
|
81
|
-
return returnValue;
|
|
82
|
-
}
|
|
83
|
-
function handleChange() {
|
|
84
|
-
getStore().handleChange();
|
|
85
|
-
}
|
|
86
|
-
exports.effectScheduler = {
|
|
87
|
-
queue(cb) {
|
|
88
|
-
const store = getStore();
|
|
89
|
-
const { index } = store;
|
|
90
|
-
store.hooksEffect.push(() => {
|
|
91
|
-
store.hooksCleanup[index]?.();
|
|
92
|
-
const cleanFn = cb(readline());
|
|
93
|
-
if (cleanFn != null && typeof cleanFn !== 'function') {
|
|
94
|
-
throw new errors_ts_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
|
|
95
|
-
}
|
|
96
|
-
store.hooksCleanup[index] = cleanFn;
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
run() {
|
|
100
|
-
const store = getStore();
|
|
101
|
-
withUpdates(() => {
|
|
102
|
-
store.hooksEffect.forEach((effect) => {
|
|
103
|
-
effect();
|
|
104
|
-
});
|
|
105
|
-
// Warning: Clean the hooks before exiting the `withUpdates` block.
|
|
106
|
-
// Failure to do so means an updates would hit the same effects again.
|
|
107
|
-
store.hooksEffect.length = 0;
|
|
108
|
-
})();
|
|
109
|
-
},
|
|
110
|
-
clearAll() {
|
|
111
|
-
const store = getStore();
|
|
112
|
-
store.hooksCleanup.forEach((cleanFn) => {
|
|
113
|
-
cleanFn?.();
|
|
114
|
-
});
|
|
115
|
-
store.hooksEffect.length = 0;
|
|
116
|
-
store.hooksCleanup.length = 0;
|
|
117
|
-
},
|
|
118
|
-
};
|
package/dist/commonjs/lib/key.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEnterKey = exports.isNumberKey = exports.isTabKey = exports.isBackspaceKey = exports.isSpaceKey = exports.isDownKey = exports.isUpKey = void 0;
|
|
4
|
-
const isUpKey = (key, keybindings = []) =>
|
|
5
|
-
// The up key
|
|
6
|
-
key.name === 'up' ||
|
|
7
|
-
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
8
|
-
(keybindings.includes('vim') && key.name === 'k') ||
|
|
9
|
-
// Emacs keybinding: Ctrl+P means "previous" in Emacs navigation conventions
|
|
10
|
-
(keybindings.includes('emacs') && key.ctrl && key.name === 'p');
|
|
11
|
-
exports.isUpKey = isUpKey;
|
|
12
|
-
const isDownKey = (key, keybindings = []) =>
|
|
13
|
-
// The down key
|
|
14
|
-
key.name === 'down' ||
|
|
15
|
-
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
16
|
-
(keybindings.includes('vim') && key.name === 'j') ||
|
|
17
|
-
// Emacs keybinding: Ctrl+N means "next" in Emacs navigation conventions
|
|
18
|
-
(keybindings.includes('emacs') && key.ctrl && key.name === 'n');
|
|
19
|
-
exports.isDownKey = isDownKey;
|
|
20
|
-
const isSpaceKey = (key) => key.name === 'space';
|
|
21
|
-
exports.isSpaceKey = isSpaceKey;
|
|
22
|
-
const isBackspaceKey = (key) => key.name === 'backspace';
|
|
23
|
-
exports.isBackspaceKey = isBackspaceKey;
|
|
24
|
-
const isTabKey = (key) => key.name === 'tab';
|
|
25
|
-
exports.isTabKey = isTabKey;
|
|
26
|
-
const isNumberKey = (key) => '1234567890'.includes(key.name);
|
|
27
|
-
exports.isNumberKey = isNumberKey;
|
|
28
|
-
const isEnterKey = (key) => key.name === 'enter' || key.name === 'return';
|
|
29
|
-
exports.isEnterKey = isEnterKey;
|