process.ts

Declarations
#

16 declarations

view source

attach_process_error_handlers
#

process.ts view source

(to_error_label?: ((err: Error, origin: UncaughtExceptionOrigin) => string | null) | undefined, map_error_text?: ((err: Error, origin: UncaughtExceptionOrigin) => string | null) | undefined, handle_error?: (err: Error, origin: UncaughtExceptionOrigin) => void): void

Attaches the 'uncoughtException' event to despawn all processes, and enables custom error logging with to_error_label.

to_error_label?

- Customize the error label or return null for the default origin.

type ((err: Error, origin: UncaughtExceptionOrigin) => string | null) | undefined
optional

map_error_text?

- Customize the error text. Return '' to silence, or null for the default print_error(err).

type ((err: Error, origin: UncaughtExceptionOrigin) => string | null) | undefined
optional

handle_error

type (err: Error, origin: UncaughtExceptionOrigin) => void
default () => process.exit(1)

returns

void

despawn
#

process.ts view source

(child: ChildProcess): Promise<SpawnResult>

Kills a child process and returns a SpawnResult.

child

type ChildProcess

returns

Promise<SpawnResult>

despawn_all
#

process.ts view source

(): Promise<SpawnResult[]>

Kills all globally registered child processes.

returns

Promise<SpawnResult[]>

global_spawn
#

process.ts view source

Set<ChildProcess>

We register spawned processes gloabally so we can gracefully exit child processes. Otherwise, errors can cause zombie processes, sometimes blocking ports even!

print_child_process
#

print_spawn_result
#

register_global_spawn
#

process.ts view source

(child: ChildProcess): () => void

Returns a function that unregisters the child.

child

the child process to register

type ChildProcess

returns

() => void

cleanup function that removes the child from global_spawn

RestartableProcess
#

spawn
#

process.ts view source

(command: string, args?: readonly string[] | undefined, options?: SpawnOptions | undefined): Promise<SpawnResult>

A convenient promise wrapper around spawn_process intended for commands that have an end, not long running-processes like watchers. Any more advanced usage should use spawn_process directly for access to the child process.

args

type [command: string, args?: readonly string[] | undefined, options?: SpawnOptions | undefined]

returns

Promise<SpawnResult>

spawn_out
#

process.ts view source

(command: string, args?: readonly string[], options?: SpawnOptions | undefined): Promise<SpawnedOut>

Similar to spawn but buffers and returns stdout and stderr as strings.

command

type string

args

type readonly string[]
default []

options?

type SpawnOptions | undefined
optional

returns

Promise<SpawnedOut>

spawn_process
#

process.ts view source

(command: string, args?: readonly string[], options?: SpawnOptions | undefined): SpawnedProcess

Wraps the normal Node childProcess.spawn with graceful child shutdown behavior. Also returns a convenient closed promise. If you only need closed, prefer the shorthand function spawn.

command

type string

args

type readonly string[]
default []

options?

type SpawnOptions | undefined
optional

returns

SpawnedProcess

spawn_restartable_process
#

process.ts view source

(command: string, args?: readonly string[], options?: SpawnOptions | undefined): RestartableProcess

Like spawn_process but with restart and kill, handling many concurrent restart calls gracefully.

command

type string

args

type readonly string[]
default []

options?

type SpawnOptions | undefined
optional

returns

RestartableProcess

Spawned
#

process.ts view source

Spawned

child

type ChildProcess

signal

type NodeJS.Signals | null

code

type number | null

SpawnedOut
#

SpawnedProcess
#

SpawnResult
#

Depends on
#

Imported by
#