/** * Which shell runs a command, and in what shape the command reaches it (ADR-0008; the * defaults and the Windows search in ADR-0022). * * The choice is configuration, not guesswork: the environment names the shell, one * call may override it, and every value that cannot be honoured is refused with the * key and the value that caused it. A wrong shell silently replaced by the default * would run someone's POSIX script through cmd and blame the command. * * Both platforms default to bash — on Windows the one beside the user's git, or the * Git Bash pi was started from — because one pen writes the commands on every host; * `cmd.exe`, the user's `$SHELL` and `sh` are explicit choices. The invocation shape * differs by dialect, not by executable: `cmd` needs one verbatim quoted argument, * everything POSIX-shaped takes the command as a normal argv entry. * * @author mystery4f <40482524+mystery4f@users.noreply.github.com> */ /** Windows: `cmd` or `bash`. */ export declare const SHELL_ENV = "PI_PRETTY_TASK_SHELL"; /** Windows: absolute path of the shell `SHELL_ENV` names. */ export declare const SHELL_PATH_ENV = "PI_PRETTY_TASK_SHELL_PATH"; /** POSIX: `inherit`, `bash` or `sh`. */ export declare const POSIX_SHELL_ENV = "PI_PRETTY_TASK_POSIX_SHELL"; /** POSIX: absolute path of the shell `POSIX_SHELL_ENV` names. */ export declare const POSIX_SHELL_PATH_ENV = "PI_PRETTY_TASK_POSIX_SHELL_PATH"; /** Shells a policy can name. `inherit` exists only on POSIX: the user's own shell. */ export type ShellName = "cmd" | "bash" | "sh" | "inherit"; /** What one call may ask for: its own shell, or whatever the environment configured. */ export type ShellChoice = "default" | "cmd" | "bash" | "sh"; /** A chosen shell and the executable it resolved to. */ export interface ShellPolicy { readonly name: ShellName; /** Absolute path, except for the bare `cmd.exe` a Windows host always finds. */ readonly executable: string; } /** How one command is handed to its shell. */ export interface ShellInvocation { readonly executable: string; readonly args: readonly string[]; readonly windowsVerbatimArguments: boolean; } /** * Whether a candidate is an executable this platform would run. A seam: the policy * tests must not depend on which shells the machine running them happens to have. */ export type ExecutableProbe = (candidate: string) => boolean; /** * Runs a discovery command such as `where` and returns its stdout; undefined when the * command fails. A seam like the probe: the policy tests must not depend on the machine. */ export type CommandRunner = (file: string, args: readonly string[]) => string | undefined; export interface ShellPolicyOptions { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv; /** Defaults to a real filesystem check for the target platform. */ probe?: ExecutableProbe; /** Defaults to a real child process; Windows discovery asks `where` and `reg` through it. */ run?: CommandRunner; } /** * The shell this platform will use, resolved from the environment once at load time: * a value that cannot be honoured has to fail the load, not every task. */ export declare function resolveShellPolicy(options?: ShellPolicyOptions): ShellPolicy; /** * Resolve one call's shell: `default` keeps the configured policy untouched, any * other value has to be one this platform actually offers. A configured path is * reused only when the override names the same shell — it belongs to that shell. */ export declare function selectShell(policy: ShellPolicy, choice: ShellChoice | undefined, options?: ShellPolicyOptions): ShellPolicy; /** * The argument shape for a policy. * * `cmd` gets `/d /s /c ""` with verbatim arguments, exactly as a terminal * does, so builtins, `&&` and quoted paths behave the same: `/d` skips AutoRun * registry commands, `/s` makes the outer quote pair be stripped rather than * reinterpreted, and verbatim arguments stop Node from re-quoting anything we pass. * * Everything else — POSIX shells and a Windows bash — takes `-c` and a normally * escaped argv entry; no `-l`, so no login-shell startup files run and the command * sees the environment pi was started with. */ export declare function shellInvocation(policy: ShellPolicy, command: string): ShellInvocation;