@salesforce/sf-plugins-core 5.0.12 → 5.0.14-dev.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.
Files changed (52) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +2 -5
  3. package/lib/compatibility.d.ts +7 -7
  4. package/lib/compatibility.js +14 -17
  5. package/lib/errorFormatting.d.ts +22 -0
  6. package/lib/errorFormatting.js +41 -0
  7. package/lib/exported.d.ts +9 -70
  8. package/lib/exported.js +9 -62
  9. package/lib/flags/duration.d.ts +1 -1
  10. package/lib/flags/duration.js +7 -10
  11. package/lib/flags/flags.d.ts +63 -0
  12. package/lib/flags/flags.js +30 -0
  13. package/lib/flags/orgApiVersion.d.ts +1 -1
  14. package/lib/flags/orgApiVersion.js +16 -19
  15. package/lib/flags/orgFlags.d.ts +4 -4
  16. package/lib/flags/orgFlags.js +30 -37
  17. package/lib/flags/salesforceId.d.ts +1 -1
  18. package/lib/flags/salesforceId.js +6 -9
  19. package/lib/prompts.d.ts +13 -0
  20. package/lib/prompts.js +25 -0
  21. package/lib/sfCommand.d.ts +26 -94
  22. package/lib/sfCommand.js +130 -131
  23. package/lib/sfCommandNamespace.d.ts +24 -0
  24. package/lib/sfCommandNamespace.js +2 -0
  25. package/lib/stubUx.d.ts +7 -9
  26. package/lib/stubUx.js +30 -37
  27. package/lib/tsconfig.tsbuildinfo +1 -1
  28. package/lib/util.d.ts +1 -0
  29. package/lib/util.js +9 -13
  30. package/lib/ux/base.d.ts +1 -1
  31. package/lib/ux/base.js +2 -5
  32. package/lib/ux/progress.d.ts +1 -1
  33. package/lib/ux/progress.js +15 -17
  34. package/lib/ux/spinner.d.ts +1 -1
  35. package/lib/ux/spinner.js +8 -12
  36. package/lib/ux/standardColors.d.ts +7 -0
  37. package/lib/ux/standardColors.js +14 -0
  38. package/lib/ux/ux.d.ts +2 -4
  39. package/lib/ux/ux.js +14 -18
  40. package/package.json +17 -11
  41. package/lib/deauthorizer.d.ts +0 -22
  42. package/lib/deauthorizer.js +0 -35
  43. package/lib/deployer.d.ts +0 -81
  44. package/lib/deployer.js +0 -58
  45. package/lib/hooks.d.ts +0 -34
  46. package/lib/hooks.js +0 -30
  47. package/lib/types/index.d.ts +0 -128
  48. package/lib/types/index.js +0 -55
  49. package/lib/ux/index.d.ts +0 -6
  50. package/lib/ux/index.js +0 -22
  51. package/lib/ux/prompter.d.ts +0 -40
  52. package/lib/ux/prompter.js +0 -99
package/lib/sfCommand.js CHANGED
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SfCommand = exports.StandardColors = void 0;
4
1
  /*
5
2
  * Copyright (c) 2022, salesforce.com, inc.
6
3
  * All rights reserved.
7
4
  * Licensed under the BSD 3-Clause license.
8
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
6
  */
10
- const os = require("node:os");
11
- const core_1 = require("@oclif/core");
12
- const core_2 = require("@salesforce/core");
13
- const chalk = require("chalk");
14
- const ux_1 = require("./ux");
15
- core_2.Messages.importMessagesDirectory(__dirname);
16
- const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
17
- exports.StandardColors = {
18
- error: chalk.bold.red,
19
- warning: chalk.bold.yellow,
20
- info: chalk.dim,
21
- success: chalk.bold.green,
22
- };
7
+ import os from 'node:os';
8
+ import { Command } from '@oclif/core';
9
+ import { envVars, Messages, SfProject, Lifecycle, EnvironmentVariable, SfError, ConfigAggregator, } from '@salesforce/core';
10
+ import { Progress } from './ux/progress.js';
11
+ import { Ux } from './ux/ux.js';
12
+ import { formatActions, formatError } from './errorFormatting.js';
13
+ import { StandardColors } from './ux/standardColors.js';
14
+ import { confirm, secretPrompt } from './prompts.js';
15
+ import { removeEmpty } from './util.js';
16
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
17
+ const messages = Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
23
18
  /**
24
19
  * A base command that provided common functionality for all sf commands.
25
20
  * Functionality includes:
@@ -51,15 +46,87 @@ exports.StandardColors = {
51
46
  * }
52
47
  * ```
53
48
  */
