Bun v0.7.2が本日公開され、JavaScriptランタイム、バンドラー、トランスパイラー、およびパッケージマネージャーの機能を1つに統合したと発表された。
この新バージョンでは、node:worker_threads
とnode:diagnostics_channel
のサポートが追加され、BroadcastChannelが利用可能になった。また、Node.jsとの互換性も改善され、いくつかの重大なメモリリークも修正されたとされている。
Bun v0.7.2の新機能と修正の概要
Bun v0.7.2では、次のような新機能と修正が行われている。
Node.js worker_threadsのサポート
Bun v0.7.2では、Node.jsのworker_threads
モジュールをサポートし、Worker
をグローバル変数として使用できるようになった。これにより、node:worker_threads
に依存するパッケージやフレームワークをBun内で利用できる。例えば、以下のようなコードでnode:worker_threads
をBunで使用できる。
import { Worker } from "node:worker_threads";
const worker = new Worker("./worker.js");
bun . - メインファイルの実行
Bun v0.7.2では、bun .
コマンドを使用することで、ファイルのパスを入力する手間を省略してプロジェクトを実行できるようになった。これはimport '.'
と同等の機能を持つ。
BroadcastChannelの追加
新たにBroadcastChannelがBunで利用可能になった。これにより、複数のWorker
スレッドとメインスレッド間でメッセージのパブリッシュとサブスクライブが簡単に行えるようになる。
const channel = new BroadcastChannel("my-channel");
const message = { hello: "world" };
channel.onmessage = (event) => {
console.log(event.data); // { hello: "world" }
};
channel.postMessage(message);
Errorオブジェクトのクローンサポート
postMessage
とstructuredClone()
によって、Error
オブジェクトのクローンがサポートされるようになった。これにより、エラーオブジェクトを簡単に複製できる。
const error = new Error("hello world");
const clone = structuredClone(error);
console.log(clone.message); // "hello world"
Node.js node:diagnostics_channelのサポート
node:diagnostics_channel
モジュールをBunで使用できるようになった。このモジュールは、名前付きチャネルを作成して診断目的の任意のメッセージデータを報告するAPIを提供する。
新しいTypedArrayの高速化
モジュール解決の変更: browserとmodule exportsの条件
Bun v0.7.2では、"browser"
または"module"
パッケージ.jsonの"exports"
条件に対する対応が変更されている。これにより、以前は問題となっていたAstro CLIやaxiosなどのバグが修正されている。詳細はBunの公式ブログを参照してほしい。
2つのメモリリークの修正
Bun v0.7.2では、いくつかの重大なメモリリークが修正されている。16バイト程度のリークがあったネイティブコードによる強い参照のリークと、response.clone()
におけるメモリリークが解消されている。
その他、今回のリリースには多数のバグフィックスが含まれている。詳細は「Bun v0.7.2 Bun Blog」を参照のこと。