simple-git
Version:
Simple GIT interface for node.js
195 lines • 8.52 kB
TypeScript
import type { SpawnOptions } from 'child_process';
import type { VulnerabilityCategoryFlags } from '@simple-git/argv-parser';
import type { SimpleGitProgressEvent } from './handlers';
import type { SimpleGitTask } from './tasks';
export * from './handlers';
export * from './tasks';
/**
* Most tasks accept custom options as an array of strings as well as the
* options object. Unless the task is explicitly documented as such, the
* tasks will not accept both formats at the same time, preferring whichever
* appears last in the arguments.
*/
export type TaskOptions<O extends Options = Options> = string[] | O;
/**
* Options supplied in most tasks as an optional trailing object
*/
export type OptionsValues = null | string | number | (string | number)[];
export type Options = Record<string, OptionsValues>;
export type OptionFlags<FLAGS extends string, VALUE = null> = Partial<Record<FLAGS, VALUE>>;
/**
* A function called by the executor immediately after creating a child
* process. Allows the calling application to implement custom handling of
* the incoming stream of data from the `git`.
*/
export type outputHandler = (command: string, stdout: NodeJS.ReadableStream, stderr: NodeJS.ReadableStream, args: string[]) => void;
/**
* Environment variables to be passed into the child process.
*/
export type GitExecutorEnv = NodeJS.ProcessEnv | undefined;
/**
* Public interface of the Executor
*/
export interface SimpleGitExecutor {
env: GitExecutorEnv;
outputHandler?: outputHandler;
cwd: string;
chain(): SimpleGitExecutor;
push<R>(task: SimpleGitTask<R>): Promise<R>;
}
/**
* The resulting output from running the git child process
*/
export interface GitExecutorResult {
stdOut: Buffer[];
stdErr: Buffer[];
exitCode: number;
rejection: Maybe<Error>;
}
export interface SimpleGitPluginConfig {
abort: AbortSignal;
/**
* Environment variables in the guarded `GitEnvKeys` set (every `GIT_`-prefixed
* key plus known-vulnerable non-prefixed keys such as `EDITOR` / `PAGER`) are
* removed from the child process environment unless named here. A guarded key
* supplied explicitly through `.env()` and not named here rejects the task it
* is used with; guarded keys inherited from the ambient environment are
* stripped and logged to the `debug` output.
*
* Naming a key here also permits it past the unsafe-operations check (for example
* `GIT_SSH_COMMAND` no longer also needs `unsafe.allowUnsafeSshCommand`), with the
* exception of `GIT_CONFIG_PARAMETERS` which still needs `unsafe.allowUnsafeConfigEnvCount`
* because its content cannot be checked against `allowConfig`.
*/
allowEnvironment: readonly string[];
/**
* Configuration keys that may be set by tasks run through this instance, whether through
* the `config` option, `-c` / `--config-env` arguments, `git config` writes or the
* `GIT_CONFIG_KEY_<n>` environment variables.
*
* A built-in list of keys that cannot be used to run programs, load files, redirect
* network traffic or turn off `git` safety checks is always allowed (see the
* `SAFE_CONFIG_KEYS` export of `@simple-git/argv-parser`). Use this option to allow any
* other key; patterns are case-insensitive and `*` matches any characters, for example:
*
* ```typescript
* simpleGit({ allowConfig: ['core.sshCommand', 'http.proxy', 'filter.lfs.*'] });
* ```
*
* Keys named here are permitted even when they are also covered by one of the
* `unsafe.allowUnsafe*` categories.
*/
allowConfig: readonly string[];
/**
* Enables strict mode, throws an exception when attempting to write to any Git config keys or use any
* Git impacting environment variables without explicitly enabling them with the `allowEnvironment` and
* `allowConfig` properties. Strict mode implies the use of `unsafe.recommended`.
*
* Without strict mode, exceptions are logged to the process rather than thrown.
*
* Defaults to `false`, this will become the default behaviour in a future major version.
*/
strict: boolean;
/**
* Name of the binary the child processes will spawn - defaults to `git`,
* supply as a tuple to enable the use of platforms that require `git` to be
* called through an alternative binary (eg: `wsl git ...`).
* Note: commands supplied in this way support a restricted set of characters
* and should not be used as a way to supply arbitrary config arguments etc.
*/
binary: string | [string] | [string, string];
/**
* Configures the events that should be used to determine when the unederlying child process has
* been terminated.
*
* Version 2 will default to use `onClose=true, onExit=50` to mean the `close` event will be
* used to immediately treat the child process as closed and start using the data from `stdOut`
* / `stdErr`, whereas the `exit` event will wait `50ms` before treating the child process
* as closed.
*
* This will be changed in version 3 to use `onClose=true, onExit=false` so that only the
* close event is used to determine the termination of the process.
*/
completion: {
onClose?: boolean | number;
onExit?: boolean | number;
};
/**
* Configures the content of errors thrown by the `simple-git` instance for each task
*/
errors(error: Buffer | Error | undefined, result: Omit<GitExecutorResult, 'rejection'>): Buffer | Error | undefined;
input(commands: readonly string[]): Buffer | string | undefined;
/**
* Handler to be called with progress events emitted through the progress plugin
*/
progress(data: SimpleGitProgressEvent): void;
/**
* Configuration for the `timeoutPlugin`
*/
timeout: {
/**
* The number of milliseconds to wait after spawning the process / receiving
* content on the stdOut/stdErr streams before forcibly closing the git process.
*/
block: number;
/**
* Reset timeout plugin after receiving data on `stdErr` - set to `false` to ignore
* `stdErr` content when determining whether to kill the process (defaults to `true`).
*/
stdErr?: boolean;
/**
* Reset timeout plugin after receiving data on `stdOut` - set to `false` to ignore
* `stdOut` content when determining whether to kill the process (defaults to `true`).
*/
stdOut?: boolean;
};
spawnOptions: Pick<SpawnOptions, 'uid' | 'gid'>;
unsafe: Partial<VulnerabilityCategoryFlags & {
/**
* Enables the recommended checks, blocking vulnerabilities caught by the broader catch-all
* rules (for example any configuration key ending in `.cmd` or `command`, which require
* `allowUnsafeCommandBinaries` or naming the key in `allowConfig`).
*
* Defaults to `false`, will default to `true` in the next major version. Implied by
* `strict: true`.
*/
recommended: boolean;
/**
* Allows potentially unsafe values to be supplied in the `binary` configuration option and
* `git.customBinary()` method call.
*/
allowUnsafeCustomBinary: boolean;
/**
* Allows the use of abbreviated long-form options in `git` commands.
* Enabling this option is only safe in environments where data supplied to `simple-git` is always sanitised
* as it can be a route to bypassing vulnerability checks.
*/
allowAbbreviatedOptions: boolean;
}>;
}
/**
* Optional configuration settings to be passed to the `simpleGit`
* builder.
*/
export interface SimpleGitOptions extends Partial<SimpleGitPluginConfig> {
/**
* Base directory for all tasks run through this `simple-git` instance
*/
baseDir: string;
/**
* Limit for the number of child processes that will be spawned concurrently from a `simple-git` instance
*/
maxConcurrentProcesses: number;
/**
* Per-command configuration parameters to be passed with the `-c` switch to `git`
*/
config: string[];
/**
* Enable trimming of trailing white-space in `git.raw`
*/
trimmed: boolean;
}
export type Maybe<T> = T | undefined;
export type MaybeArray<T> = T | T[];
export type Primitives = string | number | boolean;
//# sourceMappingURL=index.d.ts.map