Bun 1.0 has released its fourth patch update: 1.0.4 .
Bun is an extremely fast JavaScript runtime written in Zig that combines a bundler, translator, and package manager.
This release fixes 62 bugs, adds server.requestIP
support for virtual modules in runtime plugins, and reduces Bun.serve()
memory consumption in .
- Reduce
Bun.serve()
memory consumption in
Bun.serve()
Manually managed per-request memory usage is now reported to JavaScriptCore's garbage collector. In some cases, this Bun.serve()
reduces memory usage by 50%.
- accomplish
server.requestIP
server.requestIP()
A given IP address can now be retrieved using Request
.
Bun.serve({
port: 3000,
handler: (req, res) => {
console.log(server.requestIP(req));
},
});
Bun.plugin
Virtual Module in
Bun's plugin system has become more flexible and compatible with esbuild. In addition to custom loaders ( import stuff from "./stuff.foo"
), it now supports fully virtual modules ( import stuff from "foo"
). Developers can register virtual modules by registering plug-ins.
import { plugin } from "bun";
plugin({
name: "my plugin",
setup(builder) {
builder.module("my-virtual-module", () => {
return {
exports: {
hello: "world",
},
loader: "object",
};
});
},
});
This virtual module can then be used like a normal module:
import { hello } from "my-virtual-module";
console.log(hello); // "world"
// require("my-virtual-module") also works
// await import("my-virtual-module") also works
// require.resolve("my-virtual-module") also works
Details .