@salesforce/sf-plugins-core 1.15.2 → 1.16.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/exported.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Flags as OclifFlags } from '@oclif/core';
3
3
  export { toHelpSection, parseVarArgs } from './util';
4
4
  export { Deployable, Deployer, DeployerResult } from './deployer';
5
5
  export { Deauthorizer } from './deauthorizer';
6
- export { Progress, Prompter, generateTableChoices } from './ux';
6
+ export { Progress, Prompter, generateTableChoices, Ux } from './ux';
7
7
  export { SfHook } from './hooks';
8
8
  export * from './types';
9
9
  export { SfCommand, SfCommandInterface, StandardColors } from './sfCommand';
package/lib/exported.js CHANGED
@@ -20,7 +20,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.Flags = exports.StandardColors = exports.SfCommand = exports.SfHook = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.parseVarArgs = exports.toHelpSection = void 0;
23
+ exports.Flags = exports.StandardColors = exports.SfCommand = exports.SfHook = exports.Ux = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.parseVarArgs = exports.toHelpSection = void 0;
24
24
  const core_1 = require("@oclif/core");
25
25
  var util_1 = require("./util");
26
26
  Object.defineProperty(exports, "toHelpSection", { enumerable: true, get: function () { return util_1.toHelpSection; } });
@@ -34,6 +34,7 @@ var ux_1 = require("./ux");
34
34
  Object.defineProperty(exports, "Progress", { enumerable: true, get: function () { return ux_1.Progress; } });
35
35
  Object.defineProperty(exports, "Prompter", { enumerable: true, get: function () { return ux_1.Prompter; } });
36
36
  Object.defineProperty(exports, "generateTableChoices", { enumerable: true, get: function () { return ux_1.generateTableChoices; } });
37
+ Object.defineProperty(exports, "Ux", { enumerable: true, get: function () { return ux_1.Ux; } });
37
38
  var hooks_1 = require("./hooks");
38
39
  Object.defineProperty(exports, "SfHook", { enumerable: true, get: function () { return hooks_1.SfHook; } });
39
40
  __exportStar(require("./types"), exports);
