UNPKG

3.69 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 code?: typeof ERROR_COMMAND_NOT_FOUND | typeof ERROR_NON_ZERO_EXIT | typeof ERROR_SIGNAL_EXIT;
22 output?: string;
23 signal?: string;
24 exitCode?: number;
25}
26export interface SubprocessOptions extends SpawnOptions {
27}
28export interface SubprocessBashifyOptions {
29 /**
30 * Mask file path to first argument.
31 *
32 * The first argument to subprocesses is the program name or path, e.g.
33 * `/path/to/bin/my-program`. If `true`, `bashify()` will return the program
34 * name without a file path, e.g. `my-program`.
35 *
36 * The default is `true`.
37 */
38 maskArgv0?: boolean;
39 /**
40 * Mask file path to second argument.
41 *
42 * In some subprocesses, the second argument is a script file to run, e.g.
43 * `node ./scripts/post-install`. If `true`, `bashify()` will return the
44 * script name without a file path, e.g. `node post-install`.
45 *
46 * The default is `false`.
47 */
48 maskArgv1?: boolean;
49 /**
50 * Remove the first argument from output.
51 *
52 * Useful to make a command such as `node ./scripts/post-install` appear as
53 * simply `post-install`.
54 *
55 * The default is `false`.
56 */
57 shiftArgv0?: boolean;
58}
59export declare class Subprocess {
60 name: string;
61 args: readonly string[];
62 protected readonly path?: string;
63 protected _options: SpawnOptions;
64 constructor(name: string, args: readonly string[], options?: SubprocessOptions);
65 get options(): Readonly<SpawnOptions>;
66 output(): Promise<string>;
67 combinedOutput(): Promise<string>;
68 run(): Promise<void> & {
69 p: ChildProcess;
70 };
71 spawn(): ChildProcess;
72 bashify({ maskArgv0, maskArgv1, shiftArgv0 }?: SubprocessBashifyOptions): string;
73 bashifyArg(arg: string): string;
74 maskArg(arg: string): string;
75}
76export declare function spawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
77export declare function fork(modulePath: string, args?: readonly string[], options?: ForkOptions & Pick<SpawnOptions, 'stdio'>): ChildProcess;
78export interface WhichOptions {
79 PATH?: string;
80 PATHEXT?: string;
81}
82/**
83 * Find the first instance of a program in PATH.
84 *
85 * If `program` contains a path separator, this function will merely return it.
86 *
87 * @param program A command name, such as `ionic`
88 */
89export declare function which(program: string, { PATH, PATHEXT }?: WhichOptions): Promise<string>;
90/**
91 * Find all instances of a program in PATH.
92 *
93 * If `program` contains a path separator, this function will merely return it
94 * inside an array.
95 *
96 * @param program A command name, such as `ionic`
97 */
98export declare function findExecutables(program: string, { PATH, PATHEXT }?: WhichOptions): Promise<string[]>;