54
- class SfCommand extends core_1.Command {
49
+ export class SfCommand extends Command {
50
+ static enableJsonFlag = true;
51
+ /**
52
+ * Add a CONFIGURATION VARIABLES section to the help output.
53
+ *
54
+ * @example
55
+ * ```
56
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
57
+ * import { OrgConfigProperties } from '@salesforce/core';
58
+ * export default class MyCommand extends SfCommand {
59
+ * public static configurationVariablesSection = toHelpSection(
60
+ * 'CONFIGURATION VARIABLES',
61
+ * OrgConfigProperties.TARGET_ORG,
62
+ * OrgConfigProperties.ORG_API_VERSION,
63
+ * );
64
+ * }
65
+ * ```
66
+ */
67
+ static configurationVariablesSection;
68
+ /**
69
+ * Add an Environment VARIABLES section to the help output.
70
+ *
71
+ * @example
72
+ * ```
73
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
74
+ * import { EnvironmentVariable } from '@salesforce/core';
75
+ * export default class MyCommand extends SfCommand {
76
+ * public static envVariablesSection = toHelpSection(
77
+ * 'ENVIRONMENT VARIABLES',
78
+ * EnvironmentVariable.SF_TARGET_ORG,
79
+ * EnvironmentVariable.SF_USE_PROGRESS_BAR,
80
+ * );
81
+ * }
82
+ * ```
83
+ */
84
+ static envVariablesSection;
85
+ /**
86
+ * Add an ERROR CODES section to the help output.
87
+ *
88
+ * @example
89
+ * ```
90
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
91
+ * export default class MyCommand extends SfCommand {
92
+ * public static errorCodes = toHelpSection(
93
+ * 'ERROR CODES',
94
+ * { 0: 'Success', 1: 'Failure' },
95
+ * );
96
+ * }
97
+ * ```
98
+ */
99
+ static errorCodes;
100
+ /**
101
+ * Set to true if the command must be executed inside a Salesforce project directory.
102
+ *
103
+ * If set to true the command will throw an error if the command is executed outside of a Salesforce project directory.
104
+ * Additionally, this.project will be set to the current Salesforce project (SfProject).
105
+ *
106
+ */
107
+ static requiresProject;
108
+ /**
109
+ * Add a spinner to the console. {@link Spinner}
110
+ */
111
+ spinner;
112
+ /**
113
+ * Add a progress bar to the console. {@link Progress}
114
+ */
115
+ progress;
116
+ project;
117
+ /**
118
+ * ConfigAggregator instance for accessing global and local configuration.
119
+ */
120
+ configAggregator;
121
+ warnings = [];
122
+ ux;
123
+ lifecycle;
55
124
  constructor(argv, config) {
56
125
  super(argv, config);
57
- this.warnings = [];
58
- this.ux = new ux_1.Ux({ jsonEnabled: this.jsonEnabled() });
59
- this.progress = new ux_1.Progress(this.ux.outputEnabled && core_2.envVars.getBoolean(core_2.EnvironmentVariable.SF_USE_PROGRESS_BAR, true));
126
+ this.ux = new Ux({ jsonEnabled: this.jsonEnabled() });
127
+ this.progress = new Progress(this.ux.outputEnabled && envVars.getBoolean(EnvironmentVariable.SF_USE_PROGRESS_BAR, true));
60
128
  this.spinner = this.ux.spinner;
61
- this.prompter = this.ux.prompter;
62
- this.lifecycle = core_2.Lifecycle.getInstance();
129
+ this.lifecycle = Lifecycle.getInstance();
63
130
  }
64
131
  get statics() {
65
132
  return this.constructor;
@@ -70,7 +137,7 @@ class SfCommand extends core_1.Command {
70
137
  // unless it's been explicitly disabled on the command's statics
71
138
  return (super.jsonEnabled() ||
72
139
  (this.statics.enableJsonFlag !== false &&
73
- core_2.envVars.getString(core_2.EnvironmentVariable.SF_CONTENT_TYPE)?.toUpperCase() === 'JSON'));
140
+ envVars.getString(EnvironmentVariable.SF_CONTENT_TYPE)?.toUpperCase() === 'JSON'));
74
141
  }
75
142
  /**
76
143
  * Log a success message that has the standard success message color applied.
@@ -78,7 +145,7 @@ class SfCommand extends core_1.Command {
78
145
  * @param message The message to log.
79
146
  */
80
147
  logSuccess(message) {
81
- this.log(exports.StandardColors.success(message));
148
+ this.log(StandardColors.success(message));
82
149
  }
83
150
  /**
84
151
  * Log warning to users. If --json is enabled, then the warning will be added to the json output under the warnings property.
@@ -86,11 +153,12 @@ class SfCommand extends core_1.Command {
86
153
  * @param input {@link SfCommand.Warning} The message to log.
87
154
  */
88
155
  warn(input) {
89
- const colorizedArgs = [];
90
156
  this.warnings.push(input);
91
157
  const message = typeof input === 'string' ? input : input.message;
92
- colorizedArgs.push(`${exports.StandardColors.warning(messages.getMessage('warning.prefix'))} ${message}`);
93
- colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: exports.StandardColors.info }));
158
+ const colorizedArgs = [
159
+ `${StandardColors.warning(messages.getMessage('warning.prefix'))} ${message}`,
160
+ ...formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: StandardColors.info }),
161
+ ];
94
162
  this.logToStderr(colorizedArgs.join(os.EOL));
