Releases: oven-sh/bun
Bun v0.0.55
This release is mostly just bug fixes.
CommonJS <> ESM interop reliability improvements
Bun now preserves the behavior of live bindings when referencing bundled symbols. This fixes a number of subtle bugs in different packages.
This also updates the preferred extension order depending on how code is imported. Previously, .mjs
files were ignored and that was silly. Now, when you use import
and the path has no file extension, Bun will attempt to load .mjs
or .mts
before trying .js
or .cjs
// CommonJS or `require`, `require.resolve`
// configurable via --extension-order CLI flag
pub const ExtensionOrder = [_]string{
".tsx",
".ts",
".jsx",
".cts",
".cjs",
".js",
".mjs",
".mts",
".json",
};
// ES Modules or `import`
pub const ModuleExtensionOrder = [_]string{
".tsx",
".jsx",
".mts",
".ts",
".mjs",
".js",
".cts",
".cjs",
".json",
};
Template literal parsing bug
Before, this code caused an assertion failure in Bun's JavaScript parser due to the function being defined in the template tag:
import styled from 'styled-components'
export const HoverableBox = styled.div.attrs<{
disabled?: boolean
}>(({ disabled }) => ({
cursor: disabled ? undefined : 'pointer',
}))<{ disabled?: boolean }>`
${({ disabled }) => (disabled ? 'pointer-events: none;' : '')}
`
The problem was related to when scopes for template literal tags were visited. This has been fixed.
try
& require()
Previously, this code would produce a build error:
try {
require("this-package-should-not-exist");
} catch (exception) {}
try {
await import("this-package-should-not-exist");
} catch (exception) {}
import("this-package-should-not-exist").then(
() => {},
() => {}
);
In each of these cases, errors are caught at runtime, so it should not produce a build error.
Top-level await is now enabled
Top-level await will no longer error when targeting browsers, however you should know that since Bun does not transpile for backwards compatibility, you will need to be sure it is safe to use in the target environment.
Using module.exports
with top-level await is undefined behavior
Bun v0.0.46
To upgrade:
bun upgrade
Like last release, this one is mostly bug fixes.
Better ZSH completions
The zsh completions now include flags, descriptions of subcommands, and "scripts"
appear above package bins.
Also:
- Filter out
post.*
andpre.*
scripts from completions - Filter out .js files that start with
.
from completions - Filter out builtin commands from showing up at the top
The plugin for the typeahead here is zsh-autocomplete
macOS Mojave & macOS Catalina support
For absolutely no good reason, Bun was not able to run on any macOS version before macOS 11. Now bun should work for macOS Mojave and macOS Catalina.
However, I don't have a test machine so please let me know if it still doesn't work.
Bug fixes:
- [resolver] Fix a bug with importing modules from packages using
/*.extension
in "exports" package.json and improve test coverage - [internal] Improve error messages when Bun fails to build due to a missing dependency
- [zsh] zsh completions should more reliably find a directory to put them in
- [zsh]
Command not found: compdef
previously appeared if zsh completions weren't installed. That's fixed now
Bun v0.0.45
To upgrade:
bun upgrade
This release is mostly bug fixes.
Improved fish completions
- less noisy: no more file paths unless relevant and package executables are shown on
bun run
instead ofbun
- Before the description for a script was
"script"
, now it's the actual script - If the first part of the script is
NODE_OPTIONS=".*"
(or any variation ofNODE_OPTIONS
), it's stripped out from the description. This is slightly nicer for larger repos that set--max-heap-size
Bug fixes
- [bun run] Fix bug when running
bun run yarn
or a script that runsyarn --prod
- [bun run] Fix a bug with how quotes & spaces were being passed through
- [bun create] Fix npm install/yarn install for people using Volta (symlinks)
- [bun run] Fix invoking
node
when using Volta (symlinks) - [JSX parser] Match esbuild behavior for JSX multi-line string literals and improve test coverage
- [JSX parser] Fix regression with decoding JSX entities (e.g.
&
) and improve test coverage - [JS parser] Decode input as WTF-8 instead of UTF-8. Insert a unicode replacement character for invalid unicode codepoints. Amongst other things, this fixes an error that occurred on
require("faker")
- [installer] Auto-detect when an Apple Silicon device is running on Rosetta 2 and download the arm64 version instead
Full Changelog: Jarred-Sumner/bun@bun-v0.0.44...bun-v0.0.45
Bun v0.0.44
To upgrade:
bun upgrade
Next.js 12
Bun works with Next.js 12 now. Before, it only supported 11.1.2. This includes support for React 18 (react@alpha
). React Server Components is not supported yet, but it will be. I promise :)
Other stuff
- (
bun run
) ZSH completions should auto-install correctly now. This will automatically apply when you runbun upgrade
- (
bun dev
) Fixed a mistranspilation when usingrequire
from app code to a bundled module (e.g.require("relay-devtools")
) - (
bun bun
) Fixed an issue with symlinked workspace packages when usingalwaysBundle
that prevented them from being correctly imported if enough levels of indirection were added - Fixed undefined behavior when invalid UTF-8 codepoints were inside source code text printed in an error message
- (
bun-macro-relay
) Worked around a bug that could cause it to not correctly importgraphql
depending on the environment - (
bun create
) bumped the hardcoded Next.js version set to12.0.2
- Bun.js: rename
Bun.sleep
->Bun.sleepSync
Full Changelog: Jarred-Sumner/bun@bun-v0.0.42...bun-v0.0.44
Bun v0.0.42
To upgrade:
bun upgrade
tab completions for bun run
bun run
now has tab completions for zsh and fish that show scripts
from package.json and bins from node_modules/.bin
.
Install:
bun upgrade
bun completions
Going forward, bun upgrade
also updates completions, so you shouldn't have to do that again.
Bun.js
Bun now has a builtin "supports-color"
polyfill, the package used by chalk
to detect ANSI color support.
The TypeScript in this screenshot runs 2x faster in Bun.js than in Node.js:
Other stuff:
node-fetch
&isomorphic-fetch
polyfills work now. When an npm package importsnode-fetch
, Bun.js will automatically replace it with Bun's native implementation.Bun.sleep(ms)
lets you synchronously sleep. No promises- Fixed an edgecase with the CommonJS transform that affected
export default
(thank you @evanwashere for flagging) - Several more encoding issues specific to the JavaScriptCore integration were found & fixed, though there are a couple more I still need to fix.
JavaScript Lexer
- Fixed a regression with
\0
(and added an integration test)
Misc
--version
now prints a newline at the end-v
is now shorthand for--version
- Fixed spacing with the CLI help menu (thanks @KishanBagaria for flagging)
-u
is now shorthand for--origin
. Might rename that to--url
in a future release.
Bun v0.0.41
To upgrade:
bun upgrade
What's new:
bun run
:
bun run ./file.js
now supports running JavaScript, TS, TSX, and JSX files using Bun.js. If you pass bun run
a filepath to a .js
, .jsx
, .tsx
, or .ts
file, it will run it with Bun.js instead of saying "error: Missing script"
. This is very experimental!
Bun.js
Bun.js is Bun's JavaScript runtime environment.
- Top-level await works now
performance.now()
is implemented
Bug fixes
- [.env loader] functions from bash were exported incorrectly due to parsing process environment variables similarly to
.env
files which is unnecessary. Now process environment variables are passed through without extra parsing fetch()
wasn't working due to a silly mistake. That's fixed
Bun v0.0.40
It's been a busy couple weeks.
Important: the bun-cli
npm package is deprecated. It will not receive updates.
Please upgrade Bun by running:
# Remove the npm version of bun
npm uninstall -g bun-cli
# Install the new version
curl https://bun.sh/install | bash
For future upgrades:
bun upgrade
Now the fun part.
bun run
~35x faster package.json "scripts"
runner, powered by Bun. Instead of npm run
, try bun run
.
Like npm run
, bun run
reads "scripts"
in your package.json and runs the script in a shell with the same PATH
changes as npm clients. Unlike npm clients, it's fast.
You can use bun run
in projects that aren't using Bun for transpiling or bundling. It only needs a package.json
file.
When scripts launch a Node.js process, bun run
still beats npm run
by 2x:
Why? Because npm clients launch an extra instance of Node.js. With npm run
, you wait for Node.js to boot twice. With bun run
, you wait once.
For maximum performance, if nested "scripts"
run other npm tasks, bun run
automatically runs the task with Bun instead. This means adding many tasks won't slow you down as much.
bun run
supports lifecycle hooks you expect like pre
and post
and works when the package.json
file is in a parent directory.
Two extra things:
bun run
also adds anynode_modules/.bin
executables to the PATH, so e.g. if you're using Relay, you can dobun run relay-compiler
and it will run the version ofrelay-compiler
for the specific project.bun run
has builtin support for.env
. It reads:.env.local
, then.env.development
||.env.production
(respecting yourNODE_ENV
), and.env
in the current directory or enclosing package.json's directory
Oh and you can drop the run
:
Reliability
Lots of work went into improving the reliability of Bun over the last couple weeks.
Here's what I did:
- Rewrote Bun's filesystem router for determinism and to support catch-all + optional-catch-all routes. This is an oversimplification, but the routes are sorted now
- Improved testing coverage. Bun now has integration tests that check a simple Next.js app bundles & server-side prerenders successfully. If JavaScriptCore's JIT is not enabled while server-side rendering, the tests fail. Another integration test checks that a simple Create React App loads. It uses
bun create
to bootstrap the projects. - Fix all known unicode encoding & decoding bugs. Part of what makes parsing & printing JavaScript complicated is that JavaScript officially uses UTF-16 for strings, but the rest of the files on your computer likely use UTF-8. This gets extra complicated with server-side rendering because JavaScriptCore expects either a UTF-16 string for source code or a UTF-8 string. UTF-16 strings use about twice as much memory as UTF-8 strings. Instead of wasting memory, Bun escapes the strings where necessary (but only for server-side rendering)
- Fixed several edgecases with the
.env
loader..env
values are now parsed as strings instead of something JSON-like
There's still a lot of work ahead, but Bun is getting better.
Sometimes, speed and reliability is a tradeoff. This time, it's not. Bun seems to be about 3% faster overall compared to the last version (v0.0.36). Why? Mostly due to many small changes to the lexer. Inlining iterators is good.
Bun v0.0.36
bun create
bun create
is a new subcommand that lets you quickly create a project from a template.
To create a new React project (based on Create React App)
bun create react ./app
11x faster than yarn create react app
on my Macbook Pro (both installing dependencies via yarn)
To create a new Next.js project (based on Create Next App)
bun create next ./app
To create from a GitHub repository:
bun create jarred-sumner/calculator calc
To see a list of templates:
bun create
Right now, there are only two "official" templates (and they're mostly empty) – but you can add more. bun create
fetches from packages published in the examples
folder of Bun's GitHub repo. PRs are very welcome!
Local templates
Many developers have boilerplate code copied for new projects.
That's why bun create
also searches $HOME/.bun-create
for local templates.
Add a folder with a package.json in $HOME/.bun-create/my-local-template
and then you can run:
bun create my-local-template ./foo
This copies the contents of my-local-template
, initializes a git repository, runs any preinstall steps, installs dependencies (if any exist), runs any postinstall steps and rewrites the name
field in package.json
to foo
.
It uses the fastest system calls available for copying files. bun create
copies files faster than cp
. Here is a stupid microbenchmark
Performance
The slowest part is running your NPM client to install node_modules
. The second slowest part is downloading the tarball from GitHub (or NPM if it's from Bun's examples folder). Third is git.
Other stuff
fetch
now supports gzip- https support in
fetch
was completely rewritten to be more reliable. TLS is now powered by s2n-tls fetch
now supportsTransfer-Encoding: chunked
. It didn't before, which was embarrassing.- Set
self
toglobalThis
in Bun.js. This improves compatibility with some npm packages - There are two new test binaries in
misctools/
,tgz
andfetch
.tgz
is likegunzip
except harder to use andfetch
is sort of likecurl
? These are really just to help me test some things in isolation from the rest of Bun
Bun v0.0.34
Features
Slightly better tsconfig.json
handling:
jsxImportSource
support – if you setjsxImportSource
to"@emotion/react"
, JSX will auto-import from"@emotion/react/jsx-dev-runtime"
instead of"react/jsx-dev-runtime"
jsxFragmentFactory
support – this lets you override what<>
transforms into. By default it's"Fragment"
, since<>
becomesReact.Fragment
normally.jsxFactory
support – if you setjsxFactory
to"h"
, when using the classic JSX runtime, it will runh
instead ofcreateElement
This makes it easier to use @emotion/react
, preact
, and other JSX runtimes with Bun.
Bug fixes
- [fetch] Fix bug with HTTP request bodies for http (not https) requests
- Fix JSX transform edgecase with static children to match Babel's behavior (static ===
children.length > 1
) - Fix node_module resolver edgecase when resolving from the dev server (not
bun bun
) that happened when resolving workspace packages above the project root that expect dependencies from the project. This applied to pnpm
Other:
- Add a small end-to-end test for emotion JSX
- Add a small end-to-end test for React Context.Provider & Context.Consumer
- Add analytics
Bun v0.0.32
Bug fixes
- [Linux] Fix Bun failing to start when the system-installed version of ICU didn't match the dynamically linked version. The fix here is to statically link ICU. This unfortunately doubles the binary size of Bun on Linux
- Fix running
bun bun
on a networked filesystem. This is particularly relevant to WSL. The normal posix C function for moving files doesn't work if the source file is on a different mounted filesystem than the target. This fix detects the error and attempts to use sendfile() so that it copies the file faster than it would by reading the memory manually.