Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.33 KB

File metadata and controls

48 lines (32 loc) · 1.33 KB
description Modern alternatives to the execa package for running child processes

Replacements for execa

tinyexec

tinyexec is a minimal process execution library.

Example:

import { execa } from 'execa' // [!code --]
import { x } from 'tinyexec' // [!code ++]

const { stdout } = await execa('ls', ['-l']) // [!code --]
const { stdout } = await x('ls', ['-l'], { throwOnError: true }) // [!code ++]

nanoexec

If you prefer a very thin wrapper over child_process.spawn (including full spawn options and optional shell), nanoexec is another light alternative. Its stdout/stderr are Buffers.

Example:

import { execa } from 'execa' // [!code --]
import exec from 'nanoexec' // [!code ++]

const { stdout } = await execa('echo', ['example']) // [!code --]
const res = await exec('echo', ['example']) // [!code ++]
const stdout = res.stdout.toString('utf8') // [!code ++]

Bun

If you’re on Bun, its built-in $ template tag can replace execa’s script-style usage:

Example:

import { $ } from 'execa' // [!code --]
import { $ } from 'bun' // [!code ++]

const { stdout } = await $`echo "Hello"` // [!code --]
const stdout = await $`echo "Hello"`.text() // [!code ++]