bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Downloads
4.5M
Stars
70.2K
Committers
681

Bot releases are visible (Hide)

bun - Bun v0.6.4

Published by Jarred-Sumner over 1 year ago

Read Bun v0.6.4's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.6.3...bun-v0.6.4

bun - Bun v0.6.3

Published by Jarred-Sumner over 1 year ago

Read Bun v0.6.3's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.6.2...bun-v0.6.3

bun - Bun v0.6.2

Published by Jarred-Sumner over 1 year ago

This is a couple bugfixes to the bundler & minifier and performance improvements to JavaScript thanks to JavaScriptCore team members @Constellation and @shvaikalesh

Read Bun v0.6.2's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.6.1...bun-v0.6.2

bun - Bun v0.6.1

Published by Jarred-Sumner over 1 year ago

This is a bugfix release for bun build --compile

Read Bun v0.6.0's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

image

bun - Bun v0.6.0

Published by Jarred-Sumner over 1 year ago

Read Bun v0.6.0's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

image

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.9...bun-v0.6.0

bun - Bun v0.5.9

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.9's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.8...bun-v0.5.9

bun - Bun v0.5.8

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.8's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.7...bun-v0.5.8

bun - Bun v0.5.7

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.7's release notes on Bun's blog

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.6...bun-v0.5.7

bun - Bun v0.5.6

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.6's release notes on Bun's blog

This release is a follow up to Bun v0.5

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.5...bun-v0.5.6

bun - Bun v0.5.5

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.5's release notes on Bun's blog

This release is a follow up to Bun v0.5

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.4...bun-v0.5.5

bun - Bun v0.5.4

Published by Jarred-Sumner over 1 year ago

This fixes a couple bugs from Bun v0.5.2. Otherwise, it's the same as Bun v0.5.2

Read Bun v0.5.2's release notes on Bun's blog

This release is a follow up to Bun v0.5 and Bun v0.5.1

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.1...bun-v0.5.2

bun - Bun v0.5.3

Published by Jarred-Sumner over 1 year ago

This fixes a bug we missed in Bun v0.5.2. Otherwise, it's the same as Bun v0.5.2

Read Bun v0.5.2's release notes on Bun's blog

This release is a follow up to Bun v0.5 and Bun v0.5.1

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.1...bun-v0.5.2

bun - Bun v0.5.2

Published by Jarred-Sumner over 1 year ago

Read Bun v0.5.2's release notes on Bun's blog

This release is a follow up to Bun v0.5 and Bun v0.5.1

To install:

curl https://bun.sh/install | bash
# or you can use npm
# npm install -g bun

To upgrade:

bun upgrade

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.1...bun-v0.5.2

bun - Bun v0.5.1

Published by Jarred-Sumner over 1 year ago

This release is a follow up to Bun v0.5

To install:

curl https://bun.sh/install | bash

To upgrade:

bun upgrade

Read Bun v0.5.1's release notes on Bun's blog

What's Changed

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.5.0...bun-v0.5.1

bun - Bun v0.5

Published by Jarred-Sumner almost 2 years ago

To install:

curl https://bun.sh/install | bash

To upgrade:

bun upgrade

Read Bun v0.5.0's release notes on Bun's blog

All the PRs

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.4.0...bun-v0.5.0

bun - Bun v0.4.0

Published by Jarred-Sumner almost 2 years ago

To install:

curl https://bun.sh/install | bash

To upgrade:

bun upgrade

Read Bun v0.4.0's release notes on Bun's blog

Commit log

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.3.0...bun-v0.4.0

bun - Bun v0.3.0

Published by Jarred-Sumner almost 2 years ago

Read Bun v0.3.0's release notes on Bun's blog

To install:

curl -fsSL https://bun.sh/install | bash

To upgrade:

bun upgrade

There were a lot of changes! Here's the complete list:

bun - Bun v0.2.2

Published by Jarred-Sumner almost 2 years ago

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash

TLDR:

  • TCP/TLS Socket API
  • WebCrypto API
  • fs.createReadStream works now
  • Bun.peek
  • Install Bun with Homebrew
  • Several bug fixes

