UNPKG

2.68 kBTypeScriptView Raw
1import { ChildProcess } from "child_process";
2import { Disposable, HandleableErrorEvent } from "../index";
3
4/**
5 * A wrapper which provides standard error/output line buffering for
6 * Node's ChildProcess.
7 */
8export class BufferedProcess {
9 readonly process?: ChildProcess | undefined;
10
11 constructor(options: ProcessOptions);
12
13 // Event Subscription
14 /**
15 * Will call your callback when an error will be raised by the process. Usually
16 * this is due to the command not being available or not on the PATH. You can
17 * call handle() on the object passed to your callback to indicate that you
18 * have handled this error.
19 */
20 onWillThrowError(callback: (errorObject: HandleableErrorEvent) => void): Disposable;
21
22 // Helper Methods
23 /** Terminate the process. */
24 kill(): void;
25
26 /** Runs the process. */
27 start(): void;
28}
29
30export interface NodeProcessOptions {
31 /** The command to execute. */
32 command: string;
33
34 /** The array of arguments to pass to the command. */
35 args?: readonly string[] | undefined;
36
37 /** The options object to pass to Node's ChildProcess.spawn method. */
38 options?: SpawnProcessOptions | undefined;
39
40 /**
41 * The callback that receives a single argument which contains the standard
42 * output from the command.
43 */
44 stdout?(data: string): void;
45
46 /**
47 * The callback that receives a single argument which contains the standard
48 * error output from the command.
49 */
50 stderr?(data: string): void;
51
52 /** The callback which receives a single argument containing the exit status. */
53 exit?(code: number): void;
54}
55
56export interface ProcessOptions extends NodeProcessOptions {
57 /**
58 * Whether the command will automatically start when this BufferedProcess is
59 * created.
60 */
61 autoStart?: boolean | undefined;
62}
63
64export interface SpawnProcessOptions {
65 /** Current working directory of the child process. */
66 cwd?: string | undefined;
67
68 /** Environment key-value pairs. */
69 env?: { [key: string]: string } | undefined;
70
71 /** The child's stdio configuration. */
72 stdio?: string | Array<string | number> | undefined;
73
74 /** Prepare child to run independently of its parent process. */
75 detached?: boolean | undefined;
76
77 /** Sets the user identity of the process. */
78 uid?: number | undefined;
79
80 /** Sets the group identity of the process. */
81 gid?: number | undefined;
82
83 /**
84 * If true, runs command inside of a shell. Uses "/bin/sh" on UNIX, and process.env.ComSpec
85 * on Windows. A different shell can be specified as a string.
86 */
87 shell?: boolean | string | undefined;
88}