spawn-rx

  • Version 6.0.0
  • Published
  • 117 kB
  • 3 dependencies
  • MIT license

Install

npm i spawn-rx
yarn add spawn-rx
pnpm add spawn-rx

Overview

An Rx-version of child_process.spawn

Index

Functions

function findActualExecutable

findActualExecutable: (exe: string, args: string[]) => CmdWithArgs;
  • Finds the actual executable and parameters to run on Windows. This method mimics the POSIX behavior of being able to run scripts as executables by replacing the passed-in executable with the script runner, for PowerShell, CMD, and node scripts.

    This method also does the work of running down PATH, which spawn on Windows also doesn't do, unlike on POSIX.

    Parameter exe

    The executable to run

    Parameter args

    The arguments to run

    {Object} The cmd and args to run {string} cmd The command to pass to spawn {string[]} args The arguments to pass to spawn

function spawn

spawn: {
(exe: string, params: string[], opts: any): Observable<OutputLine>;
(exe: string, params: string[], opts?: any): Observable<string>;
};
  • Spawns a process attached as a child of the current process.

    Parameter exe

    The executable to run

    Parameter params

    The parameters to pass to the child

    Parameter opts

    Options to pass to spawn.

    {Observable} Returns an Observable that when subscribed to, will create a child process. The process output will be streamed to this Observable, and if unsubscribed from, the process will be terminated early. If the process terminates with a non-zero value, the Observable will terminate with onError.

  • Spawns a process attached as a child of the current process.

    Parameter exe

    The executable to run

    Parameter params

    The parameters to pass to the child

    Parameter opts

    Options to pass to spawn.

    {Observable} Returns an Observable that when subscribed to, will create a child process. The process output will be streamed to this Observable, and if unsubscribed from, the process will be terminated early. If the process terminates with a non-zero value, the Observable will terminate with onError.

function spawnPromise

spawnPromise: {
(exe: string, params: string[], opts: any): Promise<[string, string]>;
(exe: string, params: string[], opts?: any): Promise<string>;
};
  • Spawns a process as a child process.

    Parameter exe

    The executable to run

    Parameter params

    The parameters to pass to the child

    Parameter opts

    Options to pass to spawn.

    {Promise<[string, string]>} Returns an Promise that represents a child process. The value returned is the process output. If the process terminates with a non-zero value, the Promise will resolve with an Error.

  • Spawns a process as a child process.

    Parameter exe

    The executable to run

    Parameter params

    The parameters to pass to the child

    Parameter opts

    Options to pass to spawn.

    {Promise} Returns an Promise that represents a child process. The value returned is the process output. If the process terminates with a non-zero value, the Promise will resolve with an Error.

  • Spawns a process as a child process.

    Parameter exe

    The executable to run

    Parameter params

    The parameters to pass to the child

    Parameter opts

    Options to pass to spawn.

    {Promise} Returns an Promise that represents a child process. The value returned is the process output. If the process terminates with a non-zero value, the Promise will resolve with an Error.

function statNoException

statNoException: (file: string) => Promise<sfs.Stats | null>;
  • stat a file but don't throw if it doesn't exist

    Parameter file

    The path to a file {Stats} The stats structure

function statSyncNoException

statSyncNoException: (file: string) => sfs.Stats | null;
  • stat a file but don't throw if it doesn't exist

    Parameter file

    The path to a file {Stats} The stats structure

Classes

class SpawnError

class SpawnError extends Error {}
  • Custom error class for spawn operations with additional metadata

constructor

constructor(
message: string,
exitCode: number,
command: string,
args: string[],
stdout?: string,
stderr?: string
);

    property args

    readonly args: string[];

      property code

      readonly code: number;

        property command

        readonly command: string;

          property exitCode

          readonly exitCode: number;

            property stderr

            readonly stderr?: string;

              property stdout

              readonly stdout?: string;

                Interfaces

                interface ProcessMetadata

                interface ProcessMetadata {}
                • Process metadata tracked during execution

                property args

                args: string[];

                  property command

                  command: string;

                    property pid

                    pid: number;

                      property startTime

                      startTime: number;

                        Type Aliases

                        type CmdWithArgs

                        type CmdWithArgs = {
                        cmd: string;
                        args: string[];
                        };

                          type OutputLine

                          type OutputLine = {
                          source: 'stdout' | 'stderr';
                          text: string;
                          };

                            type SpawnPromiseResult

                            type SpawnPromiseResult<T extends SpawnRxExtras> = T extends {
                            split: true;
                            }
                            ? Promise<[string, string]>
                            : Promise<string>;
                            • Utility type to extract the promise return type based on split option

                            type SpawnResult

                            type SpawnResult<T extends SpawnRxExtras> = T extends { split: true }
                            ? Observable<OutputLine>
                            : Observable<string>;
                            • Utility type to extract the return type based on split option

                            type SpawnRxExtras

                            type SpawnRxExtras = {
                            stdin?: Observable<string>;
                            echoOutput?: boolean;
                            split?: boolean;
                            encoding?: BufferEncoding;
                            /**
                            * Timeout in milliseconds. If the process doesn't complete within this time,
                            * it will be killed and the observable will error with a TimeoutError.
                            */
                            timeout?: number;
                            /**
                            * Number of retry attempts if the process fails (non-zero exit code).
                            * Defaults to 0 (no retries).
                            */
                            retries?: number;
                            /**
                            * Delay in milliseconds between retry attempts. Defaults to 1000ms.
                            */
                            retryDelay?: number;
                            };

                              Package Files (1)

                              Dependencies (3)

                              Dev Dependencies (10)

                              Peer Dependencies (0)

                              No peer dependencies.

                              Badge

                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/spawn-rx.

                              • Markdown
                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/spawn-rx)
                              • HTML
                                <a href="https://www.jsdocs.io/package/spawn-rx"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>