UNPKG

6.35 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3/// <reference types="node" />
4/// <reference types="node" />
5import type { SpawnOptions } from 'child_process';
6import type { SimpleGitTask } from './tasks';
7import type { SimpleGitProgressEvent } from './handlers';
8export * from './handlers';
9export * from './tasks';
10/**
11 * Most tasks accept custom options as an array of strings as well as the
12 * options object. Unless the task is explicitly documented as such, the
13 * tasks will not accept both formats at the same time, preferring whichever
14 * appears last in the arguments.
15 */
16export declare type TaskOptions<O extends Options = Options> = string[] | O;
17/**
18 * Options supplied in most tasks as an optional trailing object
19 */
20export declare type OptionsValues = null | string | number;
21export declare type Options = Record<string, OptionsValues>;
22export declare type OptionFlags<FLAGS extends string, VALUE = null> = Partial<Record<FLAGS, VALUE>>;
23/**
24 * A function called by the executor immediately after creating a child
25 * process. Allows the calling application to implement custom handling of
26 * the incoming stream of data from the `git`.
27 */
28export declare type outputHandler = (command: string, stdout: NodeJS.ReadableStream, stderr: NodeJS.ReadableStream, args: string[]) => void;
29/**
30 * Environment variables to be passed into the child process.
31 */
32export declare type GitExecutorEnv = NodeJS.ProcessEnv | undefined;
33/**
34 * Public interface of the Executor
35 */
36export interface SimpleGitExecutor {
37 env: GitExecutorEnv;
38 outputHandler?: outputHandler;
39 cwd: string;
40 chain(): SimpleGitExecutor;
41 push<R>(task: SimpleGitTask<R>): Promise<R>;
42}
43/**
44 * The resulting output from running the git child process
45 */
46export interface GitExecutorResult {
47 stdOut: Buffer[];
48 stdErr: Buffer[];
49 exitCode: number;
50 rejection: Maybe<Error>;
51}
52export interface SimpleGitPluginConfig {
53 abort: AbortSignal;
54 /**
55 * Name of the binary the child processes will spawn - defaults to `git`,
56 * supply as a tuple to enable the use of platforms that require `git` to be
57 * called through an alternative binary (eg: `wsl git ...`).
58 * Note: commands supplied in this way support a restricted set of characters
59 * and should not be used as a way to supply arbitrary config arguments etc.
60 */
61 binary: string | [string] | [string, string];
62 /**
63 * Configures the events that should be used to determine when the unederlying child process has
64 * been terminated.
65 *
66 * Version 2 will default to use `onClose=true, onExit=50` to mean the `close` event will be
67 * used to immediately treat the child process as closed and start using the data from `stdOut`
68 * / `stdErr`, whereas the `exit` event will wait `50ms` before treating the child process
69 * as closed.
70 *
71 * This will be changed in version 3 to use `onClose=true, onExit=false` so that only the
72 * close event is used to determine the termination of the process.
73 */
74 completion: {
75 onClose?: boolean | number;
76 onExit?: boolean | number;
77 };
78 /**
79 * Configures the content of errors thrown by the `simple-git` instance for each task
80 */
81 errors(error: Buffer | Error | undefined, result: Omit<GitExecutorResult, 'rejection'>): Buffer | Error | undefined;
82 /**
83 * Handler to be called with progress events emitted through the progress plugin
84 */
85 progress(data: SimpleGitProgressEvent): void;
86 /**
87 * Configuration for the `timeoutPlugin`
88 */
89 timeout: {
90 /**
91 * The number of milliseconds to wait after spawning the process / receiving
92 * content on the stdOut/stdErr streams before forcibly closing the git process.
93 */
94 block: number;
95 /**
96 * Reset timeout plugin after receiving data on `stdErr` - set to `false` to ignore
97 * `stdErr` content when determining whether to kill the process (defaults to `true`).
98 */
99 stdErr?: boolean;
100 /**
101 * Reset timeout plugin after receiving data on `stdOut` - set to `false` to ignore
102 * `stdOut` content when determining whether to kill the process (defaults to `true`).
103 */
104 stdOut?: boolean;
105 };
106 spawnOptions: Pick<SpawnOptions, 'uid' | 'gid'>;
107 unsafe: {
108 /**
109 * Allows potentially unsafe values to be supplied in the `binary` configuration option and
110 * `git.customBinary()` method call.
111 */
112 allowUnsafeCustomBinary?: boolean;
113 /**
114 * By default `simple-git` prevents the use of inline configuration
115 * options to override the protocols available for the `git` child
116 * process to prevent accidental security vulnerabilities when
117 * unsanitised user data is passed directly into operations such as
118 * `git.addRemote`, `git.clone` or `git.raw`.
119 *
120 * Enable this override to use the `ext::` protocol (see examples on
121 * [git-scm.com](https://git-scm.com/docs/git-remote-ext#_examples)).
122 */
123 allowUnsafeProtocolOverride?: boolean;
124 /**
125 * Given the possibility of using `--upload-pack` and `--receive-pack` as
126 * attack vectors, the use of these in any command (or the shorthand
127 * `-u` option in a `clone` operation) are blocked by default.
128 *
129 * Enable this override to permit the use of these arguments.
130 */
131 allowUnsafePack?: boolean;
132 };
133}
134/**
135 * Optional configuration settings to be passed to the `simpleGit`
136 * builder.
137 */
138export interface SimpleGitOptions extends Partial<SimpleGitPluginConfig> {
139 /**
140 * Base directory for all tasks run through this `simple-git` instance
141 */
142 baseDir: string;
143 /**
144 * Limit for the number of child processes that will be spawned concurrently from a `simple-git` instance
145 */
146 maxConcurrentProcesses: number;
147 /**
148 * Per-command configuration parameters to be passed with the `-c` switch to `git`
149 */
150 config: string[];
151 /**
152 * Enable trimming of trailing white-space in `git.raw`
153 */
154 trimmed: boolean;
155}
156export declare type Maybe<T> = T | undefined;
157export declare type MaybeArray<T> = T | T[];
158export declare type Primitives = string | number | boolean;