We're hiring C/C++ and Zig engineers to build the future of JavaScript! See job listings →
This is the biggest release of Bun yet.
Bun now has a built-in JavaScript and TypeScript bundler and minifier. Use it to bundle frontend apps or bundle your code into a standalone executable.
We've also been busy improving performance and fixing bugs as-per usual: writeFile()
gets up to 20% faster on Linux, lots of bug fixes to Node.js compatiblity and Web API compatiblity, support for TypeScript 5.0 syntax, and various fixes to bun install
.
Bun's new JavaScript bundler & minifier
The focus of this release is Bun's new JavaScript bundler, but the bundler is just the beginning of a larger project. In the next couple months, we'll be announcing Bun.App
— a "super-API" that stitches together Bun's native-speed bundler, HTTP server, and file system router into a cohesive whole.
It can be used using the bun build
CLI command or the new Bun.build()
JavaScript API.
Bun.build({
entrypoints: ["./src/index.tsx"],
outdir: "./build",
minify: true,
// ...
});
bun build ./src/index.tsx --outdir ./build --minify
To learn more, check out our blog post introducing the Bun bundler.
Standalone executables
You can now create standalone executables with bun build
.
bun build --compile ./foo.ts
This lets you distribute your app as a single executable file, without requiring users to install Bun.
./foo
You can also minify it to improve startup performance for large apps:
bun build --minify --compile ./three.ts
[32ms] minify -123 KB (estimate)
[50ms] bundle 456 modules
[107ms] compile three
This is powered by Bun's new JavaScript bundler and minifier.
Standalone executables are coming in Bun v0.6.0 pic.twitter.com/eaUeFtKisL
— Jarred Sumner (@jarredsumner) May 14, 2023
import.meta.main
You can now use import.meta.main
to check if the current file is the entry point that started bun. This is useful for CLIs to determine if the current file is what started the app.
For example, if you have a file called index.ts
:
console.log(import.meta.main);
And you run it:
$ bun ./index.ts
true
But if you import it:
import "./index.ts";
And run it:
$ bun ./other.ts
false
Improvements to bun test
bun test
now reports time taken to run tests
in the next version of bun
— Jarred Sumner (@jarredsumner) May 11, 2023
bun:test prints out how long each test took
slow tests are highlighted yellow pic.twitter.com/yXDSJrkYBu
describe.skip
has been implemented (thanks to _yogr)expect().toBeEven()
andexpect().toBeOdd()
has been implemented (thanks to will-richards-ii)
Faster fs.writeFile
on Linux
In the next version of Bun
— Jarred Sumner (@jarredsumner) April 27, 2023
fs.writeFile gets 20% faster for large files on Linux pic.twitter.com/QgWhBoiz2c
Transpiler improvements
This release also introduces many improvements to the transpiler. Here are some of the highlights:
- Parser support for TypeScript 5.0.
- Parser support for import attributes.
- Some npm packages threw "ReferenceError: Cannot access uninitialized variable" errors on import due to a bug with cyclical imports in Bun's transpiler. This has been fixed.
- Support for
// @jsx
,// @jsxImportSource
, and// @jsxFragment
comments. - Dead code elimination for unused global constructor function calls like
new Set()
. - String template literal concatenation like
foo${1}${"2"}${'3'}
->foo123
. - Parser bugfixes for the deprecated ES5
with
statement.
A big thanks to @kzc for many helpful bug reports.
Node.js compatibility
tls.Server
has basic support (previously, not implemented)fs.promises.constants
is now exported correctly (previously, it was missing)node:http
's server module now (correctly) accepts acallback
argumentTimer.refresh()
now works as expected- Fixed
mkdtemp
andmkdtempSync
errors
Web API compatibility
new Request("http://example.com", otherRequest).url
would previously return the url ofotherRequest
instead of"http://example.com"
. This has been fixed.Bun.file(path).lastModified
has been added, which is similar to theFile
API'slastModified
property- Supported
redirect: "error"
infetch()
- Fixed
fetch.bind
,fetch.call
, andfetch.apply
not working
Changelog
#2556 | Implemented import.meta.main by @Jarred-Sumner |
#2561 | Removed Object.prototype from node:path exports by @privatenumber |
#2557 | Fixed Bun.deepEquals() with accessors and holed arrays by @dylan-conway |
#2554 | Fixed issues with fetch({ proxy }) by @cirospaciari |
#2491 | Implemented BunFile.lastModified by @zhongweiy |
#2567 | Fixed constants export from node:fs/promises by @paperclover |
#2552 | Implemented basic support for tls.Server by @cirospaciari |
#2593 | Implemented support for TypeScript 5.0 syntax by @Jarred-Sumner |
#2652 | Improved performance of crypto.createHash() by @paperclover |
#2661 | Fixed a bug where expect().toBeFalsy() did not increment assertions by @will-richards-ii |
#2673 | Implemented support for axios by @Jarred-Sumner |
9e1745e | Fixed a bug with path.dirname() would return the wrong path for the root by @Jarred-Sumner |
#2728 | Fixed bun add <github> by @alexlamsl |
3c4f092 | remove by @Jarred-Sumner |
5353d41 | Fixed incorrect value for modulo with negative operands by @Jarred-Sumner |
#2748 | Fixed crash with invalid JavaScript by @Jarred-Sumner |
#2759 | Improved performance of open() and writeFileSync() by @Jarred-Sumner |
#2761 | Fixed incorrect output from Hash.copy() by @silversquirl |
396416a | Fixed crash from invalid input in fetch() by @Jarred-Sumner |
#2780 | Fixed a bug with repeated bun install of a GitHub dependency by @alexlamsl |
#2781 | Fixed a bug where devDependencies did not resolve from a local dependency by @alexlamsl |
#2754 | Implemented expect().toBeEven() and expect().toBeOdd() by @will-richards-ii |
c43c1b5 | Implemented ClientRequest.setNoDelay() by @Electroid |
f95a81e | Fixed a crash in napi_create_external_buffer by @Jarred-Sumner |
c7c5dc1 | Implemented BunFile.name by @Jarred-Sumner |
#2834 | Fixed a bug where bun install --cwd was not working correctly by @alexlamsl |
#2841 | Changed bun add to ignore invalid workspaces by @alexlamsl |
#2843 | Fixed a crash during WebSocket.close() by @cirospaciari |
#2842 | Fixed fetch.bind is not a function by @cirospaciari |
#2845 | Implemented fetch({ redirect: "error" }) by @cirospaciari |
#2836 | Implemented describe.skip() by @blackmann |
5ffee94 | Added timings to each test in bun test by @Jarred-Sumner |
#2846 | Implemented dns.lookup({ all: true }) by @cirospaciari |
#2851 | Fixed suprious errors with mkdtemp() and mktempSync() by @cirospaciari |
5c08200 | Changed node:http to handle errors better from fetch() by @Jarred-Sumner |
#2850 | Fixed Bun.spawn() with a large stdout by @cirospaciari |
#2869 | Fixed node:path for Windows by @paperclover |
#2879 | Implemented support for generating standalone Bun executables by @Jarred-Sumner |
#2866 | Implemented Uint8Array support for Bun.spawn() stdout by @cirospaciari |
#2881 | Fixed bug where Request.url was incorrect by @Jarred-Sumner |
Contributors
And finally, thank you to all the contributors from the community that helped improve Bun this release: @privatenumber, @Lawlzer, @jakeboone02, @zhongweiy, @xHyroM, @rmorey, @marktani, @Kruithne, @will-richards-ii, @simon04, @alexlamsl, @flakey5, @MaanuVazquez, @Plecra, @silversquirl, @beeburrt, @aquapi, @blackmann, @Fire-The-Fox