npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nutgaard/bun-recording-shell

v0.0.2

Published

Record and replay Bun shell invocations for deterministic tests.

Readme

@nutgaard/bun-recording-shell

Record and replay Bun shell invocations for deterministic tests.

This package wraps Bun's $ shell API and gives you three modes:

  • passthrough: run commands normally
  • record: run commands and capture their outputs
  • replay: return previously recorded outputs without re-running commands

It is useful when you want to test code that shells out, but you do not want your test suite to depend on the real system state, network, filesystem tools, or command timing.

Requirements

  • Bun runtime
  • Node compatibility is for package consumers, but the runtime behavior depends on bun

Install

bun add @nutgaard/bun-recording-shell

Basic usage

import { createShell } from '@nutgaard/bun-recording-shell';

const $ = createShell({ mode: 'passthrough' });

const result = await $`printf hello`;

console.log(result.text()); // hello

Record and replay

import { createShell } from '@nutgaard/bun-recording-shell';

const recordShell = createShell({ mode: 'record' });

await recordShell`printf first`.quiet();
await recordShell`printf second`.quiet();

const replayShell = createShell({
	mode: 'replay',
	recording: recordShell.getRecording(),
});

console.log((await replayShell`printf first`).text()); // first
console.log((await replayShell`printf second`).text()); // second

Persist recordings to disk

In record mode, you can write command events to an NDJSON log file and later replay from that file.

import { createShell } from '@nutgaard/bun-recording-shell';

const recordShell = createShell({
	mode: 'record',
	recordingLogPath: './fixtures/commands.ndjson',
});

await recordShell`printf hello`.quiet();

const replayShell = createShell({
	mode: 'replay',
	recordingLogPath: './fixtures/commands.ndjson',
});

console.log((await replayShell`printf hello`).text()); // hello

If you only need the finished command entries, you can also parse the file directly:

import { readReplayRecording } from '@nutgaard/bun-recording-shell';

const recording = readReplayRecording('./fixtures/commands.ndjson');

Command behavior

Replay mode is strict by design:

  • commands must be replayed in the same order they were recorded
  • the rendered command string must match exactly
  • non-zero exits throw by default, just like live shell execution

If you want to inspect a non-zero result without throwing, use .nothrow():

const result = await replayShell`false`.nothrow();
console.log(result.exitCode);

Errors

The package exports specific error types for replay and recorded failures:

  • RecordedShellError: command failed with a non-zero exit code
  • ReplayMismatchError: replayed command did not match the next recorded command
  • ReplayExhaustedError: replay ran out of recorded entries

RecordedShellError also exposes:

  • command
  • stdout
  • stderr
  • exitCode

API

createShell(options)

Creates a Bun shell wrapper.

Modes:

  • { mode: 'passthrough' }
  • { mode: 'record', recordingLogPath?: string }
  • { mode: 'replay', recording: ShellRecordingEntry[] }
  • { mode: 'replay', recordingLogPath: string }

Shared options:

  • cwd
  • env
  • throws

ShellRecordingEntry

type ShellRecordingEntry = {
	command: string;
	stdout: string;
	stderr: string;
	exitCode: number;
};

readReplayRecording(logPath)

Reads a recording log file and returns the finished command entries as ShellRecordingEntry[].

Notes

  • This package is Bun-specific because it builds on Bun's shell API.
  • Unsupported stream-like interpolations are rejected in replay mode.
  • Published output is ESM-only.