Bun

Bun v0.4


Ashcon Partovi · December 23, 2022

Note — We're hiring C/C++ and Zig engineers to build the future of JavaScript!

Happy Holidays! We're excited to release Bun v0.4.0 with support for more Node.js APIs, increased stability, lots of bug fixes, and a new command: bunx.

Introducing bunx

This version introduces bunx, Bun's equivalent of npx with 100x faster startup times. It runs executables from local or remote npm packages.

bunx esbuild --version

As with npx, it will check for a locally installed package first, then fall back to auto-installing from npm into a shared global cache. With Bun's fast startup times, it's roughly 100x faster than npx for locally installed packages.

The --bun flag

By default, Bun respects the #!/usr/bin/env node shebang at the top of scripts or executables that are run with bun run <script> or bunx <command>.

// foo.js
#! /usr/bin/env node

console.log(process.argv[0]);
bun run foo.js
/path/to/node/19.2.0/bin/node

To override this behavior, pass the --bun flag. This temporarily aliases node to bun for the duration of the execution.

bun --bun run foo.js
/path/to/.bun/bin/bun

In the future, we might make this behaviour the default once Bun's Node.js compatibility is more complete.

bun --bun vite

Node.js compatibility

Support for Node.js APIs continues to be a top priority for Bun. As of Bun v0.4.0, you can now use the following APIs:

Setup and teardown in bun:test

Bun has a built-in test runner that you can run using the command: bun wiptest. You can now define Jest-style lifecycle hooks for the setup and teardown of tests.

import { beforeAll, test } from "bun:test";

let tests;
beforeAll(async () => {
  const response = await fetch("https://example.com/path/to/resource");
  tests = await response.json();
});

test("that integration tests are defined", () => {
  expect(tests).toHaveLength(100);
});

Bun.deepEquals() strict

You can now pass a strict argument to Bun.deepEquals(), which will have the same behaviour as expect().toStrictEqual().

const a = { entries: [1, 2] };
const b = { entries: [1, 2], extra: undefined };

Bun.deepEquals(a, b); // => true
Bun.deepEquals(a, b, true); // => false

bun pm

In case you missed it, Bun has a command that allows you see information about your packages and lockfile in a project: bun pm.

Output of "bun pm"

bun pm ls

In Bun v0.4.0 there is new sub-command, bun pm ls, which will list all the packages and versions in your project, similar to npm ls.

Output of "bun pm ls"

Notable Fixes

PR log

  • fix __require collision from linking by @dylan-conway in https://github.com/oven-sh/bun/pull/1585
  • chore: add eslintcache by @Simon-He95 in https://github.com/oven-sh/bun/pull/1586
  • Add filename completions on bun command to Zsh by @colinhacks in https://github.com/oven-sh/bun/pull/1593
  • Exclude additional TSdeclaration file extensions from completions by @colinhacks in https://github.com/oven-sh/bun/pull/1596
  • fix path string by @YUxiangLuo in https://github.com/oven-sh/bun/pull/1597
  • override process.stdin.on() correctly by @alexlamsl in https://github.com/oven-sh/bun/pull/1603
  • fix(stream): Fix Readable.pipe() by @ThatOneBro in https://github.com/oven-sh/bun/pull/1606
  • make process.stdin work under TTY by @alexlamsl in https://github.com/oven-sh/bun/pull/1611
  • add bun pm ls for printing lockfiles by @dylan-conway in https://github.com/oven-sh/bun/pull/1612
  • fix(stream): make Readable.read work w/o _construct implemented by @ThatOneBro in https://github.com/oven-sh/bun/pull/1613
  • Fix typo in bun.d.ts by @eltociear in https://github.com/oven-sh/bun/pull/1619
  • add tests for process.stdin by @alexlamsl in https://github.com/oven-sh/bun/pull/1621
  • docs(README.md): update bun-types new path definition by @hoseinprd in https://github.com/oven-sh/bun/pull/1622
  • Delete Oniguruma by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/1625
  • bug compatible with stdin.on("readable") by @alexlamsl in https://github.com/oven-sh/bun/pull/1626
  • Implement bunx by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/1634
  • add tests for #1633 by @alexlamsl in https://github.com/oven-sh/bun/pull/1635
  • fix jest hooks in bun-test by @ethanburrell in https://github.com/oven-sh/bun/pull/1639
  • fix bun install dependency resolution by @alexlamsl in https://github.com/oven-sh/bun/pull/1643
  • [install] avoid dependency conflicts between siblings by @alexlamsl in https://github.com/oven-sh/bun/pull/1647
  • Update benchmarks by @colinhacks in https://github.com/oven-sh/bun/pull/1648
  • [install] fix remaining corner cases with dependency resolution by @alexlamsl in https://github.com/oven-sh/bun/pull/1649

Contributors

We'd also like to thank everyone who helped contribute to Bun.