@oclif/core 3.18.2 → 3.19.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/lib/config/config.d.ts +1 -1
- package/lib/config/config.js +14 -5
- package/lib/help/command.js +3 -3
- package/lib/interfaces/pjson.d.ts +6 -5
- package/lib/parser/parse.d.ts +14 -0
- package/lib/parser/parse.js +14 -8
- package/package.json +7 -7
package/lib/config/config.d.ts
CHANGED
package/lib/config/config.js
CHANGED
|
@@ -360,12 +360,21 @@ class Config {
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
async loadThemes() {
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
363
|
+
const defaultThemeFile = this.pjson.oclif.theme
|
|
364
|
+
? (0, node_path_1.resolve)(this.root, this.pjson.oclif.theme)
|
|
365
|
+
: this.pjson.oclif.theme;
|
|
366
|
+
const userThemeFile = (0, node_path_1.resolve)(this.configDir, 'theme.json');
|
|
367
|
+
const [defaultTheme, userTheme] = await Promise.all([
|
|
368
|
+
defaultThemeFile ? await (0, fs_1.safeReadJson)(defaultThemeFile) : undefined,
|
|
369
|
+
await (0, fs_1.safeReadJson)(userThemeFile),
|
|
370
|
+
]);
|
|
371
|
+
// Merge the default theme with the user theme, giving the user theme precedence.
|
|
372
|
+
const merged = { ...defaultTheme, ...userTheme };
|
|
366
373
|
return {
|
|
367
|
-
file,
|
|
368
|
-
|
|
374
|
+
// Point to the user file if it exists, otherwise use the default file.
|
|
375
|
+
// This doesn't really serve a purpose to anyone but removing it would be a breaking change.
|
|
376
|
+
file: userTheme ? userThemeFile : defaultThemeFile,
|
|
377
|
+
theme: Object.keys(merged).length > 0 ? (0, theme_1.parseTheme)(merged) : undefined,
|
|
369
378
|
};
|
|
370
379
|
}
|
|
371
380
|
macosCacheDir() {
|
package/lib/help/command.js
CHANGED
|
@@ -150,7 +150,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
150
150
|
labels.push(`--${flag.name.trim()}`);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
label = labels.join((0, theme_1.colorize)(this.config?.theme?.flagSeparator,
|
|
153
|
+
label = labels.join(flag.char ? (0, theme_1.colorize)(this.config?.theme?.flagSeparator, ', ') : ' ');
|
|
154
154
|
}
|
|
155
155
|
if (flag.type === 'option') {
|
|
156
156
|
let value = flag.helpValue || (this.opts.showFlagNameInTitle ? flag.name : '<value>');
|
|
@@ -163,14 +163,14 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
163
163
|
value = chalk_1.default.underline(value);
|
|
164
164
|
label += `=${value}`;
|
|
165
165
|
}
|
|
166
|
-
return label;
|
|
166
|
+
return (0, theme_1.colorize)(this.config.theme?.flag, label);
|
|
167
167
|
}
|
|
168
168
|
flags(flags) {
|
|
169
169
|
if (flags.length === 0)
|
|
170
170
|
return;
|
|
171
171
|
const noChar = flags.reduce((previous, current) => previous && current.char === undefined, true);
|
|
172
172
|
return flags.map((flag) => {
|
|
173
|
-
let left =
|
|
173
|
+
let left = this.flagHelpLabel(flag);
|
|
174
174
|
if (noChar)
|
|
175
175
|
left = left.replace(' ', '');
|
|
176
176
|
let right = flag.summary || flag.description || '';
|
|
@@ -49,15 +49,11 @@ export declare namespace PJSON {
|
|
|
49
49
|
identifier?: string;
|
|
50
50
|
sign?: string;
|
|
51
51
|
};
|
|
52
|
-
windows?: {
|
|
53
|
-
homepage?: string;
|
|
54
|
-
keypath?: string;
|
|
55
|
-
name?: string;
|
|
56
|
-
};
|
|
57
52
|
plugins?: string[];
|
|
58
53
|
repositoryPrefix?: string;
|
|
59
54
|
schema?: number;
|
|
60
55
|
state?: 'beta' | 'deprecated' | string;
|
|
56
|
+
theme?: string;
|
|
61
57
|
topicSeparator?: ' ' | ':';
|
|
62
58
|
topics?: {
|
|
63
59
|
[k: string]: {
|
|
@@ -78,6 +74,11 @@ export declare namespace PJSON {
|
|
|
78
74
|
};
|
|
79
75
|
s3: S3;
|
|
80
76
|
};
|
|
77
|
+
windows?: {
|
|
78
|
+
homepage?: string;
|
|
79
|
+
keypath?: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
};
|
|
81
82
|
};
|
|
82
83
|
version: string;
|
|
83
84
|
}
|
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.
|
|
4
|
+
"version": "3.19.1",
|
|
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.
|
|
41
|
+
"@oclif/test": "^3.1.12",
|
|
42
42
|
"@types/ansi-styles": "^3.2.1",
|
|
43
43
|
"@types/benchmark": "^2.1.5",
|
|
44
44
|
"@types/chai": "^4.3.11",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@types/js-yaml": "^3.12.7",
|
|
52
52
|
"@types/mocha": "^10.0.6",
|
|
53
53
|
"@types/node": "^18",
|
|
54
|
-
"@types/node-notifier": "^8.0.
|
|
54
|
+
"@types/node-notifier": "^8.0.5",
|
|
55
55
|
"@types/pnpapi": "^0.0.5",
|
|
56
56
|
"@types/slice-ansi": "^4.0.0",
|
|
57
57
|
"@types/strip-ansi": "^5.2.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"chai-as-promised": "^7.1.1",
|
|
64
64
|
"commitlint": "^17.7.2",
|
|
65
65
|
"cross-env": "^7.0.3",
|
|
66
|
-
"eslint": "^8.
|
|
66
|
+
"eslint": "^8.56.0",
|
|
67
67
|
"eslint-config-oclif": "^5.0.0",
|
|
68
68
|
"eslint-config-oclif-typescript": "^3.0.35",
|
|
69
69
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"madge": "^6.1.0",
|
|
75
75
|
"mocha": "^10.2.0",
|
|
76
76
|
"nyc": "^15.1.0",
|
|
77
|
-
"prettier": "^3.
|
|
77
|
+
"prettier": "^3.2.4",
|
|
78
78
|
"shx": "^0.3.4",
|
|
79
79
|
"sinon": "^16.1.3",
|
|
80
|
-
"ts-node": "^10.9.
|
|
81
|
-
"tsd": "^0.
|
|
80
|
+
"ts-node": "^10.9.2",
|
|
81
|
+
"tsd": "^0.30.4",
|
|
82
82
|
"typescript": "^5"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|