import type { ReadConfigOptions } from '@ms-cloudpack/config'; import type { CommandAction, CommandExitParams } from '../types/CommandAction.js'; import type { ProgramOptions } from '../types/ProgramOptions.js'; import type { SharedOptions } from '../types/SharedOptions.js'; import type { ReusedOptions } from '../types/ReusedOptions.js'; import type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.js'; export interface CommandExecutorParams { /** Command-specific arguments */ args: string[]; /** Command-specific and shared options. */ options: TOptions; /** Function to execute the command. */ execute: CommandAction; /** Shared program-level configuration. */ programOptions: ProgramOptions; /** Verb being run, e.g. `bundle` or `cache clean`. */ verb: string; /** * By default, the command will run against `cwd` (usually `process.cwd()`). * If this option is set, attempt to discover app path(s) instead. * (`cwd` will still be preferred if it has a `cloudpack.config.json`.) * See {@link AppPathDiscoveryMode} for details. * * Note that `isMultiApp` elsewhere will only be true if this is set to `'multi'` and * multiple apps are found. */ discoverAppPaths: AppPathDiscoveryMode | undefined; /** * Whether to set `TaskReporter`'s `enableReset` option, which enables resetting console output. * This should only be true for commands like start which use watch mode, and needs to be set at * the beginning instead of being toggled by the command to ensure everything is captured. * (If true, the screen will also be cleared on startup.) */ enableReporterReset: boolean | undefined; /** * Apply any command-specific CLI options that need to be passed through to `readConfig`. * (Shared and reused options are applied automatically.) */ applyOptionsToConfig: ((options: Omit) => Pick | undefined) | undefined; } /** * This class manages orchestration and shared state while executing a command. */ export declare class CommandExecutor { private _options; private _execute; private _programOptions; private _verb; private _discoverAppPaths; private _enableReporterReset; private _applyOptionsToConfig; private _reporter; /** Items which should be disposed before a restart, as well as at process exit */ private _autoDisposableList; /** Items which should be disposed before exit only */ private _finalDisposableList; private _hasCalledExit; private _args; private _sigintCount; private _onInterrupt?; private _getMessageOnInterrupt?; /** Active `CommandExecutor` instances. In tests, there may be more than one. */ private static _activeInstances; /** Mock implementation of `process.exit` for testing purposes. */ private static _mockProcessExit; /** * Set a mock `process.exit()` implementation for tests, to handle cases where the command would * call `process.exit()`. */ static mockProcessExitForTests(mockImpl: typeof process.exit | undefined): void; /** * For testing use only: end all active CommandExecutor instances and call `process.exit()` * (which should be mocked by the test). */ static exitAllForTests(params: CommandExitParams): Promise; /** * Get a list of the commands that are running, including their arguments. */ static getRunningCommands(): string[]; constructor(params: CommandExecutorParams); /** * Run the command, including handling for restarts. This should only be called once per instance, * immediately after the constructor (since constructors can't be async). */ execute(): Promise; /** * Execute a single iteration of the command. * @returns true if a restart is needed */ private _executeOnce; /** * Determine the app paths and initialize the context for each app. * @returns Context(s), or an exit options object if there was an error. (might also throw on error) */ private _initializeContexts; /** Translate certain CLI options into options for `readConfig()`. */ private _getConfigOptionsFromCliOptions; private _initTelemetry; private _sigintHandler; private _uncaughtExceptionHandler; private _unexpectedErrorHandler; /** * Exit function called with the result returned by the command's execute function, * or manually via `CommandExecutor.exitAll()` in tests. * * Except in tests, execution can be assumed to have stopped after this is called. * (In tests, `process.exit` is probably mocked to throw.) */ private _exit; /** Call the mocked or real `process.exit()` function */ private _callProcessExit; } //# sourceMappingURL=CommandExecutor.d.ts.map