UNPKG

3.79 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ChildProcess, ForkOptions, SpawnOptions } from 'child_process';
3export declare const ERROR_COMMAND_NOT_FOUND = "ERR_SUBPROCESS_COMMAND_NOT_FOUND";
4export declare const ERROR_NON_ZERO_EXIT = "ERR_SUBPROCESS_NON_ZERO_EXIT";
5export declare const ERROR_SIGNAL_EXIT = "ERR_SUBPROCESS_SIGNAL_EXIT";
6export declare const TILDE_PATH_REGEX: RegExp;
7export declare function expandTildePath(p: string): string;
8/**
9 * Prepare the PATH environment variable for use with subprocesses.
10 *
11 * If a raw tilde is found in PATH, e.g. `~/.bin`, it is expanded. The raw
12 * tilde works in Bash, but not in Node's `child_process` outside of a shell.
13 *
14 * This is a utility method. You do not need to use it with `Subprocess`.
15 *
16 * @param path Defaults to `process.env.PATH`
17 */
18export declare function convertPATH(path?: string): string;
19export declare class SubprocessError extends Error {
20 readonly name = "SubprocessError";
21 message: string;
22 stack: string;
23 code?: typeof ERROR_COMMAND_NOT_FOUND | typeof ERROR_NON_ZERO_EXIT | typeof ERROR_SIGNAL_EXIT;
24 error?: Error;
25 output?: string;
26 signal?: string;
27 exitCode?: number;
28 constructor(message: string);
29}
30export interface SubprocessOptions extends SpawnOptions {
31}
32export interface SubprocessBashifyOptions {
33 /**
34 * Mask file path to first argument.
35 *
36 * The first argument to subprocesses is the program name or path, e.g.
37 * `/path/to/bin/my-program`. If `true`, `bashify()` will return the program
38 * name without a file path, e.g. `my-program`.
39 *
40 * The default is `true`.
41 */
42 maskArgv0?: boolean;
43 /**
44 * Mask file path to second argument.
45 *
46 * In some subprocesses, the second argument is a script file to run, e.g.
47 * `node ./scripts/post-install`. If `true`, `bashify()` will return the
48 * script name without a file path, e.g. `node post-install`.
49 *
50 * The default is `false`.
51 */
52 maskArgv1?: boolean;
53 /**
54 * Remove the first argument from output.
55 *
56 * Useful to make a command such as `node ./scripts/post-install` appear as
57 * simply `post-install`.
58 *
59 * The default is `false`.
60 */
61 shiftArgv0?: boolean;
62}
63export declare class Subprocess {
64 name: string;
65 args: readonly string[];
66 protected readonly path?: string;
67 protected _options: SpawnOptions;
68 constructor(name: string, args: readonly string[], options?: SubprocessOptions);
69 get options(): Readonly<SpawnOptions>;
70 output(): Promise<string>;
71 combinedOutput(): Promise<string>;
72 run(): Promise<void> & {
73 p: ChildProcess;
74 };
75 spawn(): ChildProcess;
76 bashify({ maskArgv0, maskArgv1, shiftArgv0 }?: SubprocessBashifyOptions): string;
77 bashifyArg(arg: string): string;
78 maskArg(arg: string): string;
79}
80export declare function spawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
81export declare function fork(modulePath: string, args?: readonly string[], options?: ForkOptions & Pick<SpawnOptions, 'stdio'>): ChildProcess;
82export interface WhichOptions {
83 PATH?: string;
84 PATHEXT?: string;
85}
86/**
87 * Find the first instance of a program in PATH.
88 *
89 * If `program` contains a path separator, this function will merely return it.
90 *
91 * @param program A command name, such as `ionic`
92 */
93export declare function which(program: string, { PATH, PATHEXT }?: WhichOptions): Promise<string>;
94/**
95 * Find all instances of a program in PATH.
96 *
97 * If `program` contains a path separator, this function will merely return it
98 * inside an array.
99 *
100 * @param program A command name, such as `ionic`
101 */
102export declare function findExecutables(program: string, { PATH, PATHEXT }?: WhichOptions): Promise<string[]>;