@oclif/core 3.19.0 → 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.
@@ -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;
@@ -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(), 100);
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
- // if the value ends up being one of the command's flags, the user didn't provide an input
111
- if (typeof input !== 'string' || this.findFlag(input).name) {
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.0",
4
+ "version": "3.19.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -74,7 +74,7 @@
74
74
  "madge": "^6.1.0",
75
75
  "mocha": "^10.2.0",
76
76
  "nyc": "^15.1.0",
77
- "prettier": "^3.1.1",
77
+ "prettier": "^3.2.4",
78
78
  "shx": "^0.3.4",
79
79
  "sinon": "^16.1.3",
80
80
  "ts-node": "^10.9.2",