@oclif/core 3.19.0 → 3.19.2
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/lib/cli-ux/prompt.js +16 -16
- package/lib/execute.d.ts +4 -10
- package/lib/execute.js +4 -10
- package/lib/parser/parse.d.ts +14 -0
- package/lib/parser/parse.js +14 -8
- package/package.json +4 -4
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -28,28 +28,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.anykey = exports.confirm = exports.prompt = void 0;
|
|
30
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
31
32
|
const Errors = __importStar(require("../errors"));
|
|
32
33
|
const config_1 = require("./config");
|
|
33
34
|
function normal(options, retries = 100) {
|
|
34
35
|
if (retries < 0)
|
|
35
36
|
throw new Error('no input');
|
|
37
|
+
const ac = new AbortController();
|
|
38
|
+
const { signal } = ac;
|
|
36
39
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
process.stdin.setEncoding('utf8');
|
|
46
|
-
process.stderr.write(options.prompt);
|
|
47
|
-
process.stdin.resume();
|
|
48
|
-
process.stdin.once('data', (b) => {
|
|
49
|
-
if (timer)
|
|
50
|
-
clearTimeout(timer);
|
|
51
|
-
process.stdin.pause();
|
|
52
|
-
const data = (typeof b === 'string' ? b : b.toString()).trim();
|
|
40
|
+
const rl = node_readline_1.default.createInterface({
|
|
41
|
+
input: process.stdin,
|
|
42
|
+
output: process.stdout,
|
|
43
|
+
});
|
|
44
|
+
rl.question(options.prompt, { signal }, (answer) => {
|
|
45
|
+
rl.close();
|
|
46
|
+
const data = answer.trim();
|
|
53
47
|
if (!options.default && options.required && data === '') {
|
|
54
48
|
resolve(normal(options, retries - 1));
|
|
55
49
|
}
|
|
@@ -57,6 +51,12 @@ function normal(options, retries = 100) {
|
|
|
57
51
|
resolve(data || options.default);
|
|
58
52
|
}
|
|
59
53
|
});
|
|
54
|
+
if (options.timeout) {
|
|
55
|
+
signal.addEventListener('abort', () => {
|
|
56
|
+
reject(new Error('Prompt timeout'));
|
|
57
|
+
}, { once: true });
|
|
58
|
+
setTimeout(() => ac.abort(), options.timeout);
|
|
59
|
+
}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
function getPrompt(name, type, defaultValue) {
|
package/lib/execute.d.ts
CHANGED
|
@@ -8,23 +8,17 @@ import { LoadOptions } from './interfaces';
|
|
|
8
8
|
* @example For ESM dev.js
|
|
9
9
|
* ```
|
|
10
10
|
* #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
|
|
11
|
-
*
|
|
12
|
-
* const oclif = await import('@oclif/core')
|
|
13
|
-
* await oclif.execute({development: true, dir: import.meta.url})
|
|
14
|
-
* }
|
|
11
|
+
* import { execute } from '@oclif/core'
|
|
15
12
|
*
|
|
16
|
-
* await
|
|
13
|
+
* await execute({development: true, dir: import.meta.url})
|
|
17
14
|
* ```
|
|
18
15
|
*
|
|
19
16
|
* @example For ESM run.js
|
|
20
17
|
* ```
|
|
21
18
|
* #!/usr/bin/env node
|
|
22
|
-
*
|
|
23
|
-
* const oclif = await import('@oclif/core')
|
|
24
|
-
* await oclif.execute({dir: import.meta.url})
|
|
25
|
-
* }
|
|
19
|
+
* import { execute } from '@oclif/core'
|
|
26
20
|
*
|
|
27
|
-
* await
|
|
21
|
+
* await execute({dir: import.meta.url})
|
|
28
22
|
* ```
|
|
29
23
|
*
|
|
30
24
|
* @example For CJS dev.js
|
package/lib/execute.js
CHANGED
|
@@ -14,23 +14,17 @@ const settings_1 = require("./settings");
|
|
|
14
14
|
* @example For ESM dev.js
|
|
15
15
|
* ```
|
|
16
16
|
* #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
|
|
17
|
-
*
|
|
18
|
-
* const oclif = await import('@oclif/core')
|
|
19
|
-
* await oclif.execute({development: true, dir: import.meta.url})
|
|
20
|
-
* }
|
|
17
|
+
* import { execute } from '@oclif/core'
|
|
21
18
|
*
|
|
22
|
-
* await
|
|
19
|
+
* await execute({development: true, dir: import.meta.url})
|
|
23
20
|
* ```
|
|
24
21
|
*
|
|
25
22
|
* @example For ESM run.js
|
|
26
23
|
* ```
|
|
27
24
|
* #!/usr/bin/env node
|
|
28
|
-
*
|
|
29
|
-
* const oclif = await import('@oclif/core')
|
|
30
|
-
* await oclif.execute({dir: import.meta.url})
|
|
31
|
-
* }
|
|
25
|
+
* import { execute } from '@oclif/core'
|
|
32
26
|
*
|
|
33
|
-
* await
|
|
27
|
+
* await execute({dir: import.meta.url})
|
|
34
28
|
* ```
|
|
35
29
|
*
|
|
36
30
|
* @example For CJS dev.js
|
package/lib/parser/parse.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { OutputArgs, OutputFlags, ParserInput, ParserOutput } from '../interfaces/parser';
|
|
2
|
+
declare global {
|
|
3
|
+
/**
|
|
4
|
+
* Cache the stdin so that it can be read multiple times.
|
|
5
|
+
*
|
|
6
|
+
* This fixes a bug where the stdin would be read multiple times (because Parser.parse() was called more than once)
|
|
7
|
+
* but only the first read would be successful - all other reads would return null.
|
|
8
|
+
*
|
|
9
|
+
* Storing in global is necessary because we want the cache to be shared across all versions of @oclif/core in
|
|
10
|
+
* in the dependency tree. Storing in a variable would only share the cache within the same version of @oclif/core.
|
|
11
|
+
*/
|
|
12
|
+
var oclif: {
|
|
13
|
+
stdinCache?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
2
16
|
export declare const readStdin: () => Promise<null | string>;
|
|
3
17
|
export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']>, BFlags extends OutputFlags<T['flags']>, TArgs extends OutputArgs<T['args']>> {
|
|
4
18
|
private readonly input;
|
package/lib/parser/parse.js
CHANGED
|
@@ -32,11 +32,15 @@ const readStdin = async () => {
|
|
|
32
32
|
// Because of this, we have to set a timeout to prevent the process from hanging.
|
|
33
33
|
if (stdin.isTTY)
|
|
34
34
|
return null;
|
|
35
|
+
if (global.oclif?.stdinCache) {
|
|
36
|
+
debug('resolved stdin from global cache', global.oclif.stdinCache);
|
|
37
|
+
return global.oclif.stdinCache;
|
|
38
|
+
}
|
|
35
39
|
return new Promise((resolve) => {
|
|
36
40
|
let result = '';
|
|
37
41
|
const ac = new AbortController();
|
|
38
42
|
const { signal } = ac;
|
|
39
|
-
const timeout = setTimeout(() => ac.abort(),
|
|
43
|
+
const timeout = setTimeout(() => ac.abort(), 10);
|
|
40
44
|
const rl = (0, node_readline_1.createInterface)({
|
|
41
45
|
input: stdin,
|
|
42
46
|
output: stdout,
|
|
@@ -48,6 +52,7 @@ const readStdin = async () => {
|
|
|
48
52
|
rl.once('close', () => {
|
|
49
53
|
clearTimeout(timeout);
|
|
50
54
|
debug('resolved from stdin', result);
|
|
55
|
+
global.oclif = { ...global.oclif, stdinCache: result };
|
|
51
56
|
resolve(result);
|
|
52
57
|
});
|
|
53
58
|
signal.addEventListener('abort', () => {
|
|
@@ -85,6 +90,7 @@ class Parser {
|
|
|
85
90
|
}
|
|
86
91
|
async parse() {
|
|
87
92
|
this._debugInput();
|
|
93
|
+
// eslint-disable-next-line complexity
|
|
88
94
|
const parseFlag = async (arg) => {
|
|
89
95
|
const { isLong, name } = this.findFlag(arg);
|
|
90
96
|
if (!name) {
|
|
@@ -107,19 +113,19 @@ class Parser {
|
|
|
107
113
|
}
|
|
108
114
|
this.currentFlag = flag;
|
|
109
115
|
let input = isLong || arg.length < 3 ? this.argv.shift() : arg.slice(arg[2] === '=' ? 3 : 2);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
throw new errors_1.CLIError(`Flag --${name} expects a value`);
|
|
113
|
-
}
|
|
114
|
-
if (flag.allowStdin === 'only' && input !== '-') {
|
|
115
|
-
throw new errors_1.CLIError(`Flag --${name} can only be read from stdin. The value must be "-".`);
|
|
116
|
+
if (flag.allowStdin === 'only' && input !== '-' && input !== undefined) {
|
|
117
|
+
throw new errors_1.CLIError(`Flag --${name} can only be read from stdin. The value must be "-" or not provided at all.`);
|
|
116
118
|
}
|
|
117
|
-
if (flag.allowStdin && input === '-') {
|
|
119
|
+
if ((flag.allowStdin && input === '-') || flag.allowStdin === 'only') {
|
|
118
120
|
const stdin = await (0, exports.readStdin)();
|
|
119
121
|
if (stdin) {
|
|
120
122
|
input = stdin.trim();
|
|
121
123
|
}
|
|
122
124
|
}
|
|
125
|
+
// if the value ends up being one of the command's flags, the user didn't provide an input
|
|
126
|
+
if (typeof input !== 'string' || this.findFlag(input).name) {
|
|
127
|
+
throw new errors_1.CLIError(`Flag --${name} expects a value`);
|
|
128
|
+
}
|
|
123
129
|
this.raw.push({ flag: flag.name, input, type: 'flag' });
|
|
124
130
|
}
|
|
125
131
|
else {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "3.19.
|
|
4
|
+
"version": "3.19.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@oclif/plugin-help": "^6",
|
|
39
39
|
"@oclif/plugin-plugins": "^4",
|
|
40
40
|
"@oclif/prettier-config": "^0.2.1",
|
|
41
|
-
"@oclif/test": "^3.1.
|
|
41
|
+
"@oclif/test": "^3.1.14",
|
|
42
42
|
"@types/ansi-styles": "^3.2.1",
|
|
43
43
|
"@types/benchmark": "^2.1.5",
|
|
44
44
|
"@types/chai": "^4.3.11",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"husky": "^8",
|
|
73
73
|
"lint-staged": "^14.0.1",
|
|
74
74
|
"madge": "^6.1.0",
|
|
75
|
-
"mocha": "^10.
|
|
75
|
+
"mocha": "^10.3.0",
|
|
76
76
|
"nyc": "^15.1.0",
|
|
77
|
-
"prettier": "^3.
|
|
77
|
+
"prettier": "^3.2.5",
|
|
78
78
|
"shx": "^0.3.4",
|
|
79
79
|
"sinon": "^16.1.3",
|
|
80
80
|
"ts-node": "^10.9.2",
|