@oclif/core 1.9.10 → 1.12.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/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.12.0](https://github.com/oclif/core/compare/v1.11.0...v1.12.0) (2022-07-20)
6
+
7
+
8
+ ### Features
9
+
10
+ * improve the instantiation of global flags ([#445](https://github.com/oclif/core/issues/445)) ([d264535](https://github.com/oclif/core/commit/d2645358ccf1cddd0bb65d236e73ecf4c5ac7c0c))
11
+
12
+ ## [1.11.0](https://github.com/oclif/core/compare/v1.10.0...v1.11.0) (2022-07-18)
13
+
14
+
15
+ ### Features
16
+
17
+ * print error info when module not found ([#427](https://github.com/oclif/core/issues/427)) ([223e79b](https://github.com/oclif/core/commit/223e79b363ad01da327e264244daf23810849d70))
18
+
19
+ ## [1.10.0](https://github.com/oclif/core/compare/v1.9.10...v1.10.0) (2022-07-15)
20
+
21
+
22
+ ### Features
23
+
24
+ * add stderr method ([#441](https://github.com/oclif/core/issues/441)) ([d9490f7](https://github.com/oclif/core/commit/d9490f77ff4cac0ee9767f1386f18c7357e0666e))
25
+
5
26
  ### [1.9.10](https://github.com/oclif/core/compare/v1.9.9...v1.9.10) (2022-07-15)
6
27
 
7
28
  ### [1.9.9](https://github.com/oclif/core/compare/v1.9.8...v1.9.9) (2022-07-14)
package/lib/command.d.ts CHANGED
@@ -55,7 +55,9 @@ export default abstract class Command {
55
55
  */
56
56
  static examples: Interfaces.Example[];
57
57
  static parserOptions: {};
58
- static enableJsonFlag: boolean;
58
+ static _enableJsonFlag: boolean;
59
+ static get enableJsonFlag(): boolean;
60
+ static set enableJsonFlag(value: boolean);
59
61
  /**
60
62
  * instantiate and run the command
61
63
  * @param {Interfaces.Command.Class} this Class
@@ -86,6 +88,7 @@ export default abstract class Command {
86
88
  exit?: number;
87
89
  } & PrettyPrintableError): never;
88
90
  log(message?: string, ...args: any[]): void;
91
+ logToStderr(message?: string, ...args: any[]): void;
89
92
  jsonEnabled(): boolean;
90
93
  /**
91
94
  * actual command run code goes here
package/lib/command.js CHANGED
@@ -39,19 +39,25 @@ class Command {
39
39
  this.debug = () => { };
40
40
  }
41
41
  }
42
+ static get enableJsonFlag() {
43
+ return this._enableJsonFlag;
44
+ }
45
+ static set enableJsonFlag(value) {
46
+ this._enableJsonFlag = value;
47
+ if (value)
48
+ this.globalFlags = jsonFlag;
49
+ }
42
50
  static get globalFlags() {
43
51
  return this._globalFlags;
44
52
  }
45
53
  static set globalFlags(flags) {
46
- this._globalFlags = this.enableJsonFlag ?
47
- Object.assign({}, jsonFlag, this.globalFlags, flags) :
48
- Object.assign({}, this.globalFlags, flags);
54
+ this._globalFlags = Object.assign({}, this.globalFlags, flags);
55
+ this.flags = this.globalFlags;
49
56
  }
50
57
  static get flags() {
51
58
  return this._flags;
52
59
  }
53
60
  static set flags(flags) {
54
- this.globalFlags = {};
55
61
  this._flags = Object.assign({}, this.globalFlags, flags);
56
62
  }
57
63
  get ctor() {
@@ -91,11 +97,16 @@ class Command {
91
97
  }
92
98
  log(message = '', ...args) {
93
99
  if (!this.jsonEnabled()) {
94
- // tslint:disable-next-line strict-type-predicates
95
100
  message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
96
101
  process.stdout.write((0, util_1.format)(message, ...args) + '\n');
97
102
  }
98
103
  }
104
+ logToStderr(message = '', ...args) {
105
+ if (!this.jsonEnabled()) {
106
+ message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
107
+ process.stderr.write((0, util_1.format)(message, ...args) + '\n');
108
+ }
109
+ }
99
110
  jsonEnabled() {
100
111
  return this.ctor.enableJsonFlag && this.argv.includes('--json');
101
112
  }
@@ -118,7 +129,7 @@ class Command {
118
129
  options = this.constructor;
119
130
  const opts = { context: this, ...options };
120
131
  // the spread operator doesn't work with getters so we have to manually add it here
121
- opts.flags = options === null || options === void 0 ? void 0 : options.flags;
132
+ opts.flags = Object.assign({}, options === null || options === void 0 ? void 0 : options.flags, options === null || options === void 0 ? void 0 : options.globalFlags);
122
133
  return Parser.parse(argv, opts);
123
134
  }
124
135
  async catch(err) {
@@ -164,7 +175,7 @@ Command.aliases = [];
164
175
  Command.strict = true;
165
176
  Command.parse = true;
166
177
  Command.parserOptions = {};
167
- Command.enableJsonFlag = false;
178
+ Command._enableJsonFlag = false;
168
179
  // eslint-disable-next-line valid-jsdoc
169
180
  /**
170
181
  * instantiate and run the command
@@ -160,6 +160,7 @@ export declare type EnumFlagOptions<T> = Partial<OptionFlag<T>> & {
160
160
  export declare type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
161
161
  export declare type Input<TFlags extends FlagOutput> = {
162
162
  flags?: FlagInput<TFlags>;
163
+ globalFlags?: FlagInput<TFlags>;
163
164
  args?: ArgInput;
164
165
  strict?: boolean;
165
166
  context?: any;
@@ -82,7 +82,7 @@ class ModuleLoader {
82
82
  }
83
83
  catch (error) {
84
84
  if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
85
- throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
85
+ throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
86
86
  }
87
87
  throw error;
88
88
  }
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": "1.9.10",
4
+ "version": "1.12.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {