0
Fork 0
mirror of https://github.com/oven-sh/bun.git synced 2026-11-16 19:10:59 +00:00
Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one https://bun.com
  • Rust 76.5%
  • C++ 12.4%
  • TypeScript 8.8%
  • JavaScript 1.1%
  • C 0.9%
  • Other 0.1%
Find a file
Alistair Smith 3ddacf00ee
dev server: split the module loader and replaceModules into smaller functions (#49078)
This is a refactor of the dev server's module loader. It does not change
behavior.

It makes `src/runtime/bake/hmr-module.ts` easier to change. The fixes
for hot updates come in later PRs.

What changed

- `loadModuleSync` and `loadModuleAsync` had the same code four times to
make or reuse a module record. It is now `prepareModule`.
- The code that makes the CommonJS `module` object was there three
times. It is now `createCJSModule`.
- The debug checks of a bundled ES module were there twice, one copy
with plain numbers. They are now `assertUnloadedESM`. A failed debug
check no longer also prints the module.
- The last step of an ES module load was there three times. It is now
`finishESMExports`.
- `replaceModules` was one long function. Its steps are now
`findBoundaries`, `reportFailures`, `disposeModules` and
`reloadModules`. They run in the same order.

Visible changes

The depth of a very long import chain that fits on the stack moves a
little. A chain of `import` goes from 10,353 modules to 11,290. A chain
of `require` goes from 10,696 to 10,345. With the DFG JIT off, the
`require` depth does not change.

Testing

- I ran random apps on both loaders. Each app has ES modules, CommonJS,
top-level await, `accept`, `dispose`, `import()`, errors and saves. I
compared every step. In 11,000 apps nothing was different.
- These apps have no import circles, because a save in a circle can hang
the loader on main. That is a separate fix.
- Four broken copies of the refactor made the same test fail.
- The dev server tests that I can run gave the same results on both
loaders. The browser tests run only in CI.
- There is no new test, because behavior does not change.
History 2026-11-16 11:08:55 -08:00
.buildkite image: replace libjpeg-turbo with a JPEG codec in Rust (#49024) 2026-11-15 23:02:07 -08:00
.cargo Rewrite Bun in Rust (#30412) 2026-05-14 01:09:34 -07:00
.claude usockets: the TLS layer is C++, and what it allocates has an owner (#49074) 2026-11-15 22:32:23 -08:00
.cursor chore: convert .cursor/rules to .claude/skills (#25683) 2025-12-24 23:37:26 -08:00
.github Upgrade Rust nightly to 2026-11-14 (#49051) 2026-11-15 17:39:29 -08:00
.vscode Revert "Build JavaScriptCore and ICU from source in bun's own build graph on every target (#41330)" 2026-09-07 15:59:20 -07:00
bench image: replace libjpeg-turbo with a JPEG codec in Rust (#49024) 2026-11-15 23:02:07 -08:00
completions AOT: frames of built-ins, options, crash reports, files that throw, bound functions of node:fs (#49004) 2026-11-15 10:49:53 -08:00
dockerhub release: fix the Homebrew job and a flaky Docker download (#46498) 2026-10-22 11:04:28 -07:00
docs AOT: stores into enums, children of wrapped functions, JSX settings, order files, and tests of the engine's fixes (#49081) 2026-11-16 04:23:46 -08:00
misctools Upgrade WebKit to 8156ba68efab (#48297) 2026-11-11 15:00:24 -08:00
packages AOT: stores into enums, children of wrapped functions, JSX settings, order files, and tests of the engine's fixes (#49081) 2026-11-16 04:23:46 -08:00
patches image: replace libjpeg-turbo with a JPEG codec in Rust (#49024) 2026-11-15 23:02:07 -08:00
scripts Remove workarounds the new Rust nightly makes unnecessary (#49098) 2026-11-16 10:18:36 -08:00
src dev server: split the module loader and replaceModules into smaller functions (#49078) 2026-11-16 11:08:55 -08:00
test http: a request in flight has one owner (#49088) 2026-11-16 10:49:56 -08:00
tools/hawk Remove workarounds the new Rust nightly makes unnecessary (#49098) 2026-11-16 10:18:36 -08:00
.aikido Remove the @types/bun alias, pin the root devDependencies, and add --package-manager=npm (#41225) 2026-09-03 17:27:59 -07:00
.bk.yaml scripts: replace buildkite-failures.ts with bk-backed ci:* helpers (#28877) 2026-04-04 17:41:26 -07:00
.clang-tidy Reapply "Convert build scripts to CMake (#13427)" 2024-09-11 08:24:50 -07:00
.clangd meta: fix disabling of clangd auto header insertion (#17172) 2025-02-10 02:04:21 -08:00
.coderabbit.yaml Disable coderabbit enrichment 2025-12-18 18:03:23 -08:00
.cursorignore Remove dead code from bun-uws, the native BufferList class, built-in JS, the bake dev server assets, the shell, and the SQL crates (#40066) 2026-08-22 23:39:14 -07:00
.dockerignore Remove dead code from bun-uws, the native BufferList class, built-in JS, the bake dev server assets, the shell, and the SQL crates (#40066) 2026-08-22 23:39:14 -07:00
.editorconfig Bring uSockets & uWebSockets forks into Bun's repository (#4372) 2023-08-28 08:38:30 -07:00
.git-blame-ignore-revs Update .git-blame-ignore-revs 2025-06-13 16:16:14 -07:00
.gitattributes AOT: bun compile, build output, module mocks, fixes and new names (#48436) 2026-11-10 05:38:22 -08:00
.gitignore http: replace picohttpparser with a Rust parser (#49033) 2026-11-15 20:02:31 -08:00
.lldbinit Move LLDB initialization commands to make attach configuration work (#20085) 2025-05-30 19:33:03 -07:00
.mailmap do not print duplicate code (#16231) 2025-01-07 20:19:12 -08:00
.prettierignore AOT: the Bun side of the rewritten ahead-of-time compiler (#47942) 2026-11-07 13:21:27 -08:00
.prettierrc One bindgen: replace bindgen v1 and v2, add classes, generate the Rust side (#45104) 2026-10-15 20:23:52 -07:00
AGENTS.md Make AGENTS.md a symlink to CLAUDE.md 2025-06-27 21:13:21 -07:00
bun.lock ci: use bun lint and bun fmt; docs: a Linter tab (#45119) 2026-10-13 00:10:32 -07:00
bunfig.node-test.toml node:module compatibility pt 1 (#18106) 2025-03-12 15:47:41 -07:00
bunfig.toml ci: use bun lint and bun fmt; docs: a Linter tab (#45119) 2026-10-13 00:10:32 -07:00
Cargo.lock sys, windows: Win32 wrappers take terminated strings and slices, and return owned handles (#49094) 2026-11-16 10:43:48 -08:00
Cargo.toml Remove workarounds the new Rust nightly makes unnecessary (#49098) 2026-11-16 10:18:36 -08:00
CLAUDE.md http: replace picohttpparser with a Rust parser (#49033) 2026-11-15 20:02:31 -08:00
clippy.toml bun lint, bun fmt: the first run, oxlint's order, Prettier's Tailwind plugin, native JavaScript plugins, a faster Bun.Glob (#45043) 2026-10-12 23:23:46 -07:00
CODE_OF_CONDUCT.md Add a code of conduct 2022-09-03 20:54:15 -07:00
CONTRIBUTING.md Compile TypeScript to machine code ahead of time: bun build --compile --aot (#45631) 2026-10-27 16:50:41 -07:00
entitlements.debug.plist Faster debug builds (#16354) 2025-01-12 20:03:24 -08:00
entitlements.plist New subcommand: bun upgrade. It upgrades bun to the latest version. 2021-10-28 05:34:38 -07:00
flake.lock Upgrade LLVM 21.1.8 → 23.1.1 and Rust nightly to 2026-09-15 (#42851) 2026-09-16 01:45:17 -07:00
flake.nix ci: content-addressed machine images (#43608) 2026-09-20 03:38:01 -07:00
hawk.toml Remove workarounds the new Rust nightly makes unnecessary (#49098) 2026-11-16 10:18:36 -08:00
LATEST Bump to 1.4.5 (#48774) 2026-11-12 16:11:36 -08:00
LICENSE.md image: replace libjpeg-turbo with a JPEG codec in Rust (#49024) 2026-11-15 23:02:07 -08:00
mordant-baseline.toml http: a request in flight has one owner (#49088) 2026-11-16 10:49:56 -08:00
mordant.toml Remove 131 unsafe blocks from Blob, Bun.write, FileSink, fetch, Response and the S3 client (#47895) 2026-11-04 00:18:34 -08:00
oxlint.json AOT: Bun's side of the compiler's new optimizations, with fixes and tests (#48120) 2026-11-09 16:48:28 -08:00
package.json Bump to 1.4.5 (#48774) 2026-11-12 16:11:36 -08:00
README.md Compile TypeScript to machine code ahead of time: bun build --compile --aot (#45631) 2026-10-27 16:50:41 -07:00
REVIEW.md bindgen: move the remaining 61 classes to schemas and delete generate-classes.ts (#46329) 2026-10-22 14:59:52 -07:00
rust-toolchain.toml Remove workarounds the new Rust nightly makes unnecessary (#49098) 2026-11-16 10:18:36 -08:00
rustfmt.toml HTMLRewriter: use the lol_html Rust crate directly instead of its C API (#33048) 2026-06-29 15:30:52 -07:00
SECURITY.md bun.sh -> bun.com (#20909) 2025-07-10 00:10:43 -07:00
shell.nix ci: content-addressed machine images (#43608) 2026-09-20 03:38:01 -07:00
tsconfig.base.json Add new bindings generator; port SSLConfig (#23169) 2025-10-03 17:10:28 -07:00
tsconfig.json Fix clippy, rustfmt, Miri, and stale tsconfig references on main (#37078) 2026-08-06 18:22:58 -07:00

Logo

Bun

stars Bun speed

Documentation   •   Discord   •   Issues   •   Roadmap

Read the docs →

What is Bun?

Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable called bun.

At its core is the Bun runtime, a fast JavaScript runtime designed as a drop-in replacement for Node.js. It's written in Rust and powered by JavaScriptCore under the hood, dramatically reducing startup times and memory usage.

bun run index.tsx             # TS and JSX supported out-of-the-box

The bun command-line tool also implements a test runner, script runner, and Node.js-compatible package manager. Instead of 1,000 node_modules for development, you only need bun. Bun's built-in tools are significantly faster than existing options and usable in existing Node.js projects with little to no changes.

bun test                      # run tests
bun run start                 # run the `start` script in `package.json`
bun install <pkg>             # install a package
bunx cowsay 'Hello, world!'   # execute a package

Install

Bun supports Linux (x64 & arm64), macOS (x64 & Apple Silicon), and Windows (x64 & arm64).

Linux users — Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1.

x64 users — if you see "illegal instruction" or similar errors, check our CPU requirements

# with install script (recommended)
curl -fsSL https://bun.com/install | bash

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

# with npm
npm install -g bun

# with Homebrew
brew tap oven-sh/bun
brew install bun

# with Docker
docker pull oven/bun
docker run --rm --init --ulimit memlock=-1:-1 oven/bun

Upgrade

To upgrade to the latest version of Bun, run:

bun upgrade

Bun automatically releases a canary build on every commit to main. To upgrade to the latest canary build, run:

bun upgrade --canary

View canary build

Guides

Contributing

Refer to the Project > Contributing guide to start contributing to Bun.

License

Refer to the Project > License page for information about Bun's licensing.