TCP sockets

Bun now has support for TCP clients and servers. You can use it to implement database clients, game servers, or anything else that needs to use TCP instead of HTTP.

A TCP echo server runs 24% faster in Bun compared to Node:

image

This API is designed to be fast. Instead of promises or assigning callbacks for each socket, like the Node.js EventEmitter or the standard WebSocket API, callbacks are defined once for optimal performance and better code readability.

Start a TCP server

import { listen } from "bun";

listen({
  hostname: "localhost",
  port: 8080,
  socket: {
    open(socket) {},
    data(socket, data) {
      console.log(data instanceof Uint8Array); // true
    },
    drain(socket) {},
    close(socket) {},
    error(socket, error) {},
  },
});

Start a TCP client

import { connect } from "bun";

connect({
  hostname: "localhost",
  port: 8080,
  socket: {
    data(socket, data) {
      console.log("Received:", data);
    },
  },
});

There is also support for:

  • Hot-reloading a TCP socket without downtime
  • Assigning custom data to a socket
  • TLS/SSL support

You can read more about TCP sockets in the README.

This API is very new and I imagine there are still some bugs to fix. Please file issues about any bugs you run into!

Bug fixes

Bun has a special transform for importing builtin modules which converts them from asynchronous ESM imports into synchronous ESM import.meta.require. A transpiler bug when default was imported in these builtin Bun modules along with other named imports caused a runtime error:

// this code would break
import fs, {writeFileSync} from 'fs';

// but this code worked
import * as fs from 'fs';

The bug was due to how Bun's transpiler rewrote those imports. In this case, default is equivalent to the namespace object (only for these builtin modules which may not actually point to JavaScript source code)

Now, Bun transpiles the above into:

var fs = import.meta.require("node:fs");

// note: live bindings are not preserved
var {writeFileSync} = fs;

When an import fails to resolve at build time, Bun throws a ResolveError. ResolveError includes a position object that exposes detailed line & column information about where the file was originally imported.

There was a bug where Bun would crash if you attempted to access the position object when it came from an await import which imported another file that failed to resolve

File A:

import { expect, it, describe } from "bun:test";

describe("ResolveError", () => {
  it("position object does not segfault", async () => {
    try {
      await import("./file-b");
    } catch (e) {
      expect(Bun.inspect(e.position).length > 0).toBe(true);
    }
  });
});

file-b.js:

import "./does-not-exist.js";

This bug has been fixed.


Error handling logic for new Response(Bun.file(fileDescriptorAsANumber)) when used with the HTTP server expected it to be used with file paths instead of file descriptor numbers, causing a crash. Thanks to @sno2 for the fix.


export default {
   // This would crash due to incorrect error handling logic
   fetch(req) { return new Response(Bun.file(123)); }
}


An edgecase involving hex-escaped RegExp literals with lookbehinds caused our Oniguruma polyfill from v0.2.1 to throw an error. This was fixed thanks to @dylan-conway


More bug fixes:

Bun.peek

Sometimes you have code that is async, but you know it is not actually async. The new peek function will allow you to read a promise's result without await or .then, but only if the promise has already fulfilled or rejected.

import { peek } from "bun";

const promise = Promise.resolve("immediate");
const result = peek(promise); // no await!

console.log(result); // "immediate"

It is useful for performance-sensitive code where you want to reduce the number of extra microticks. It's an advanced API and you (probably) shouldn't use it unless you know what you're doing.

You can read more about peek in the README.

Node.js streams

In addition to new APIs, we continue to make progress towards Node.js compatibility. Bun now supports fs.createReadStream and has generally improved support for Node.js streams.

import { createReadStream } from "node:fs";

// Reads the first 100 bytes of a file
const reader = createReadStream("example.txt", {
  encoding: "utf-8",
  start: 0,
  end: 100,
});

reader.on("data", (chunk) => {
  console.log(chunk);
});

WebCrypto API

