pwshub.com

Bun v1.1.29

Bun v1.1.29 is here! This release fixes 21 bugs (addressing 22 πŸ‘). Fixes issue with proxying requests with axios. N-API (napi) support in compiled C. Faster typed arrays in bun:ffi with 'buffer' type. Fixes issue with bundling imported .wasm files in bun build. Fixes regression with bun build from v1.1.28. Fixes snapshot regression in bun test. Fixes bug with argument validation in Bun.build plugins.

We're hiring systems engineers in San Francisco to build the future of JavaScript!

To install Bun

curl

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

powershell

powershell -c "irm bun.sh/install.ps1|iex"

docker

docker run --rm --init --ulimit memlock=-1:-1 oven/bun

To upgrade Bun

N-API (napi) support in compiled C

In Bun v1.1.28 (previous version), we introduced support for compiling and running C code from JavaScript.

In this release, we've added N-API (napi) support to cc. This makes it easier to return JavaScript strings, objects, arrays and other non-primitive values from C code.

For example, this returns a JavaScript string "Hello, Napi!":

hello-napi.c

#include <node/node_api.h>

napi_value hello_napi(napi_env env) {
  napi_value result;
  napi_create_string_utf8(env, "Hello, Napi!", NAPI_AUTO_LENGTH, &result);
  return result;
}

hello-napi.js

import { cc } from "bun:ffi";
import source from "./hello-napi.c" with {type: "file"};
const hello_napi = cc({
  source,
  symbols: {
    hello_napi: {
      args: ["napi_env"],
      returns: "napi_value",
    },
  },
});

console.log(hello_napi());
// => "Hello, Napi!"

You can continue to use types like int, float, double to send & receive primitive values from C code, but now you can also use N-API types! Also, this works when using dlopen to load shared libraries with bun:ffi (such as Rust or C++ libraries with C ABI exports).

"buffer" type in bun:ffi

You can now use the "buffer" type in bun:ffi to send and receive JavaScript typed arrays (Uint8Array, Buffer, etc) in C code slightly faster and simpler.

The following example returns the last byte of a Uint8Array:

last-byte.c

uint8_t lastByte(uint8_t *arr, size_t len) {
  return arr[len - 1];
}

last-byte.js

import { cc } from "bun:ffi";
import source from "./last-byte.c" with {type: "file"};
const lastByte = cc({
  source,
  symbols: {
    lastByte: {
      args: ["buffer", "usize"],
      returns: "u8",
    },
  },
});

const arr = new Uint8Array([1, 2, 3, 4, 5]);
console.log(lastByte(arr, arr.length));
// => 5

In this microbenchmark, the hash function gets 30% faster by using the "buffer" type in bun:ffi instead of wrapping the Uint8Array in the ptr() function.

cpu: Apple M3 Max
runtime: bun 1.1.29 (arm64-darwin)

benchmark          time (avg)             (min … max)       p75       p99      p995
----------------------------------------------------- -----------------------------
hash (ptr)      82.63 ns/iter   (79.6 ns … 172.82 ns)  81.65 ns 111.22 ns 118.77 ns
hash (buffer)   48.59 ns/iter    (45.04 ns … 94.9 ns)  50.09 ns  79.17 ns  81.93 ns

Under the hood, we've made the conversion between JavaScript typed arrays and C uint8_t* happen inline without external function calls, which makes it faster than using the ptr function from bun:ffi.

Fixed: proxy with axios

A bug causing proxying requests with axios to not work properly is fixed.

Thanks to @cirospaciari for the fix!

Fixed: Bundling imported .wasm files in bun build

A bug that could cause a crash when bundling imported .wasm files in bun build is fixed.

Thanks to @dylan-conway for the fix!

Fixed: regression with bun build from v1.1.28

A regression where certain symbols were being re-ordered incorrectly in bun build is fixed.

Thanks to @paperdave for the fix!

Fixed: snapshot regression in bun test

A regression that caused bun test to always update snapshots is fixed.

Thanks to @dylan-conway for the fix!

Fixed: Argument validation issue in Bun.build plugins

A crash that could happen when passing an incorrect argument to the plugins option in Bun.build is fixed.

Thanks to @dylan-conway for the fix!

Fixed: cc missing include directories on Linux and macOS

A bug that caused cc to not find the default system include directories on Linux and macOS is fixed.

Thanks to 3 contributors!

Source: bun.sh

Related stories
1 month ago - Fixes 79 bugs (addressing 93 πŸ‘). Express is now 3x faster in Bun, ES modules load faster on Windows, 10% faster Bun.serve() at POST requests, source maps in `bun build --compile`. Memory usage reductions to `--hot`, Bun.serve(), and...
1 week ago - Fixes 130 bugs (addressing 250 πŸ‘). `bun pm pack`, faster `node:zlib`. Static routes in Bun.serve(). ReadableStream support in response.clone() & request.clone(). Per-request timeouts. Cancel method in ReadableStream is called. `bun run`...
1 day ago - This release fixes 40 bugs (addressing 51 πŸ‘). Compile & run C from JavaScript. 30x faster path.resolve. Named pipes on Windows. Several Node.js compatibility improvements and bugfixes.
1 month ago - Fixes 72 bugs (addressing 63 πŸ‘). 30% faster fetch() decompression, New --fetch-preconnect flag, improved Remix support, Bun gets 4 MB smaller on Linux, bundle packages excluding dependencies, many bundler fixes and node compatibility...
1 month ago - Support for `TextEncoderStream` and `TextDecoderStream`, 50% faster `console.log(string)`, support for `Float16Array`, Node.js<>Bun IPC on Windows, truncate large arrays in `console.log()`, and many more bug fixes and Node.js...
Other stories
21 minutes ago - What are strategies for being a productive developer with ADHD? How can you help your team members with ADHD to succeed and complete projects? This week on the show, we speak with Chris Ferdinandi about his website and podcast "ADHD For...
48 minutes ago - The accounting equation forms the basic premise of all financial reporting in an organization. It implies that a company’s assets must be paid for either by borrowing or from its own funds. It shows how a company’s resources (assets) are...
10 hours ago - Vivaldi web browser has arrived on the Canonical Snap Store – officially. This closed-source, Chromium-based web browser has been available on Linux since its debut in 2015, providing an official DEB package for Ubuntu users (which adds...
14 hours ago - Four Prometheus metric types that all developers and DevOps pros should know form the building blocks of an effective observability strategy
15 hours ago - The 2024 Gartner Magic Quadrant positions AWS as a Leader, reflecting our commitment to diverse virtual desktop solutions and operational excellence - driving innovation for remote and hybrid workforces.