95
163
  return input;
96
164
  }
@@ -100,11 +168,11 @@ class SfCommand extends core_1.Command {
100
168
  * @param input {@link SfCommand.Info} The message to log.
101
169
  */
102
170
  info(input) {
103
- const colorizedArgs = [];
104
171
  const message = typeof input === 'string' ? input : input.message;
105
- colorizedArgs.push(`${exports.StandardColors.info(message)}`);
106
- colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: exports.StandardColors.info }));
107
- this.log(colorizedArgs.join(os.EOL));
172
+ this.log([
173
+ `${StandardColors.info(message)}`,
174
+ ...formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: StandardColors.info }),
175
+ ].join(os.EOL));
108
176
  }
109
177
  /**
110
178
  * Warn user about sensitive information (access tokens, etc...) before logging to the console.
@@ -160,40 +228,32 @@ class SfCommand extends core_1.Command {
160
228
  // If `--json` is enabled, then the ux instance on the class will disable output, which
161
229
  // means that the logJson method will not output anything. So, we need to create a new
162
230
  // instance of the ux class that does not have output disabled in order to log the json.
163
- new ux_1.Ux().styledJSON(json);
231
+ new Ux().styledJSON(json);
164
232
  }
165
233
  /**
166
- * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
234
+ * Prompt user for yes/no confirmation.
235
+ * Avoid calling in --json scenarios and always provide a `--no-prompt` option for scripting
167
236
  *
168
- * This will NOT be automatically suppressed when the --json flag is present since we assume
169
- * that any command that prompts the user for required information will not also support the --json flag.
170
- *
171
- * If you need to conditionally suppress prompts to support json output, then do the following:
237
+ * @param message text to display. Do not include a question mark.
238
+ * @param ms milliseconds to wait for user input. Defaults to 60s. Will throw an error when timeout is reached.
172
239
  *
173
- * @example
174
- * if (!this.jsonEnabled()) {
175
- * await this.prompt();
176
- * }
177
240
  */
178
- async prompt(questions, initialAnswers) {
179
- return this.prompter.prompt(questions, initialAnswers);
241
+ // eslint-disable-next-line class-methods-use-this
242
+ async secretPrompt({ message, ms = 60000 }) {
243
+ return secretPrompt({ message, ms });
180
244
  }
181
245
  /**
182
- * Simplified prompt for single-question confirmation. Times out and throws after 10s
246
+ * Prompt user for yes/no confirmation.
247
+ * Avoid calling in --json scenarios and always provide a `--no-prompt` option for scripting
248
+ *
249
+ * @param message text to display. Do not include a question mark or Y/N.
250
+ * @param ms milliseconds to wait for user input. Defaults to 10s. Will use the default value when timeout is reached.
251
+ * @param defaultAnswer boolean to set the default answer to. Defaults to false.
183
252
  *
184
- * @param message text to display. Do not include a question mark.
185
- * @param ms milliseconds to wait for user input. Defaults to 10s.
186
- * @param defaultAnswer boolean to set the default answer to. Defaults to true.
187
- * @return true if the user confirms, false if they do not.
188
- */
189
- async confirm(message, ms = 10000, defaultAnswer = true) {
190
- return this.prompter.confirm(message, ms, defaultAnswer);
191
- }
192
- /**
193
- * Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
194
253
  */
195
- async timedPrompt(questions, ms = 10000, initialAnswers) {
196
- return this.prompter.timedPrompt(questions, ms, initialAnswers);
254
+ // eslint-disable-next-line class-methods-use-this
255
+ async confirm({ message, ms = 10000, defaultAnswer = false }) {
256
+ return confirm({ message, ms, defaultAnswer });
197
257
  }
198
258
  async _run() {
199
259
  ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP'].map((listener) => {
@@ -202,8 +262,8 @@ class SfCommand extends core_1.Command {
202
262
  });
203
263
  });