The standard WebCrypto API is now implemented, thanks to the many contributors at WebKit.

WebCrypto is a low-level API, so we only recommend using it when you know a little more than a thing or two about cryptography. However, there are popular libraries that depend on WebCrypto that you can now use with Bun.

Here's an example using a package that depends on WebCrypto: jose by @panva.

const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
  .setProtectedHeader({ alg: 'ES256' })
  .setIssuedAt()
  .setIssuer('urn:example:issuer')
  .setAudience('urn:example:audience')
  .setExpirationTime('2h')
  .sign(privateKey)

console.log(jwt)

Homebrew

You can now install or upgrade Bun with our official Homebrew tap.

brew tap oven-sh/bun
brew install bun

You can also install a specific version.

brew install [email protected]

You can also upgrade with either brew or bun.

brew upgrade bun
bun upgrade # still works

All the PRs

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.2.1...bun-v0.2.2

bun - Bun v0.2.1

Published by Jarred-Sumner about 2 years ago

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

WebSocket server

Bun.serve() now has builtin support for websockets on the server

Bun.serve({
  websocket: {
    message(ws, message) {
      ws.send(message);
    },
  },

  fetch(req, server) {
    // Upgrade to a ServerWebSocket if we can
    // This automatically checks for the `Sec-WebSocket-Key` header
    // meaning you don't have to check headers, you can just call `upgrade()`
    if (server.upgrade(req))
      // When upgrading, we return undefined since we don't want to send a Response
      return;

    return new Response("Regular HTTP response");
  },
});

For more information about using websockets with Bun.serve(), see the readme

For a chat room on Linux:

To reproduce this benchmark on your own computer, go here

Bun's server-side websockets are powered by uWebSockets.

RegExp lookbehinds assertions fix

To address #314, Bun now includes a fallback RegExp implementation that uses the Oniguruma regex engine. Thanks to @dylan-conway!

RegExp lookbehind assertions are used by popular npm packages like Discord.js

When a RegExp literal with a lookbehind is used inside Bun's runtime, Bun's transpiler now automatically replaces it with a Bun.OnigurumaRegExp. This API isn't intended to be used outside of the transpiler and will be removed once JavaScriptCore lands native support.

When run inside Bun's JavaScript runtime, this input:

export default /\d+(?=%)/;

Transpiles to:

export default (new globalThis.Bun.OnigurumaRegExp("\\d+(?=%)"));

The RegExp polyfill is largely based on JavaScriptCore's own JSC::RegExp bindings.

More stuff

  • Send a Date header in HTTP responses
  • performance.timeOrigin has been implemented
  • process.argv was returning an empty array when bun started without arguments other than the script, like bun foo.js (thanks to @dylan-conway for the fix)
  • Fix a crash when BodyMixin functions throw
  • Fix a memory leak in HTTP server related to promises
  • Fix a regression from v0.2.0 where small buffered (non-streaming) HTTP response bodies would sometimes include invalid data due to a memory aliasing bug
  • Fix a bug where a pong control frame in bun's WebSocket client would sometimes put the WebSocket in an error state https://github.com/oven-sh/bun/commit/c6fe82018aeda88a3337a5355313de7db68ef827
  • Fix a bug where a WebSocket client would not keep the process open - #1335
  • More test coverage for bun's client-side WebSocket implementation due to adding server-side WebSockets
  • Added DOMJIT function call support to Bun's JavaScriptCore bindings generator (used by the new ServerWebSocket object for publishText, publishBinary, sendText and sendBinary functions)

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.2.0...bun-v0.2.1

bun - Bun v0.2.0

Published by Jarred-Sumner about 2 years ago

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

Introducing Bun v0.2.0

https://user-images.githubusercontent.com/709451/195575815-96df744a-1073-4292-b24d-5ba76c20b942.png

New:

Breaking:

  • bun run and bun CLI arguments parsing has been changed so that anything after bun run <file-or-script> or bun <file> is passed through verbatim. This fixes a number of bugs with CLI argument parsing in both bun as a runtime and when used as a package.json "scripts" runner.
