@salesforce/sf-plugins-core 2.1.3 → 2.2.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 +2 -1
- package/lib/exported.js +3 -1
- package/lib/sfCommand.d.ts +1 -0
- package/lib/sfCommand.js +25 -8
- package/lib/stubUx.d.ts +37 -0
- package/lib/stubUx.js +55 -0
- package/package.json +1 -1
package/lib/exported.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ 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, Ux } from './ux';
|
|
6
|
+
export { Progress, Prompter, generateTableChoices, Ux, Spinner } from './ux';
|
|
7
7
|
export { SfHook } from './hooks';
|
|
8
8
|
export * from './types';
|
|
9
9
|
export { SfCommand, SfCommandInterface, StandardColors } from './sfCommand';
|
|
10
10
|
export * from './compatibility';
|
|
11
|
+
export * from './stubUx';
|
|
11
12
|
export declare const Flags: {
|
|
12
13
|
boolean: typeof OclifFlags.boolean;
|
|
13
14
|
directory: import("@oclif/core/lib/interfaces/parser").FlagDefinition<string, {
|
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.Ux = 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.Spinner = 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; } });
|
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "Progress", { enumerable: true, get: function ()
|
|
|
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
37
|
Object.defineProperty(exports, "Ux", { enumerable: true, get: function () { return ux_1.Ux; } });
|
|
38
|
+
Object.defineProperty(exports, "Spinner", { enumerable: true, get: function () { return ux_1.Spinner; } });
|
|
38
39
|
var hooks_1 = require("./hooks");
|
|
39
40
|
Object.defineProperty(exports, "SfHook", { enumerable: true, get: function () { return hooks_1.SfHook; } });
|
|
40
41
|
__exportStar(require("./types"), exports);
|
|
@@ -42,6 +43,7 @@ var sfCommand_1 = require("./sfCommand");
|
|
|
42
43
|
Object.defineProperty(exports, "SfCommand", { enumerable: true, get: function () { return sfCommand_1.SfCommand; } });
|
|
43
44
|
Object.defineProperty(exports, "StandardColors", { enumerable: true, get: function () { return sfCommand_1.StandardColors; } });
|
|
44
45
|
__exportStar(require("./compatibility"), exports);
|
|
46
|
+
__exportStar(require("./stubUx"), exports);
|
|
45
47
|
// custom flags
|
|
46
48
|
const orgFlags_1 = require("./flags/orgFlags");
|
|
47
49
|
const salesforceId_1 = require("./flags/salesforceId");
|
package/lib/sfCommand.d.ts
CHANGED
|
@@ -251,6 +251,7 @@ export declare abstract class SfCommand<T> extends Command {
|
|
|
251
251
|
* Wrap the command error into the standardized JSON structure.
|
|
252
252
|
*/
|
|
253
253
|
protected toErrorJson(error: SfCommand.Error): SfCommand.Error;
|
|
254
|
+
protected logJson(json: AnyJson | unknown): void;
|
|
254
255
|
protected assignProject(): Promise<SfProject>;
|
|
255
256
|
protected catch(error: Error | SfError | SfCommand.Error): Promise<SfCommand.Error>;
|
|
256
257
|
/**
|
package/lib/sfCommand.js
CHANGED
|
@@ -235,6 +235,13 @@ class SfCommand extends core_1.Command {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
// eslint-disable-next-line class-methods-use-this
|
|
238
|
+
logJson(json) {
|
|
239
|
+
// If `--json` is enabled, then the ux instance on the class will disable output, which
|
|
240
|
+
// means that the logJson method will not output anything. So, we need to create a new
|
|
241
|
+
// instance of the ux class that does not have output disabled in order to log the json.
|
|
242
|
+
new ux_1.Ux().styledJSON(json);
|
|
243
|
+
}
|
|
244
|
+
// eslint-disable-next-line class-methods-use-this
|
|
238
245
|
async assignProject() {
|
|
239
246
|
try {
|
|
240
247
|
return await core_2.SfProject.resolve();
|
|
@@ -248,11 +255,18 @@ class SfCommand extends core_1.Command {
|
|
|
248
255
|
}
|
|
249
256
|
async catch(error) {
|
|
250
257
|
// transform an unknown error into one that conforms to the interface
|
|
251
|
-
|
|
258
|
+
// @ts-expect-error because exitCode is not on Error
|
|
259
|
+
const codeFromError = error.exitCode ?? 1;
|
|
252
260
|
process.exitCode ?? (process.exitCode = codeFromError);
|
|
253
|
-
const sfErrorProperties =
|
|
254
|
-
|
|
255
|
-
:
|
|
261
|
+
const sfErrorProperties = removeEmpty({
|
|
262
|
+
// @ts-expect-error because data is not on Error
|
|
263
|
+
data: error.data ?? null,
|
|
264
|
+
// @ts-expect-error because actions is not on Error
|
|
265
|
+
actions: error.actions ?? null,
|
|
266
|
+
code: codeFromError,
|
|
267
|
+
// @ts-expect-error because context is not on Error
|
|
268
|
+
context: error.context ?? null,
|
|
269
|
+
});
|
|
256
270
|
const sfCommandError = {
|
|
257
271
|
...sfErrorProperties,
|
|
258
272
|
...{
|
|
@@ -264,13 +278,12 @@ class SfCommand extends core_1.Command {
|
|
|
264
278
|
},
|
|
265
279
|
};
|
|
266
280
|
if (this.jsonEnabled()) {
|
|
267
|
-
|
|
281
|
+
this.logJson(this.toErrorJson(sfCommandError));
|
|
268
282
|
}
|
|
269
283
|
else {
|
|
270
|
-
|
|
271
|
-
console.error(this.formatError(sfCommandError));
|
|
284
|
+
this.logToStderr(this.formatError(sfCommandError));
|
|
272
285
|
}
|
|
273
|
-
|
|
286
|
+
throw sfCommandError;
|
|
274
287
|
}
|
|
275
288
|
/**
|
|
276
289
|
* Format errors and actions for human consumption. Adds 'Error (<ErrorCode>):',
|
|
@@ -329,4 +342,8 @@ SfCommand.enableJsonFlag = true;
|
|
|
329
342
|
* ```
|
|
330
343
|
*/
|
|
331
344
|
SfCommand.tableFlags = core_1.ux.table.flags;
|
|
345
|
+
function removeEmpty(obj) {
|
|
346
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
347
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v != null));
|
|
348
|
+
}
|
|
332
349
|
//# sourceMappingURL=sfCommand.js.map
|
package/lib/stubUx.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SinonSandbox } from 'sinon';
|
|
2
|
+
import { SfCommand } from './sfCommand';
|
|
3
|
+
import { Prompter, Ux } from './ux';
|
|
4
|
+
export declare function stubUx(sandbox: SinonSandbox): {
|
|
5
|
+
log: import("sinon").SinonStub<[message?: string | undefined, ...args: string[]], void>;
|
|
6
|
+
warn: import("sinon").SinonStub<[message: string | Error], void>;
|
|
7
|
+
table: import("sinon").SinonStub<[data: Ux.Table.Data[], columns: Ux.Table.Columns<Ux.Table.Data>, options?: import("@oclif/core/lib/cli-ux/styled/table").table.Options | undefined], void>;
|
|
8
|
+
url: import("sinon").SinonStub<[text: string, uri: string, params?: {} | undefined], void>;
|
|
9
|
+
styledHeader: import("sinon").SinonStub<[text: string], void>;
|
|
10
|
+
styledObject: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson, keys?: string[] | undefined], void>;
|
|
11
|
+
styledJSON: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson], void>;
|
|
12
|
+
};
|
|
13
|
+
export declare function stubSfCommandUx(sandbox: SinonSandbox): {
|
|
14
|
+
log: import("sinon").SinonStub<[message?: string | undefined, ...args: any[]], void>;
|
|
15
|
+
logToStderr: import("sinon").SinonStub<[message?: string | undefined, ...args: any[]], void>;
|
|
16
|
+
logSuccess: import("sinon").SinonStub<[message: string], void>;
|
|
17
|
+
logSensitive: import("sinon").SinonStub<[msg?: string | undefined], void>;
|
|
18
|
+
info: import("sinon").SinonStub<[input: SfCommand.Info], void>;
|
|
19
|
+
warn: import("sinon").SinonStub<[input: SfCommand.Warning], SfCommand.Warning>;
|
|
20
|
+
table: import("sinon").SinonStub<[data: Ux.Table.Data[], columns: Ux.Table.Columns<Ux.Table.Data>, options?: import("@oclif/core/lib/cli-ux/styled/table").table.Options | undefined], void>;
|
|
21
|
+
url: import("sinon").SinonStub<[text: string, uri: string, params?: {} | undefined], void>;
|
|
22
|
+
styledHeader: import("sinon").SinonStub<[text: string], void>;
|
|
23
|
+
styledObject: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson], void>;
|
|
24
|
+
styledJSON: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson], void>;
|
|
25
|
+
};
|
|
26
|
+
export declare function stubSpinner(sandbox: SinonSandbox): {
|
|
27
|
+
start: import("sinon").SinonStub<[action: string, status?: string | undefined, opts?: {
|
|
28
|
+
stdout?: boolean | undefined;
|
|
29
|
+
} | undefined], void>;
|
|
30
|
+
stop: import("sinon").SinonStub<[msg?: string | undefined], void>;
|
|
31
|
+
};
|
|
32
|
+
export declare function stubPrompter(sandbox: SinonSandbox): {
|
|
33
|
+
prompt: import("sinon").SinonStub<[questions: Prompter.Questions<Record<string, unknown>>, initialAnswers?: Partial<Record<string, unknown>> | undefined], Promise<Record<string, unknown>>>;
|
|
34
|
+
confirm: import("sinon").SinonStub<[message: string, ms?: number | undefined, defaultAnswer?: boolean | undefined], Promise<boolean>>;
|
|
35
|
+
timedPrompt: import("sinon").SinonStub<[questions: Prompter.Questions<Record<string, unknown>>, ms?: number | undefined, initialAnswers?: Partial<Record<string, unknown>> | undefined], Promise<Record<string, unknown>>>;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=stubUx.d.ts.map
|
package/lib/stubUx.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.stubPrompter = exports.stubSpinner = exports.stubSfCommandUx = exports.stubUx = void 0;
|
|
10
|
+
const sfCommand_1 = require("./sfCommand");
|
|
11
|
+
const ux_1 = require("./ux");
|
|
12
|
+
function stubUx(sandbox) {
|
|
13
|
+
return {
|
|
14
|
+
log: sandbox.stub(ux_1.Ux.prototype, 'log'),
|
|
15
|
+
warn: sandbox.stub(ux_1.Ux.prototype, 'warn'),
|
|
16
|
+
table: sandbox.stub(ux_1.Ux.prototype, 'table'),
|
|
17
|
+
url: sandbox.stub(ux_1.Ux.prototype, 'url'),
|
|
18
|
+
styledHeader: sandbox.stub(ux_1.Ux.prototype, 'styledHeader'),
|
|
19
|
+
styledObject: sandbox.stub(ux_1.Ux.prototype, 'styledObject'),
|
|
20
|
+
styledJSON: sandbox.stub(ux_1.Ux.prototype, 'styledJSON'),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.stubUx = stubUx;
|
|
24
|
+
function stubSfCommandUx(sandbox) {
|
|
25
|
+
return {
|
|
26
|
+
log: sandbox.stub(sfCommand_1.SfCommand.prototype, 'log'),
|
|
27
|
+
logToStderr: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logToStderr'),
|
|
28
|
+
logSuccess: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logSuccess'),
|
|
29
|
+
logSensitive: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logSensitive'),
|
|
30
|
+
info: sandbox.stub(sfCommand_1.SfCommand.prototype, 'info'),
|
|
31
|
+
warn: sandbox.stub(sfCommand_1.SfCommand.prototype, 'warn'),
|
|
32
|
+
table: sandbox.stub(sfCommand_1.SfCommand.prototype, 'table'),
|
|
33
|
+
url: sandbox.stub(sfCommand_1.SfCommand.prototype, 'url'),
|
|
34
|
+
styledHeader: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledHeader'),
|
|
35
|
+
styledObject: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledObject'),
|
|
36
|
+
styledJSON: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledJSON'),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.stubSfCommandUx = stubSfCommandUx;
|
|
40
|
+
function stubSpinner(sandbox) {
|
|
41
|
+
return {
|
|
42
|
+
start: sandbox.stub(ux_1.Spinner.prototype, 'start'),
|
|
43
|
+
stop: sandbox.stub(ux_1.Spinner.prototype, 'stop'),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.stubSpinner = stubSpinner;
|
|
47
|
+
function stubPrompter(sandbox) {
|
|
48
|
+
return {
|
|
49
|
+
prompt: sandbox.stub(ux_1.Prompter.prototype, 'prompt'),
|
|
50
|
+
confirm: sandbox.stub(ux_1.Prompter.prototype, 'confirm'),
|
|
51
|
+
timedPrompt: sandbox.stub(ux_1.Prompter.prototype, 'timedPrompt'),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.stubPrompter = stubPrompter;
|
|
55
|
+
//# sourceMappingURL=stubUx.js.map
|