UNPKG

3.72 kBTypeScriptView Raw
1/// <reference types="node" />
2import { SpawnOptions } from 'child_process';
3import { SimpleGitTask } from './tasks';
4import { SimpleGitProgressEvent } from './handlers';
5export * from './handlers';
6export * from './tasks';
7/**
8 * Most tasks accept custom options as an array of strings as well as the
9 * options object. Unless the task is explicitly documented as such, the
10 * tasks will not accept both formats at the same time, preferring whichever
11 * appears last in the arguments.
12 */
13export declare type TaskOptions<O extends Options = Options> = string[] | O;
14/**
15 * Options supplied in most tasks as an optional trailing object
16 */
17export declare type OptionsValues = null | string | number;
18export declare type Options = Record<string, OptionsValues>;
19export declare type OptionFlags<FLAGS extends string, VALUE = null> = Partial<Record<FLAGS, VALUE>>;
20/**
21 * A function called by the executor immediately after creating a child
22 * process. Allows the calling application to implement custom handling of
23 * the incoming stream of data from the `git`.
24 */
25export declare type outputHandler = (command: string, stdout: NodeJS.ReadableStream, stderr: NodeJS.ReadableStream, args: string[]) => void;
26/**
27 * Environment variables to be passed into the child process.
28 */
29export declare type GitExecutorEnv = NodeJS.ProcessEnv | undefined;
30/**
31 * Public interface of the Executor
32 */
33export interface SimpleGitExecutor {
34 env: GitExecutorEnv;
35 outputHandler?: outputHandler;
36 binary: string;
37 cwd: string;
38 chain(): SimpleGitExecutor;
39 push<R>(task: SimpleGitTask<R>): Promise<R>;
40}
41/**
42 * The resulting output from running the git child process
43 */
44export interface GitExecutorResult {
45 stdOut: Buffer[];
46 stdErr: Buffer[];
47 exitCode: number;
48 rejection: Maybe<Error>;
49}
50export interface SimpleGitPluginConfig {
51 /**
52 * Configures the events that should be used to determine when the unederlying child process has
53 * been terminated.
54 *
55 * Version 2 will default to use `onClose=true, onExit=50` to mean the `close` event will be
56 * used to immediately treat the child process as closed and start using the data from `stdOut`
57 * / `stdErr`, whereas the `exit` event will wait `50ms` before treating the child process
58 * as closed.
59 *
60 * This will be changed in version 3 to use `onClose=true, onExit=false` so that only the
61 * close event is used to determine the termination of the process.
62 */
63 completion: {
64 onClose?: boolean | number;
65 onExit?: boolean | number;
66 };
67 /**
68 * Configures the content of errors thrown by the `simple-git` instance for each task
69 */
70 errors(error: Buffer | Error | undefined, result: Omit<GitExecutorResult, 'rejection'>): Buffer | Error | undefined;
71 /**
72 * Handler to be called with progress events emitted through the progress plugin
73 */
74 progress(data: SimpleGitProgressEvent): void;
75 /**
76 * Configuration for the `timeoutPlugin`
77 */
78 timeout: {
79 /**
80 * The number of milliseconds to wait after spawning the process / receiving
81 * content on the stdOut/stdErr streams before forcibly closing the git process.
82 */
83 block: number;
84 };
85 spawnOptions: Pick<SpawnOptions, 'uid' | 'gid'>;
86}
87/**
88 * Optional configuration settings to be passed to the `simpleGit`
89 * builder.
90 */
91export interface SimpleGitOptions extends Partial<SimpleGitPluginConfig> {
92 baseDir: string;
93 binary: string;
94 maxConcurrentProcesses: number;
95 config: string[];
96}
97export declare type Maybe<T> = T | undefined;
98export declare type MaybeArray<T> = T | T[];
99export declare type Primitives = string | number | boolean;