# before, server.js wouldn't see the --port argument
bun run server.js --port 3000
  • process.version now reports a fake Node.js version instead of Bun's version. This is for compatibility with many npm packages that check for Node.js version to enable/disable features. To get Bun's version, use Bun.version or process.versions.bun.

  • Bun.serve().hostname should return the hostname instead of the origin. This is a breaking change because it affects how URLs may be printed if you were using this getter before. https://github.com/oven-sh/bun/commit/e15fb6b9b220510df049e782d4f2f6eb3150d069

bun --hot: hot reloads on the server

bun --hot lets you see code changes immediately, without restarting your server. Unlike popular file watchers like nodemon, bun --hot preserves some of the state of your app, meaning in-flight HTTP requests don't get interrupted.

Screen Recording 2022-10-06 at 2 36 06 AM

To use it with Bun's HTTP server (automatic):

server.ts (vanilla JavaScript works too)

// The global object is preserved across code reloads
// You can use it to store state, for now until Bun implements import.meta.hot.
const reloadCount = globalThis.reloadCount || 0;
globalThis.reloadCount = reloadCount + 1;

export default {
  fetch(req: Request) {
    return new Response(`Code reloaded ${reloadCount} times`, {
      headers: { "content-type": "text/plain" },
    });
  },
};

Then, run:

bun --hot server.ts

You can also use bun run:

bun run --hot server.ts

For more information, see bun --hot section in Bun's readme.

Bun.spawn spawn processes in Bun

Bun.spawn efficiently spawns a new process in Bun.

import { spawn } from "bun";

const { stdout } = await spawn(["echo", "hello world"]);
console.log(
  await new Response(
    // stdout is a ReadableStream
    stdout
  ).text()
); // "hello world"

Bun.spawn is flexible. stdin can be a Response, Blob, Request, ArrayBuffer, ArrayBufferView, Bun.file, "pipe" or number.

import { spawn } from "bun";

const { stdout } = spawn({
  cmd: ["esbuild"],
  // using fetch()
  stdin: await fetch(
    "https://raw.githubusercontent.com/oven-sh/bun/main/examples/hashing.js"
  ),
});

const text = await new Response(
  // stdout is a ReadableStream here
  stdout
).text();
console.log(text.slice(0, 128), "..."); // const input = "hel...

stdout and stderr return ReadableStreams when "pipe" is used.

Request.body & Response.body return a ReadableStream

This fixes https://github.com/oven-sh/bun/issues/530

You can read Request & Response objects bodies as a ReadableStream now

ReadableStream now supports async iterators

This works now:

const body = new Response(["hello"]).body;
const chunks = [];
for await (const chunk of body) {
    chunks.push(chunk);
}

Previously, you had to call getReader() like this:

const reader = body.getReader();
const chunks = [];
while (true) {
    const { done, value } = await reader.read();
    if (done) {
        break;
    }
    chunks.push(value);
}

HTTP request body streaming

Bun.serve now supports streaming request bodies. This is useful for large file uploads.

import { serve } from "bun";

serve({
  async fetch(req) {
    // body is a ReadableStream
    const body: ReadableStream = req.body;

    const id = `upload.${Date.now()}.txt`;
    const writer = Bun.file(id).writer();
    for await (const chunk of body) {
      writer.write(chunk);
    }
    const wrote = await writer.close();

    return Response.json({ wrote, id, type: req.headers.get("Content-Type") });
  },
});

"imports" support in package.json

This release adds support for the imports field in package.json

image

Reduced memory usage for Bun.serve()

Bun wasn't correctly reporting memory usage for Request, Response, and Blob objects to JavaScriptCore, causing the garbage collector to be unaware of how much memory was really in use for http responses/requests.

image

bun:test performance improvements

An event loop bug in bun:test caused the process the idle for awhile. Now bun's own http server tests run > 10x faster.

image

Bug fixes:

More changes:

All the PRs

New Contributors

Full Changelog: https://github.com/oven-sh/bun/compare/bun-v0.1.13...bun-v0.2.0