204
264
  [this.configAggregator, this.project] = await Promise.all([
205
- core_2.ConfigAggregator.create(),
206
- ...(this.statics.requiresProject ? [this.assignProject()] : []),
265
+ ConfigAggregator.create(),
266
+ ...(this.statics.requiresProject ? [assignProject()] : []),
207
267
  ]);
208
268
  if (this.statics.state === 'beta') {
209
269
  this.warn(messages.getMessage('warning.CommandInBeta'));
@@ -252,23 +312,11 @@ class SfCommand extends core_1.Command {
252
312
  warnings: this.warnings,
253
313
  };
254
314
  }
255
- // eslint-disable-next-line class-methods-use-this
256
- async assignProject() {
257
- try {
258
- return await core_2.SfProject.resolve();
259
- }
260
- catch (err) {
261
- if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') {
262
- throw messages.createError('errors.RequiresProject');
263
- }
264
- throw err;
265
- }
266
- }
267
315
  // eslint-disable-next-line @typescript-eslint/require-await
268
316
  async catch(error) {
269
317
  // stop any spinners to prevent it from unintentionally swallowing output.
270
318
  // If there is an active spinner, it'll say "Error" instead of "Done"
271
- this.spinner.stop(exports.StandardColors.error('Error'));
319
+ this.spinner.stop(StandardColors.error('Error'));
272
320
  // transform an unknown error into one that conforms to the interface
273
321
  // @ts-expect-error because exitCode is not on Error
274
322
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
@@ -297,10 +345,10 @@ class SfCommand extends core_1.Command {
297
345
  this.logJson(this.toErrorJson(sfCommandError));
298
346
  }
299
347
  else {
300
- this.logToStderr(this.formatError(sfCommandError));
348
+ this.logToStderr(formatError(sfCommandError));
301
349
  }
302
350
  // Create SfError that can be thrown
303
- const err = new core_2.SfError(error.message, error.name ?? 'Error',
351
+ const err = new SfError(error.message, error.name ?? 'Error',
304
352
  // @ts-expect-error because actions is not on Error
305
353
  error.actions ?? [], process.exitCode);
306
354
  err.context = sfCommandError.context;
@@ -319,65 +367,16 @@ class SfCommand extends core_1.Command {
319
367
  process.emit('sfCommandError', err);
320
368
  throw err;
321
369
  }
322
- /**
323
- * Format errors and actions for human consumption. Adds 'Error (<ErrorCode>):',
324
- * When there are actions, we add 'Try this:' in blue
325
- * followed by each action in red on its own line.
326
- * If Error.code is present it is output last in parentheses
327
- *
328
- * @returns {string} Returns decorated messages.
329
- */
330
- formatError(error) {
331
- const colorizedArgs = [];
332
- const errorCode = typeof error.code === 'string' || typeof error.code === 'number' ? ` (${error.code})` : '';
333
- const errorPrefix = `${exports.StandardColors.error(messages.getMessage('error.prefix', [errorCode]))}`;
334
- colorizedArgs.push(`${errorPrefix} ${error.message}`);
335
- colorizedArgs.push(...this.formatActions(error.actions ?? []));
336
- if (error.stack && core_2.envVars.getString(SfCommand.SF_ENV) === core_2.Mode.DEVELOPMENT) {
337
- colorizedArgs.push(exports.StandardColors.info(`\n*** Internal Diagnostic ***\n\n${error.stack}\n******\n`));
338
- }
339
- return colorizedArgs.join('\n');
370
+ }
371
+ const assignProject = async () => {
372
+ try {
373
+ return await SfProject.resolve();
340
374
  }
341
- /**
342
- * Utility function to format actions lines
343
- *
344
- * @param actions
345
- * @param options
346
- * @private
347
- */
348
- // eslint-disable-next-line class-methods-use-this
349
- formatActions(actions, options = { actionColor: exports.StandardColors.info }) {
350
- const colorizedArgs = [];
351
- // Format any actions.
352
- if (actions?.length) {
353
- colorizedArgs.push(`\n${exports.StandardColors.info(messages.getMessage('actions.tryThis'))}\n`);
354
- actions.forEach((action) => {
355
- colorizedArgs.push(`${options.actionColor(action)}`);
356
- });
375
+ catch (err) {
376
+ if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') {
377
+ throw messages.createError('errors.RequiresProject');
357
378
  }
358
- return colorizedArgs;
379
+ throw err;
359
380
  }
360
- }
361
- exports.SfCommand = SfCommand;
362
- SfCommand.SF_ENV = 'SF_ENV';
363
- SfCommand.enableJsonFlag = true;
364
- /**
365
- * Flags that you can use for manipulating tables.
366
- *
367
- * @example
368
- * ```
369
- * import { SfCommand } from '@salesforce/sf-plugins-core';
370
- * export default class MyCommand extends SfCommand {
371
- * public static flags = {
372
- * ...SfCommand.tableFags,
373
- * 'my-flags: flags.string({ char: 'm', description: 'my flag' }),
374
- * }
375
- * }
376
- * ```
377
- */
378
- SfCommand.tableFlags = core_1.ux.table.flags;
379
- function removeEmpty(obj) {
380
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
381
- return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v != null));
382
- }
381
+ };
383
382
  //# sourceMappingURL=sfCommand.js.map
