@salesforce/sf-plugins-core 1.5.0 → 1.5.3

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,21 @@
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.5.3](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.2...v1.5.3) (2022-03-08)
6
+
7
+ ### Bug Fixes
8
+
9
+ - expose styledHeader as func in sf command ([fd2dc48](https://github.com/salesforcecli/sf-plugins-core/commit/fd2dc48444be224a884c3b56d5604f4b854f1c0e))
10
+
11
+ ### [1.5.2](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.1...v1.5.2) (2022-03-07)
12
+
13
+ ### Bug Fixes
14
+
15
+ - add styled header function to sf command ([5cc0e8b](https://github.com/salesforcecli/sf-plugins-core/commit/5cc0e8bf60774918c2ebaf2ba5b465f3dd6caf15))
16
+ - retrhow ([eaebd44](https://github.com/salesforcecli/sf-plugins-core/commit/eaebd44d0028cedab92173ed30050757602d2c28))
17
+
18
+ ### [1.5.1](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.0...v1.5.1) (2022-03-07)
19
+
5
20
  ## [1.5.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.4.1...v1.5.0) (2022-03-03)
6
21
 
7
22
  ### Features
package/lib/exported.js CHANGED
@@ -7,7 +7,11 @@
7
7
  */
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
9
  if (k2 === undefined) k2 = k;
10
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
11
15
  }) : (function(o, m, k, k2) {
12
16
  if (k2 === undefined) k2 = k;
13
17
  o[k2] = m[k];
@@ -1,5 +1,5 @@
1
1
  import { CliUx, Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
- import { SfdxProject } from '@salesforce/core';
2
+ import { SfProject, StructuredMessage } from '@salesforce/core';
3
3
  import { AnyJson } from '@salesforce/ts-types';
4
4
  import { Progress, Prompter, Spinner, Ux } from './ux';
5
5
  export interface SfCommandInterface extends Interfaces.Command {
@@ -16,6 +16,7 @@ export interface SfCommandInterface extends Interfaces.Command {
16
16
  * @see https://github.com/oclif/core/blob/main/src/command.ts
17
17
  */
18
18
  export declare abstract class SfCommand<T> extends Command {
19
+ static SF_ENV: string;
19
20
  static enableJsonFlag: boolean;
20
21
  static configurationVariablesSection?: HelpSection;
21
22
  static envVariablesSection?: HelpSection;
@@ -24,7 +25,7 @@ export declare abstract class SfCommand<T> extends Command {
24
25
  static requiresProject: boolean;
25
26
  spinner: Spinner;
26
27
  progress: Progress;
27
- project: SfdxProject;
28
+ project: SfProject;
28
29
  private warnings;
29
30
  private ux;
30
31
  private prompter;
@@ -36,6 +37,10 @@ export declare abstract class SfCommand<T> extends Command {
36
37
  * will be added to the json output under the warnings property.
37
38
  */
38
39
  warn(input: SfCommand.Warning): SfCommand.Warning;
40
+ /**
41
+ * Log info message to users.
42
+ */
43
+ info(input: SfCommand.Info): void;
39
44
  /**
40
45
  * Warn user about sensitive information (access tokens, etc...) before
41
46
  * logging to the console.
@@ -57,6 +62,10 @@ export declare abstract class SfCommand<T> extends Command {
57
62
  * Log stylized object to the console. Will automatically be suppressed when --json flag is present.
58
63
  */
59
64
  styledObject(obj: AnyJson): void;
65
+ /**
66
+ * Log stylized header to the console. Will automatically be suppressed when --json flag is present.
67
+ */
68
+ styledHeader(text: string): void;
60
69
  /**
61
70
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
62
71
  *
@@ -80,11 +89,30 @@ export declare abstract class SfCommand<T> extends Command {
80
89
  * Wrap the command error into the standardized JSON structure.
81
90
  */
82
91
  protected toErrorJson(error: Error): SfCommand.Error;
83
- protected assignProject(): Promise<SfdxProject>;
92
+ protected assignProject(): Promise<SfProject>;
93
+ protected catch(error: SfCommand.Error): Promise<SfCommand.Error>;
94
+ /**
95
+ * Format errors and actions for human consumption. Adds 'Error:',
96
+ * When there are actions, we add 'Try this:' in blue
97
+ * followed by each action in red on its own line.
98
+ * If Error.code is present it is output last in parentheses
99
+ *
100
+ * @returns {string} Returns decorated messages.
101
+ */
102
+ protected formatError(error: SfCommand.Error): string;
103
+ /**
104
+ * Utility function to format actions lines
105
+ *
106
+ * @param actions
107
+ * @param options
108
+ * @private
109
+ */
110
+ private formatActions;
84
111
  abstract run(): Promise<T>;
85
112
  }
86
113
  export declare namespace SfCommand {
87
- type Warning = string | Error;
114
+ type Info = StructuredMessage | string;
115
+ type Warning = StructuredMessage | string;
88
116
  interface Json<T> {
89
117
  status: number;
90
118
  result: T;
@@ -96,6 +124,9 @@ export declare namespace SfCommand {
96
124
  message: string;
97
125
  stack: string | undefined;
98
126
  warnings?: Warning[];
127
+ actions?: string[];
128
+ code?: unknown;
129
+ exitCode?: number;
99
130
  }
100
131
  }
101
132
  //# sourceMappingURL=sfCommand.d.ts.map
package/lib/sfCommand.js CHANGED
@@ -7,8 +7,10 @@ exports.SfCommand = void 0;
7
7
  * Licensed under the BSD 3-Clause license.
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
9
  */
10
+ const os = require("os");
10
11
  const core_1 = require("@oclif/core");
11
12
  const core_2 = require("@salesforce/core");
13
+ const chalk_1 = require("chalk");
12
14
  const ux_1 = require("./ux");
13
15
  core_2.Messages.importMessagesDirectory(__dirname);
14
16
  const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
@@ -39,10 +41,24 @@ class SfCommand extends core_1.Command {
39
41
  * will be added to the json output under the warnings property.
40
42
  */
41
43
  warn(input) {
42
- const warning = super.warn(input);
43
- this.warnings.push(warning);
44
+ const colorizedArgs = [];
45
+ this.warnings.push(input);
46
+ const message = typeof input === 'string' ? input : input.message;
47
+ colorizedArgs.push(`${chalk_1.default.bold.yellow(messages.getMessage('warning.prefix'))} ${message}`);
48
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: chalk_1.default.reset }));
49
+ this.log(colorizedArgs.join(os.EOL));
44
50
  return input;
45
51
  }
52
+ /**
53
+ * Log info message to users.
54
+ */
55
+ info(input) {
56
+ const colorizedArgs = [];
57
+ const message = typeof input === 'string' ? input : input.message;
58
+ colorizedArgs.push(`${chalk_1.default.bold(messages.getMessage('info.prefix'))} ${message}`);
59
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: chalk_1.default.reset }));
60
+ this.log(colorizedArgs.join(os.EOL));
61
+ }
46
62
  /**
47
63
  * Warn user about sensitive information (access tokens, etc...) before
48
64
  * logging to the console.
@@ -75,6 +91,12 @@ class SfCommand extends core_1.Command {
75
91
  styledObject(obj) {
76
92
  this.ux.styledObject(obj);
77
93
  }
94
+ /**
95
+ * Log stylized header to the console. Will automatically be suppressed when --json flag is present.
96
+ */
97
+ styledHeader(text) {
98
+ this.ux.styledHeader(text);
99
+ }
78
100
  /**
79
101
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
80
102
  *
@@ -126,7 +148,7 @@ class SfCommand extends core_1.Command {
126
148
  }
127
149
  async assignProject() {
128
150
  try {
129
- return await core_2.SfdxProject.resolve();
151
+ return await core_2.SfProject.resolve();
130
152
  }
131
153
  catch (err) {
132
154
  if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') {
@@ -135,8 +157,56 @@ class SfCommand extends core_1.Command {
135
157
  throw err;
136
158
  }
137
159
  }
160
+ async catch(error) {
161
+ var _a, _b;
162
+ process.exitCode = (_b = (_a = process.exitCode) !== null && _a !== void 0 ? _a : error.exitCode) !== null && _b !== void 0 ? _b : 1;
163
+ this.log(this.formatError(error));
164
+ if (this.jsonEnabled()) {
165
+ core_1.CliUx.ux.styledJSON(this.toErrorJson(error));
166
+ }
167
+ throw error;
168
+ }
169
+ /**
170
+ * Format errors and actions for human consumption. Adds 'Error:',
171
+ * When there are actions, we add 'Try this:' in blue
172
+ * followed by each action in red on its own line.
173
+ * If Error.code is present it is output last in parentheses
174
+ *
175
+ * @returns {string} Returns decorated messages.
176
+ */
177
+ formatError(error) {
178
+ const colorizedArgs = [];
179
+ colorizedArgs.push(`${chalk_1.default.bold.red(messages.getMessage('error.prefix'))} ${error.message}`);
180
+ colorizedArgs.push(...this.formatActions(error.actions || []));
181
+ if (error.stack && core_2.envVars.getString(SfCommand.SF_ENV) === core_2.Mode.DEVELOPMENT) {
182
+ colorizedArgs.push(chalk_1.default.red(`\n*** Internal Diagnostic ***\n\n${error.stack}\n******\n`));
183
+ }
184
+ if (error.code) {
185
+ colorizedArgs.push(chalk_1.default.bold(`\n(${error.code})`));
186
+ }
187
+ return colorizedArgs.join('\n');
188
+ }
189
+ /**
190
+ * Utility function to format actions lines
191
+ *
192
+ * @param actions
193
+ * @param options
194
+ * @private
195
+ */
196
+ formatActions(actions, options = { actionColor: chalk_1.default.red }) {
197
+ const colorizedArgs = [];
198
+ // Format any actions.
199
+ if (actions === null || actions === void 0 ? void 0 : actions.length) {
200
+ colorizedArgs.push(`\n${chalk_1.default.blue.bold(messages.getMessage('actions.tryThis'))}\n`);
201
+ actions.forEach((action) => {
202
+ colorizedArgs.push(`${options.actionColor(action)}`);
203
+ });
204
+ }
205
+ return colorizedArgs;
206
+ }
138
207
  }
139
208
  exports.SfCommand = SfCommand;
209
+ SfCommand.SF_ENV = 'SF_ENV';
140
210
  SfCommand.enableJsonFlag = true;
141
211
  SfCommand.tableFlags = core_1.CliUx.ux.table.flags;
142
212
  //# sourceMappingURL=sfCommand.js.map
@@ -67,7 +67,7 @@ class Progress extends _1.UxBase {
67
67
  this.bar.stop();
68
68
  }
69
69
  _start(total, payload = {}) {
70
- const start = kit_1.once((bar, t, p = {}) => {
70
+ const start = (0, kit_1.once)((bar, t, p = {}) => {
71
71
  bar.start(t);
72
72
  if (Object.keys(p).length) {
73
73
  bar.update(0, p);
@@ -14,7 +14,7 @@ class Prompter {
14
14
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
15
15
  */
16
16
  async prompt(questions, initialAnswers) {
17
- const answers = await inquirer_1.prompt(questions, initialAnswers);
17
+ const answers = await (0, inquirer_1.prompt)(questions, initialAnswers);
18
18
  return answers;
19
19
  }
20
20
  }
@@ -32,7 +32,7 @@ function generateTableChoices(columns, choices,
32
32
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
33
  padForCheckbox = true) {
34
34
  const columnEntries = Object.entries(columns);
35
- const columnLengths = columnEntries.map(([key, value]) => Math.max(ts_types_1.ensureString(value).length, ...choices.map((option) => ts_types_1.ensureString(option[key], `Type ${typeof option[key]} for ${key} in ${Object.keys(option).join(', ')}`)
35
+ const columnLengths = columnEntries.map(([key, value]) => Math.max((0, ts_types_1.ensureString)(value).length, ...choices.map((option) => (0, ts_types_1.ensureString)(option[key], `Type ${typeof option[key]} for ${key} in ${Object.keys(option).join(', ')}`)
36
36
  .length)) + 1);
37
37
  const choicesOptions = [
38
38
  new inquirer_1.Separator(`${padForCheckbox ? ' '.repeat(2) : ''}${columnEntries
@@ -41,9 +41,9 @@ padForCheckbox = true) {
41
41
  ];
42
42
  for (const meta of choices) {
43
43
  const name = columnEntries
44
- .map(([key], index) => ts_types_1.ensureString(meta[key]).padEnd(columnLengths[index], ' '))
44
+ .map(([key], index) => (0, ts_types_1.ensureString)(meta[key]).padEnd(columnLengths[index], ' '))
45
45
  .join('');
46
- const choice = { name, value: meta.value, short: ts_types_1.ensureString(meta.name) };
46
+ const choice = { name, value: meta.value, short: (0, ts_types_1.ensureString)(meta.name) };
47
47
  choicesOptions.push(choice);
48
48
  }
49
49
  return choicesOptions;
package/lib/ux/ux.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare class Ux extends UxBase {
7
7
  url(text: string, uri: string, params?: {}): void;
8
8
  styledJSON(obj: AnyJson): void;
9
9
  styledObject(obj: AnyJson): void;
10
+ styledHeader(text: string): void;
10
11
  }
11
12
  export declare namespace Ux {
12
13
  namespace Table {
package/lib/ux/ux.js CHANGED
@@ -25,6 +25,9 @@ class Ux extends base_1.UxBase {
25
25
  styledObject(obj) {
26
26
  this.maybeNoop(() => core_1.CliUx.ux.styledObject(obj));
27
27
  }
28
+ styledHeader(text) {
29
+ this.maybeNoop(() => core_1.CliUx.ux.styledHeader(text));
30
+ }
28
31
  }
29
32
  exports.Ux = Ux;
30
33
  //# sourceMappingURL=ux.js.map
@@ -1,3 +1,7 @@
1
+ # error.prefix
2
+
3
+ Error:
4
+
1
5
  # warning.security
2
6
 
3
7
  This command will expose sensitive information that allows for subsequent activity using your current authenticated session. Sharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege. For additional information, please review the authorization section of the <https://developer.salesforce.com/docs/atlas.en-us.234.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_web_flow.htm>
@@ -57,3 +61,15 @@ The value must be an integer.
57
61
  # errors.DurationBounds
58
62
 
59
63
  The value must be between %s and %s (inclusive).
64
+
65
+ # warning.prefix
66
+
67
+ Warning:
68
+
69
+ # info.prefix
70
+
71
+ Info:
72
+
73
+ # actions.tryThis
74
+
75
+ Try this:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.5.0",
3
+ "version": "1.5.3",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -32,40 +32,42 @@
32
32
  "/messages"
33
33
  ],
34
34
  "dependencies": {
35
- "@oclif/core": "^1.5.1",
36
- "@salesforce/core": "^3.7.7",
37
- "@salesforce/kit": "^1.5.17",
35
+ "@oclif/core": "^1.5.2",
36
+ "@salesforce/core": "^3.7.9",
37
+ "@salesforce/kit": "^1.5.34",
38
38
  "@salesforce/ts-types": "^1.5.20",
39
+ "chalk": "^2.4.2",
39
40
  "inquirer": "^8.2.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@salesforce/dev-config": "^2.1.2",
43
- "@salesforce/dev-scripts": "^1.0.2",
43
+ "@oclif/test": "^2.1.0",
44
+ "@salesforce/dev-config": "^2.1.3",
45
+ "@salesforce/dev-scripts": "^1.0.4",
44
46
  "@salesforce/prettier-config": "^0.0.2",
45
- "@salesforce/ts-sinon": "^1.2.3",
46
- "@types/inquirer": "^8.1.3",
47
- "@typescript-eslint/eslint-plugin": "^4.2.0",
48
- "@typescript-eslint/parser": "^4.2.0",
49
- "chai": "^4.2.0",
47
+ "@salesforce/ts-sinon": "^1.3.21",
48
+ "@types/inquirer": "^8.2.0",
49
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
50
+ "@typescript-eslint/parser": "^4.33.0",
51
+ "chai": "^4.3.6",
50
52
  "eslint": "^6.8.0",
51
- "eslint-config-prettier": "^6.11.0",
53
+ "eslint-config-prettier": "^6.15.0",
52
54
  "eslint-config-salesforce": "^0.1.6",
53
55
  "eslint-config-salesforce-license": "^0.1.6",
54
- "eslint-config-salesforce-typescript": "^0.2.7",
55
- "eslint-plugin-header": "^3.0.0",
56
- "eslint-plugin-import": "^2.20.2",
57
- "eslint-plugin-jsdoc": "^27.0.3",
58
- "eslint-plugin-prettier": "^3.1.3",
56
+ "eslint-config-salesforce-typescript": "^0.2.8",
57
+ "eslint-plugin-header": "^3.1.1",
58
+ "eslint-plugin-import": "^2.25.4",
59
+ "eslint-plugin-jsdoc": "^27.1.2",
60
+ "eslint-plugin-prettier": "^3.4.1",
59
61
  "husky": "^7.0.4",
60
62
  "mocha": "^8.4.0",
61
63
  "nyc": "^15.1.0",
62
- "prettier": "^2.0.5",
63
- "pretty-quick": "^3.1.0",
64
+ "prettier": "^2.5.1",
65
+ "pretty-quick": "^3.1.3",
64
66
  "shelljs": "0.8.5",
65
- "sinon": "10.0.0",
66
- "strip-ansi": "6.0.0",
67
- "ts-node": "^10.4.0",
68
- "typescript": "^4.1.3"
67
+ "sinon": "10.0.1",
68
+ "strip-ansi": "6.0.1",
69
+ "ts-node": "^10.7.0",
70
+ "typescript": "^4.5.5"
69
71
  },
70
72
  "publishConfig": {
71
73
  "access": "public"