@@ -1,5 +1,5 @@
1
1
  import { CliUx, Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
- import { SfProject, StructuredMessage, SfError } from '@salesforce/core';
2
+ import { SfProject, StructuredMessage, SfError, ConfigAggregator } from '@salesforce/core';
3
3
  import { AnyJson } from '@salesforce/ts-types';
4
4
  import * as chalk from 'chalk';
5
5
  import { Progress, Prompter, Spinner, Ux } from './ux';
@@ -129,6 +129,33 @@ export declare abstract class SfCommand<T> extends Command {
129
129
  */
130
130
  progress: Progress;
131
131
  project: SfProject;
132
+ /**
133
+ * ConfigAggregator instance for accessing global and local configuration.
134
+ *
135
+ * NOTE: If the active executable is sfdx, this will be an instance of SfdxConfigAggregator, which supports
136
+ * the deprecated sfdx config vars like defaultusername, defaultdevhubusername, apiversion, etc. Otherwise,
137
+ * it will be an instance of ConfigAggregator will only supports the config vars introduce by @salesforce/core@v3.
138
+ *
139
+ * The executable is determined by `this.config.bin` which is supplied by the base oclif/core Command class. The value
140
+ * of `this.config.bin` will be the executable running (e.g. sfdx or sf) or, for local development (e.g. using bin/dev),
141
+ * it will be the value of oclif.bin in the plugin's package.json.
142
+ *
143
+ * If you need to write NUTS for a plugin that needs to work with both sets of config vars you can
144
+ * use set the `SF_USE_DEPRECATED_CONFIG_VARS` to `true` to force configAggregator to be an instance of SfdxConfigAggregator or
145
+ * `false` to force configAggregator to be an instance of ConfigAggregator.
146
+ *
147
+ * @example
148
+ * ```
149
+ * import { execCmd } from '@salesforce/cli-plugins-testkit';
150
+ * execCmd('config:set defaultusername=test@example.com', {
151
+ * env: {
152
+ * ...process.env,
153
+ * SF_USE_DEPRECATED_CONFIG_VARS: true,
154
+ * }
155
+ * })
156
+ * ```
157
+ */
158
+ configAggregator: ConfigAggregator;
132
159
  private warnings;
133
160
  private ux;
134
161
  private prompter;
package/lib/sfCommand.js CHANGED
@@ -10,6 +10,7 @@ exports.SfCommand = exports.StandardColors = void 0;
10
10
  const os = require("os");
11
11
  const core_1 = require("@oclif/core");
12
12
  const core_2 = require("@salesforce/core");
13
+ const kit_1 = require("@salesforce/kit");
13
14
  const chalk = require("chalk");
14
15
  const ux_1 = require("./ux");
15
16
  core_2.Messages.importMessagesDirectory(__dirname);
@@ -56,10 +57,10 @@ class SfCommand extends core_1.Command {
56
57
  super(argv, config);
57
58
  this.warnings = [];
58
59
  const outputEnabled = !this.jsonEnabled();
59
- this.spinner = new ux_1.Spinner(outputEnabled);
60
60
  this.progress = new ux_1.Progress(outputEnabled && core_2.envVars.getBoolean(core_2.EnvironmentVariable.SF_USE_PROGRESS_BAR, true));
61
61
  this.ux = new ux_1.Ux(outputEnabled);
62
- this.prompter = new ux_1.Prompter();
62
+ this.spinner = this.ux.spinner;
63
+ this.prompter = this.ux.prompter;
63
64
  this.lifecycle = core_2.Lifecycle.getInstance();
64
65
  }
65
66
  get statics() {
@@ -187,6 +188,12 @@ class SfCommand extends core_1.Command {
187
188
  return this.prompter.timedPrompt(questions, ms, initialAnswers);
188
189
  }
189
190
  async _run() {
191
+ this.configAggregator =
192
+ this.config.bin === 'sfdx' ??
193
+ kit_1.env.getBoolean('SF_USE_DEPRECATED_CONFIG_VARS') ??
194
+ kit_1.env.getBoolean('SFDX_USE_DEPRECATED_CONFIG_VARS')
195
+ ? await core_2.SfdxConfigAggregator.create()
196
+ : await core_2.ConfigAggregator.create();
190
197
  if (this.statics.requiresProject) {
191
198
  this.project = await this.assignProject();
192
199
  }
package/lib/ux/base.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AnyFunction } from '@salesforce/ts-types';
2
2
  export declare class UxBase {
3
- protected outputEnabled: boolean;
3
+ readonly outputEnabled: boolean;
4
4
  constructor(outputEnabled: boolean);
5
5
  protected maybeNoop(fn: AnyFunction<unknown>): void;
6
6
  }
package/lib/ux/ux.d.ts CHANGED
@@ -1,12 +1,76 @@
1
1
  import { CliUx } from '@oclif/core';
2
2
  import { AnyJson } from '@salesforce/ts-types';
3
3
  import { UxBase } from './base';
4
+ import { Prompter } from './prompter';
5
+ import { Spinner } from './spinner';
6
+ /**
7
+ * UX methods for plugins. Automatically suppress console output if outputEnabled is set to false.
8
+ *
9
+ * @example
10
+ * ```
11
+ * import { SfCommand, Ux } from '@salesforce/sf-plugins-core';
12
+ * import { AnyJson } from '@salesforce/ts-types';
13
+ *
14
+ * class MyCommand extends SfCommand<AnyJson> {
15
+ * public async run(): Promise<AnyJson> {
16
+ * const ux = new Ux(!this.jsonEnabled());
17
+ * }
18
+ * }
19
+ *
20
+ * ```
21
+ */
4
22
  export declare class Ux extends UxBase {
23
+ readonly outputEnabled: boolean;
24
+ spinner: Spinner;
25
+ prompter: Prompter;
5
26
  constructor(outputEnabled: boolean);
27
+ /**
28
+ * Log a message to the console. This will be automatically suppressed if output is disabled.
29
+ *
30
+ * @param message Message to log. Formatting is supported.
31
+ * @param args Args to be used for formatting.
32
+ */
33
+ log(message?: string, ...args: string[]): void;
34
+ /**
35
+ * Log a warning message to the console. This will be automatically suppressed if output is disabled.
36
+ *
37
+ * @param message Warning message to log.
38
+ */
39
+ warn(message: string | Error): void;
40
+ /**
41
+ * Display a table to the console. This will be automatically suppressed if output is disabled.
42
+ *
43
+ * @param data Data to be displayed
44
+ * @param columns Columns to display the data in
45
+ * @param options Options for how the table should be displayed
46
+ */
6
47
  table<T extends Ux.Table.Data>(data: T[], columns: Ux.Table.Columns<T>, options?: Ux.Table.Options): void;
48
+ /**
49
+ * Display a url to the console. This will be automatically suppressed if output is disabled.
50
+ *
51
+ * @param text text to display
52
+ * @param uri URL link
53
+ * @param params
54
+ */
7
55
  url(text: string, uri: string, params?: {}): void;
56
+ /**
57
+ * Display stylized JSON to the console. This will be automatically suppressed if output is disabled.
58
+ *
59
+ * @param obj JSON to display
60
+ */
8
61
  styledJSON(obj: AnyJson): void;
9
- styledObject(obj: AnyJson): void;
62
+ /**
63
+ * Display stylized object to the console. This will be automatically suppressed if output is disabled.
64
+ *
65
+ * @param obj Object to display
66
+ * @param keys Keys of object to display
67
+ */
68
+ styledObject(obj: AnyJson, keys?: string[]): void;
69
+ /**
70
+ * Display stylized header to the console. This will be automatically suppressed if output is disabled.
71
+ *
72
+ * @param text header to display
73
+ */
10
74
  styledHeader(text: string): void;
11
75
  }
12
76
  export declare namespace Ux {
package/lib/ux/ux.js CHANGED
@@ -9,22 +9,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Ux = void 0;
10
10
  const core_1 = require("@oclif/core");
11
11
  const base_1 = require("./base");
12
+ const prompter_1 = require("./prompter");
13
+ const spinner_1 = require("./spinner");
14
+ /**
15
+ * UX methods for plugins. Automatically suppress console output if outputEnabled is set to false.
16
+ *
17
+ * @example
18
+ * ```
19
+ * import { SfCommand, Ux } from '@salesforce/sf-plugins-core';
20
+ * import { AnyJson } from '@salesforce/ts-types';
21
+ *
22
+ * class MyCommand extends SfCommand<AnyJson> {
23
+ * public async run(): Promise<AnyJson> {
24
+ * const ux = new Ux(!this.jsonEnabled());
25
+ * }
26
+ * }
27
+ *
28
+ * ```
29
+ */
12
30
  class Ux extends base_1.UxBase {
13
31
  constructor(outputEnabled) {
14
32
  super(outputEnabled);
33
+ this.outputEnabled = outputEnabled;
34
+ this.spinner = new spinner_1.Spinner(outputEnabled);
35
+ this.prompter = new prompter_1.Prompter();
36
+ }
37
+ /**
38
+ * Log a message to the console. This will be automatically suppressed if output is disabled.
39
+ *
40
+ * @param message Message to log. Formatting is supported.
41
+ * @param args Args to be used for formatting.
42
+ */
43
+ log(message, ...args) {
44
+ this.maybeNoop(() => core_1.CliUx.ux.log(message, ...args));
45
+ }
46
+ /**
47
+ * Log a warning message to the console. This will be automatically suppressed if output is disabled.
48
+ *
49
+ * @param message Warning message to log.
50
+ */
51
+ warn(message) {
52
+ this.maybeNoop(() => core_1.CliUx.ux.warn(message));
15
53
  }
54
+ /**
55
+ * Display a table to the console. This will be automatically suppressed if output is disabled.
56
+ *
57
+ * @param data Data to be displayed
58
+ * @param columns Columns to display the data in
59
+ * @param options Options for how the table should be displayed
60
+ */
16
61
  table(data, columns, options) {
17
62
  this.maybeNoop(() => core_1.CliUx.ux.table(data, columns, options));
18
63
  }
64
+ /**
65
+ * Display a url to the console. This will be automatically suppressed if output is disabled.
66
+ *
67
+ * @param text text to display
68
+ * @param uri URL link
69
+ * @param params
70
+ */
19
71
  url(text, uri, params = {}) {
20
72
  this.maybeNoop(() => core_1.CliUx.ux.url(text, uri, params));
21
73
  }
74
+ /**
75
+ * Display stylized JSON to the console. This will be automatically suppressed if output is disabled.
76
+ *
77
+ * @param obj JSON to display
78
+ */
22
79
  styledJSON(obj) {
23
80
  this.maybeNoop(() => core_1.CliUx.ux.styledJSON(obj));
24
81
  }
25
- styledObject(obj) {
26
- this.maybeNoop(() => core_1.CliUx.ux.styledObject(obj));
82
+ /**
83
+ * Display stylized object to the console. This will be automatically suppressed if output is disabled.
84
+ *
85
+ * @param obj Object to display
86
+ * @param keys Keys of object to display
87
+ */
88
+ styledObject(obj, keys) {
89
+ this.maybeNoop(() => core_1.CliUx.ux.styledObject(obj, keys));
27
90
  }
91
+ /**
92
+ * Display stylized header to the console. This will be automatically suppressed if output is disabled.
93
+ *
94
+ * @param text header to display
95
+ */
28
96
  styledHeader(text) {
29
97
  this.maybeNoop(() => core_1.CliUx.ux.styledHeader(text));
30
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.15.2",
3
+ "version": "1.16.1",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -32,24 +32,24 @@
32
32
  "/messages"
33
33
  ],
34
34
  "dependencies": {
35
- "@oclif/core": "^1.16.4",
36
- "@salesforce/core": "^3.30.9",
35
+ "@oclif/core": "^1.19.0",
36
+ "@salesforce/core": "^3.31.16",
37
37
  "@salesforce/kit": "^1.7.0",
38
38
  "@salesforce/ts-types": "^1.5.20",
39
39
  "chalk": "^4",
40
40
  "inquirer": "^8.2.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@oclif/test": "^2.1.0",
43
+ "@oclif/test": "^2.2.4",
44
44
  "@salesforce/dev-config": "^3.0.0",
45
45
  "@salesforce/dev-scripts": "^3.1.0",
46
46
  "@salesforce/prettier-config": "^0.0.2",
47
47
  "@salesforce/ts-sinon": "^1.3.21",
48
48
  "@types/inquirer": "^8.2.3",
49
- "@typescript-eslint/eslint-plugin": "^5.33.0",
50
- "@typescript-eslint/parser": "^5.33.0",
49
+ "@typescript-eslint/eslint-plugin": "^5.40.0",
50
+ "@typescript-eslint/parser": "^5.40.0",
51
51
  "chai": "^4.3.6",
52
- "eslint": "^8.21.0",
52
+ "eslint": "^8.25.0",
53
53
  "eslint-config-prettier": "^8.5.0",
54
54
  "eslint-config-salesforce": "^1.1.0",
55
55
  "eslint-config-salesforce-license": "^0.1.6",