Bun v0.5.9 introduces watch mode using bun --watch
, adds support for tarball dependencies in bun install
, and fixes lots of bugs to improve stability and compatibility.
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
Watch mode
Bun now supports watch mode using bun --watch
, which auto-restarts your application when you make a change to your files. This is useful in development to quickly see changes you've made to your code. It's a builtin replacement for nodemon
that is noticeably faster.
Run a file with bun --watch
"bun --watch ./watchy.tsx" pic.twitter.com/qi7zCvx37p
— Jarred Sumner (@jarredsumner) March 29, 2023
Run tests with bun test --watch
"bun test --watch url" in a large folder with multiple files that start with "url" pic.twitter.com/aZV9BP4eFu
— Jarred Sumner (@jarredsumner) March 29, 2023
Bun still supports bun --hot
, which attempts to reload your application code without restarting the whole process. This is particularly useful when developing a server with Bun.serve
, especially one long-lived connections like WebSockets. But in most cases --watch
is a better general purpose tool.
Tarball dependencies
You can now use tarball dependencies in your package.json
. Bun will download and install the package from the specified tarball URL, rather than from npm (or whichever package registry you have configured).
{
"dependencies": {
"zod": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz"
}
}
Use tarball URLs to include a dependency that is not in a registry or privately hosted.
Squashed bugs
We fixed a lot of bugs this release, here are a few interesting highlights.
- The
url.origin
property is to"null"
when the protocol is non-HTTP.
test("url.origin is null when protocol is non-http", () => {
expect(new URL("https://example.com")).toHaveProperty(
"origin",
"https://example.com",
);
expect(new URL("file://path/to/file")).toHaveProperty("origin", "null");
expect(new URL("about:blank")).toHaveProperty("origin", "null");
});
Set-Cookie
headers are no longer de-duplicated.
test("headers can handle duplicate set-cookie headers", () => {
const headers = new Headers([["Set-Cookie", "foo=bar"]]);
headers.append("set-Cookie", "foo=baz");
expect([...headers]).toEqual([
["set-cookie", "foo=bar"],
["set-cookie", "foo=baz"],
]);
});
- An invalid
Date
nowconsole.log()
as "Invalid Date".
test("invalid date inspects as 'Invalid Date'", () => {
expect(Bun.inspect(new Date("hello world"))).toBe("Invalid Date");
});
- Node.js'
util.isError()
function now works for objects that are "Error-like".
test("util.isError() works for non-native errors", () => {
const actual = util.isError({ name: "Error", message: "an error occurred" });
expect(actual).toBe(true);
});
- We also improved the Error messages when you import a Node.js module that has not been implemented yet in Bun, like
node:http2
andnode:vm
.
made errors for not implemented yet node.js builtins better pic.twitter.com/U9VQK5Yk1q
— Jarred Sumner (@jarredsumner) April 2, 2023
Looking ahead
A new JavaScript bundler is coming, including builtin support for server components.
server components is coming in Bun v0.6.0 pic.twitter.com/ZfcIewP3HE
— Jarred Sumner (@jarredsumner) April 3, 2023
Changelog
#2425 | Improved zsh completions to include directories by @JacksonKearl |
#2429 | Updated moduleResolution to be "bundler" in tsconfig.json by @johnnyreilly |
#2414 | Improved types for EventEmitter to be type-safe by @gaurishhs |
58a5c2a | Fixed crash with export namespace ns { export class F {} } by @Jarred-Sumner |
#2458 | Fixed various failing tests by @dylan-conway |
#2459 | Fixed tests for undici by @ThatOneBro |
#2463 | Fixed issue with npm registries that end with a "/" by @Jarred-Sumner |
#2490 | Fixed incorrect port with HTTPS requests from http.request() by @cirospaciari |
#2497 | Implemented tarball URL support in bun install by @alexlamsl |
#2486 | Fixed more bugs, including escapeHTML() and util.isError() by @Jarred-Sumner |
#2500 | Implemented watch mode: bun --watch by @Jarred-Sumner |
#2501 | Fixed a crash from request.json() with a FormData body by @Jarred-Sumner |
#2506 | Improved compatibility of yarn lockfile printer by @Validark |
#2474 | Fixed bug with "Invalid Date" format by @adrien-zinger |
#2519 | Fixed bug when re-installing a git dependency using bun install by @alexlamsl |
#2534 | Added stubs for various unimplemented node modules, including v8 , trace_events , repl , inspector , http2 , diagnostics_channel , dgram , and cluster by @Jarred-Sumner |
#2536 | Reduced concurrent HTTP connections during bun install by @alexlamsl |
Contributors
And finally, thank you to all the contributors from the community that helped improve Bun this release: @jq170727, @JacksonKearl, @johnnyreilly, @gaurishhs, @Fire-The-Fox, @bnzone, @JokerQyou, @andres039, @Validark, @adrien-zinger, @jakeboone02