@@ -0,0 +1,24 @@
1
+ import { StructuredMessage } from '@salesforce/core';
2
+ export declare namespace SfCommand {
3
+ type Info = StructuredMessage | string;
4
+ type Warning = StructuredMessage | string;
5
+ interface Json<T> {
6
+ status: number;
7
+ result: T;
8
+ warnings?: Warning[];
9
+ }
10
+ interface Error {
11
+ status: number;
12
+ name: string;
13
+ message: string;
14
+ stack: string | undefined;
15
+ warnings?: Warning[];
16
+ actions?: string[];
17
+ code?: unknown;
18
+ exitCode?: number;
19
+ data?: unknown;
20
+ context?: string;
21
+ commandName?: string;
22
+ }
23
+ }
24
+ //# sourceMappingURL=sfCommandNamespace.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sfCommandNamespace.js.map
package/lib/stubUx.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { SinonSandbox } from 'sinon';
2
- import { SfCommand } from './sfCommand';
3
- import { Prompter, Ux } from './ux';
2
+ import { Ux } from './ux/ux.js';
4
3
  /**
5
4
  * Stub methods on the Ux class.
6
5
  * Even if you plan to make no assertions, this will silence the output to keep your test results clean
@@ -21,7 +20,7 @@ import { Prompter, Ux } from './ux';
21
20
  export declare function stubUx(sandbox: SinonSandbox): {
22
21
  log: import("sinon").SinonStub<[message?: string | undefined, ...args: string[]], void>;
23
22
  warn: import("sinon").SinonStub<[message: string | Error], void>;
24
- 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>;
23
+ table: import("sinon").SinonStub<[data: Ux.Table.Data[], columns: Ux.Table.Columns<Ux.Table.Data>, options?: import("@oclif/core/lib/cli-ux/styled/table.js").table.Options | undefined], void>;
25
24
  url: import("sinon").SinonStub<[text: string, uri: string, params?: {} | undefined], void>;
26
25
  styledHeader: import("sinon").SinonStub<[text: string], void>;
27
26
  styledObject: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson, keys?: string[] | undefined], void>;
@@ -50,9 +49,9 @@ export declare function stubSfCommandUx(sandbox: SinonSandbox): {
50
49
  logToStderr: import("sinon").SinonStub<[message?: string | undefined, ...args: any[]], void>;
51
50
  logSuccess: import("sinon").SinonStub<[message: string], void>;
52
51
  logSensitive: import("sinon").SinonStub<[msg?: string | undefined], void>;
53
- info: import("sinon").SinonStub<[input: SfCommand.Info], void>;
54
- warn: import("sinon").SinonStub<[input: SfCommand.Warning], SfCommand.Warning>;
55
- 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>;
52
+ info: import("sinon").SinonStub<[input: import("./sfCommandNamespace.js").SfCommand.Info], void>;
53
+ warn: import("sinon").SinonStub<[input: import("./sfCommandNamespace.js").SfCommand.Warning], import("./sfCommandNamespace.js").SfCommand.Warning>;
54
+ table: import("sinon").SinonStub<[data: Ux.Table.Data[], columns: Ux.Table.Columns<Ux.Table.Data>, options?: import("@oclif/core/lib/cli-ux/styled/table.js").table.Options | undefined], void>;
56
55
  url: import("sinon").SinonStub<[text: string, uri: string, params?: {} | undefined], void>;
57
56
  styledHeader: import("sinon").SinonStub<[text: string], void>;
58
57
  styledObject: import("sinon").SinonStub<[obj: import("@salesforce/ts-types").AnyJson], void>;
@@ -100,8 +99,7 @@ export declare function stubSpinner(sandbox: SinonSandbox): {
100
99
  *
101
100
  */
