import { SpawnOptionsWithoutStdio } from 'node:child_process'; import { SfError } from '@salesforce/core'; import { Duration } from '@salesforce/kit'; import { AnyJson, Many } from '@salesforce/ts-types'; import { ExecOptions, ShellString } from 'shelljs'; export type CLI = 'inherit' | 'sfdx' | 'sf' | 'dev'; type BaseExecOptions = { /** * Throws if this exit code is not returned by the child process. */ ensureExitCode?: number | 'nonZero'; /** * The executable that should be used for execCmd. * - inherit uses TESTKIT_EXECUTABLE_PATH to determine the executable. If it's not set it defaults to the local bin/dev * - sfdx refers to the globally installed sf executable * - sf refers to the globally installed sf executable */ cli?: CLI; }; export type ExecCmdOptions = ExecOptions & BaseExecOptions & ({ cwd: string; } | { cwd?: never; }); type ExcludeMethods = Pick any ? never : K; }[keyof T]>>; export type JsonOutput = { status: number; result: T; warnings: string[]; } & Partial>; export type ExecCmdResult = { /** * Command output parsed as JSON, if `--json` param present. */ jsonOutput?: JsonOutput; /** * Command output from the shell. * * @see https://www.npmjs.com/package/shelljs#execcommand--options--callback */ shellOutput: ShellString; /** * The JsonParseError if parsing failed. */ jsonError?: Error; /** * Command execution duration. */ execCmdDuration: Duration; }; /** * Determine the executable path for use by `execCmd`. * * If the cli is 'inherit', the executable preference order is: * 1. TESTKIT_EXECUTABLE_PATH env var * 2. `bin/run.js` (default) * * @returns The command string with CLI executable. E.g., `"node_modules/bin/sf org:create:user -a testuser1"` */ export declare const determineExecutable: (cli?: CLI) => string; /** * Synchronously execute a command with the provided options in a child process. * * Option defaults: * 1. `cwd` = process.cwd() * 2. `timeout` = 3,600,000 (1 hour) * 3. `env` = process.env * 4. `silent` = true (child process output not written to the console) * 5. `cli` = 'inherit' (use the TESTKIT_EXECUTABLE_PATH env var or `bin/dev` if not set for executing commands) * * Other defaults: * * @see www.npmjs.com/package/shelljs#execcommand--options--callback * @see www.nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback * * @param cmd The command string to be executed by a child process. * @param options The options used to run the command. * @returns The child process exit code, stdout, stderr, cmd run time, and the parsed JSON if `--json` param present. */ export declare function execCmd(cmd: string, options?: ExecCmdOptions & { async?: false; }): ExecCmdResult; export declare function execCmd(cmd: string, options: ExecCmdOptions & { async: true; }): Promise>; export declare enum Interaction { DOWN = "\u001B[B", UP = "\u001B[A", ENTER = "\r", SELECT = " ", Yes = "Y\r", No = "N\r", BACKSPACE = "\b", ALL = "a" } export type InteractiveCommandExecutionResult = { code: number | null; stdout: string; stderr: string; duration: Duration; }; export type InteractiveCommandExecutionOptions = BaseExecOptions & SpawnOptionsWithoutStdio; /** * A map of questions and answers to be used in an interactive command. * * The questions are strings that will be used to match the question asked by the command. */ export type PromptAnswers = Record>; /** * Execute an interactive command. * * @example * ``` * import { TestSession, execInteractiveCmd, Interaction } from '@salesforce/cli-plugins-testkit'; * * const result = await execInteractiveCmd( * 'dev generate plugin', * { * 'internal Salesforce team': Interaction.Yes, * 'name of your new plugin': ['plugin-awesome', Interaction.ENTER], * 'description for your plugin': ['a description', Interaction.ENTER], * 'Select the existing "sf" commands you plan to extend': [ * Interaction.SELECT, * Interaction.DOWN, * Interaction.SELECT, * Interaction.ENTER, * ], * }, * { cwd: session.dir, ensureExitCode: 0 } * ); * ``` * * If your flag values included spaces (where you'd normally need quotes like `some:cmd --flag "value with spaces"`), * use an array of strings to represent the command ex: `['some:cmd', '--flag', 'value with spaces']` */ export declare function execInteractiveCmd(command: string | string[], answers: PromptAnswers, options?: InteractiveCommandExecutionOptions): Promise; export declare class Cache extends Map { private static instance; static getInstance(): Cache; } export {};