Bun v1.0.22 fixes 29 bugs (addressing 118 👍 reactions), fixesbun install
issues on Vercel, addsperformance.mark()
APIs, addschild_process
support for extra pipes, makesBuffer.concat
faster, addstoBeEmptyObject
andtoContainKeys
matchers, fixesconsole.table
width using emojis, and support forargv
andexecArgv
options inworker_threads
, and supports Brotli infetch
.
Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager — all in one. In case you missed it, here are some of the recent changes to Bun:
v1.0.21
- Fixes 33 bugs (addressing 80 👍 reactions).console.table()
support.Bun.write
, Bun.file, and bun:sqlite use less memory. Large file uploads with FormData use less memory. bun:sqlite error messages get more detailed. Memory leak in errors from node:fs fixed. Node.js compatibility improvements, and many crashes fixed.v1.0.20
- Reduces memory usage infs.readlink
,fs.readFile
,fs.writeFile
,fs.stat
andHTMLRewriter
. Fixes a regression where setTimeout caused high CPU usage on Linux.HTMLRewriter.transform
now supports strings andArrayBuffer
.fs.writeFile()
andfs.readFile()
now supporthex
&base64
encodings.Bun.spawn
shows how much CPU & memory the process used.v1.0.19
- Fixes 26 bugs (addressing 92 👍 reactions). Use @types/bun instead of bun-types. Fixes --frozen-lockfile bug. bcrypt & argon2 packages now work. setTimeout & setInterval get 4x higher throughput. module mocks in bun:test resolve specifiers. Optimized spawnSync() for large stdio on Linux. Bun.peek() gets 90x faster, expect(map1).toEqual(map2) gets 100x faster. Bugfixes to NAPI, bun install, and Node.js compatibility improvements.To install Bun:
curl -fsSL https://bun.sh/install| bash
npm install -g bun
brew tap oven-sh/bun
brew install bun
docker pull oven/bun
docker run --rm --init --ulimit memlock=-1:-1 oven/bun
To upgrade Bun:
bun upgrade
bun install
on VercelIn a recent release of Bun, we introduced changes tobun install
to make lifecycle scripts run faster by running them in parallel. When doing this, we also changed the how Bun sets the current working directory for lifecycle scripts, and started to use theposix_spawn_file_actions_addchdir_np
C-standard library function.
Bun was not properly checking if that function failed. The function was introduced in glibc 2.29, but Vercel uses glibc 2.26. Therefore, when runningbun install
on Vercel, the function would fail, andbun install
would not handle that failure.
The fix was to implement aposix_spawn
-like polyfill for Linux.
performance.mark()
APIsYou can now useuser-timings APIs, which includeperformance.mark()
andperformance.measure()
. This is useful for measuring the performance of your code.
performance.mark("start");while (true) {// ...}performance.mark("end");performance.measure("task","start","end");
You can also use thePerformanceObserver
API to listen for performance events.
const observer=newPerformanceObserver((list)=> {for (const entryof list.getEntries()) {if (entry.entryType==="mark") { console.log(entry);// { name: "start", startTime: 0 } }elseif (entry.entryType==="measure") { console.log(entry);// { name: "task", startTime: 0, duration: 1000 } } }});observer.observe({ entryTypes: ["mark","measure"] });
Thanks to@gvilums for submitting a PR to add this to Bun, and thanks to theWebKit team for their implementation of these APIs.
child_process
support for extra pipesYou can now pass extra pipes tochild_process
functions. This is useful for passing data between processes. For example, you can pass a pipe to a child process, and then write to that pipe from the parent process.
import { spawn }from"node:child_process";const child=spawn(process.argv0, ["child.js"], { stdio: ["inherit","inherit","inherit","pipe"],});const pipe= child.stdio[3];pipe.on("data", (data)=> { console.log(data.toString());// "hello!"});
import { createWriteStream }from"node:fs";const stream=createWriteStream(null, { fd:3 });stream.on("ready", ()=> { stream.write("hello!");});
These changes were necessary to supportPlaywright, which uses extra pipes to communicate with the browser process. However, there is still oneoutstanding PR that needs to be merged to get Playwright working with Bun.
Thanks to@nektro for implementing this missing API.
fetch
You can now usefetch
to make requests with thebr
encoding. This is useful for making requests to servers that support Brotli compression.
const response=awaitfetch("https://example.com", { headers: {"Accept-Encoding":"br", },});
We also changed brotli support to be statically-linked in Bun, instead of dynamically-linked. This fixed issues with certain Linux distros and older macOS releases that did not have the nessary libraries.
toBeEmptyObject
andtoContainKeys
matchersYou can now useexpect().toBeEmptyObject()
to check if an object is empty.
expect({}).toBeEmptyObject();expect({ a:1 }).not.toBeEmptyObject();
You can also useexpect().toContainKeys()
orexpect().toContainAnyKeys()
to check if an object contains certain keys.
expect({ a:1, b:2 }).toContainKeys(["a","b"]);expect({ a:1, b:2 }).not.toContainKeys(["c"]);
expect({ foo:"bar" }).toContainAnyKeys(["foo","baz"]);expect({ foo:"bar" }).not.toContainAnyKeys(["baz"]);
Thanks to@coratgerl for implementing this feature.
Buffer.concat
UsingBuffer.concat
is now 15% to 400% faster, depending on the size of the buffers being concatenated.
In the next version of Bun
— Jarred Sumner (@jarredsumner)January 8, 2024
Buffer.concat gets 15% - 400% faster, depending on the input size.pic.twitter.com/hdC1mqhF51
We also fixed a bug whereBuffer.concat
would crash when concatenating a large number of buffers. This was caused by an out-of-memory error not being handled correctly.
new Headers(object)
Usingnew Headers(object)
andnew URLSearchParams(object)
with an object is now 10% to 15% faster.
In the next version of Bun
— Jarred Sumner (@jarredsumner)January 7, 2024
new Headers(myObject) gets 10% fasterpic.twitter.com/JLSeFDvq8A
console.table
width using emojisIn Bun v1.0.21, we added support forconsole.table
. However, we did not properly handle emojis, and the table would be misaligned if there were emojis or unicode characters in the table. This has been fixed by using the official Unicodedataset to determine the width of each character.
Thanks to@otgerrogla for implementingconsole.table
, and following up to fix this bug.
argv
andexecArgv
options forworker_threads
Bun did not support theargv
andexecArgv
options forworker_threads
. This has been fixed.
import { Worker }from"node:worker_threads";const worker=newWorker("./worker.js", { argv: ["--foo","bar"], execArgv: ["--inspect"],});worker.on("message", (data)=> { console.log(data);// { argv: [ "--foo", "bar" ], execArgv: [ "--inspect" ] }});
postMessage({ argv: process.argv, execArgv: process.execArgv,});
Thanks to@otgerrogla for fixing this missing functionality.
0.0.0.0
would bind to IPv6 as wellThere was a bug wherecreateServer
would bind to both IPv4 and IPv6 when binding to0.0.0.0
. This has been fixed thanks to@Hanaasagi.
node:http
In Bun v1.0.10, we introduced a bug where thePURGE
andOPTIONS
headers were not being properly transformed to uppercase. This caused problems with Fastify and CORS pre-flight requests. This has been fixed thanks to@asomethings.
BufferList
There was a bug where multiple, partial consumes onBufferList
would not increment theoffset
properly. This causedcbor
to not work properly, and has been fixed thanks to@hborchardt.
bun build --compile
withcompiled://
URLWe fixed a bug wherebun build --compile
would not work withcompiled://
URLs. This has been fixed by changingcompiled://
URLs to use a special prefix that Bun recognizes.
assert.doesNotMatch
You can now useassert.doesNotMatch
to check if a string does not match a regular expression.
assert.doesNotMatch("I will not match",/match/);
Thanks to@markusn for implementing this missing API.
Thank you to all the contributors to this release of Bun, including the new 13 contributors who submitted their first pull request!
You can also read thefull changelog.