102
101
  export declare function stubPrompter(sandbox: SinonSandbox): {
103
- prompt: import("sinon").SinonStub<[questions: Prompter.Questions<Record<string, unknown>>, initialAnswers?: Partial<Record<string, unknown>> | undefined], Promise<Record<string, unknown>>>;
104
- confirm: import("sinon").SinonStub<[message: string, ms?: number | undefined, defaultAnswer?: boolean | undefined], Promise<boolean>>;
105
- timedPrompt: import("sinon").SinonStub<[questions: Prompter.Questions<Record<string, unknown>>, ms?: number | undefined, initialAnswers?: Partial<Record<string, unknown>> | undefined], Promise<Record<string, unknown>>>;
102
+ secret: import("sinon").SinonStub<[import("./prompts.js").PromptInputs<string>], Promise<string>>;
103
+ confirm: import("sinon").SinonStub<[import("./prompts.js").PromptInputs<boolean>], Promise<boolean>>;
106
104
  };
107
105
  //# sourceMappingURL=stubUx.d.ts.map
package/lib/stubUx.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2023, salesforce.com, inc.
4
3
  * All rights reserved.
@@ -6,10 +5,9 @@
6
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
6
  */
8
7
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.stubPrompter = exports.stubSpinner = exports.stubSfCommandUx = exports.stubUx = void 0;
11
- const sfCommand_1 = require("./sfCommand");
12
- const ux_1 = require("./ux");
8
+ import { SfCommand } from './sfCommand.js';
9
+ import { Spinner } from './ux/spinner.js';
10
+ import { Ux } from './ux/ux.js';
13
11
  /**
14
12
  * Stub methods on the Ux class.
15
13
  * Even if you plan to make no assertions, this will silence the output to keep your test results clean
@@ -27,18 +25,17 @@ const ux_1 = require("./ux");
27
25
  * ```
28
26
  *
29
27
  */
30
- function stubUx(sandbox) {
28
+ export function stubUx(sandbox) {
31
29
  return {
32
- log: sandbox.stub(ux_1.Ux.prototype, 'log'),
33
- warn: sandbox.stub(ux_1.Ux.prototype, 'warn'),
34
- table: sandbox.stub(ux_1.Ux.prototype, 'table'),
35
- url: sandbox.stub(ux_1.Ux.prototype, 'url'),
36
- styledHeader: sandbox.stub(ux_1.Ux.prototype, 'styledHeader'),
37
- styledObject: sandbox.stub(ux_1.Ux.prototype, 'styledObject'),
38
- styledJSON: sandbox.stub(ux_1.Ux.prototype, 'styledJSON'),
30
+ log: sandbox.stub(Ux.prototype, 'log'),
31
+ warn: sandbox.stub(Ux.prototype, 'warn'),
32
+ table: sandbox.stub(Ux.prototype, 'table'),
33
+ url: sandbox.stub(Ux.prototype, 'url'),
34
+ styledHeader: sandbox.stub(Ux.prototype, 'styledHeader'),
35
+ styledObject: sandbox.stub(Ux.prototype, 'styledObject'),
36
+ styledJSON: sandbox.stub(Ux.prototype, 'styledJSON'),
39
37
  };
40
38
  }
41
- exports.stubUx = stubUx;
42
39
  /**
43
40
  * Stub methods on the Ux class.
44
41
  * Even if you plan to make no assertions, this will silence the output to keep your test results clean
@@ -56,23 +53,22 @@ exports.stubUx = stubUx;
56
53
  * ```
57
54
  *
58
55
  */
59
- function stubSfCommandUx(sandbox) {
56
+ export function stubSfCommandUx(sandbox) {
60
57
  return {
61
- log: sandbox.stub(sfCommand_1.SfCommand.prototype, 'log'),
62
- logJson: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logJson'),
63
- logToStderr: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logToStderr'),
64
- logSuccess: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logSuccess'),
65
- logSensitive: sandbox.stub(sfCommand_1.SfCommand.prototype, 'logSensitive'),
66
- info: sandbox.stub(sfCommand_1.SfCommand.prototype, 'info'),
67
- warn: sandbox.stub(sfCommand_1.SfCommand.prototype, 'warn'),
68
- table: sandbox.stub(sfCommand_1.SfCommand.prototype, 'table'),
69
- url: sandbox.stub(sfCommand_1.SfCommand.prototype, 'url'),
70
- styledHeader: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledHeader'),
71
- styledObject: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledObject'),
72
- styledJSON: sandbox.stub(sfCommand_1.SfCommand.prototype, 'styledJSON'),
58
+ log: sandbox.stub(SfCommand.prototype, 'log'),
59
+ logJson: sandbox.stub(SfCommand.prototype, 'logJson'),
60
+ logToStderr: sandbox.stub(SfCommand.prototype, 'logToStderr'),
61
+ logSuccess: sandbox.stub(SfCommand.prototype, 'logSuccess'),
62
+ logSensitive: sandbox.stub(SfCommand.prototype, 'logSensitive'),
63
+ info: sandbox.stub(SfCommand.prototype, 'info'),
64
+ warn: sandbox.stub(SfCommand.prototype, 'warn'),
65
+ table: sandbox.stub(SfCommand.prototype, 'table'),
66
+ url: sandbox.stub(SfCommand.prototype, 'url'),
67
+ styledHeader: sandbox.stub(SfCommand.prototype, 'styledHeader'),
68
+ styledObject: sandbox.stub(SfCommand.prototype, 'styledObject'),
69
+ styledJSON: sandbox.stub(SfCommand.prototype, 'styledJSON'),
73
70
  };
74
71
  }
75
- exports.stubSfCommandUx = stubSfCommandUx;
76
72
  /**
77
73
  * Stub the SfCommand spinner.
78
74
  * Even if you plan to make no assertions, this will silence the output to keep your test results clean
@@ -90,13 +86,12 @@ exports.stubSfCommandUx = stubSfCommandUx;
90
86
  * ```
91
87
  *
92
88
  */
93
- function stubSpinner(sandbox) {
89
+ export function stubSpinner(sandbox) {
94
90
  return {
95
- start: sandbox.stub(ux_1.Spinner.prototype, 'start'),
96
- stop: sandbox.stub(ux_1.Spinner.prototype, 'stop'),
91
+ start: sandbox.stub(Spinner.prototype, 'start'),
92
+ stop: sandbox.stub(Spinner.prototype, 'stop'),
97
93
  };
98
94
  }
99
- exports.stubSpinner = stubSpinner;
100
95
  /**
101
96
  * Stub the SfCommand prompter.
102
97
  *
@@ -115,12 +110,10 @@ exports.stubSpinner = stubSpinner;
115
110
  * ```
116
111
  *
117
112
  */
118
- function stubPrompter(sandbox) {
113
+ export function stubPrompter(sandbox) {
119
114
  return {
120
- prompt: sandbox.stub(ux_1.Prompter.prototype, 'prompt'),
121
- confirm: sandbox.stub(ux_1.Prompter.prototype, 'confirm'),
122
- timedPrompt: sandbox.stub(ux_1.Prompter.prototype, 'timedPrompt'),
115
+ secret: sandbox.stub(SfCommand.prototype, 'secretPrompt'),
116
+ confirm: sandbox.stub(SfCommand.prototype, 'confirm'),
123
117
  };
124
118
  }
125
- exports.stubPrompter = stubPrompter;
126
119
  //# sourceMappingURL=stubUx.js.map