Skip to content

docs: update documentation for Bun v1.3.2 features#24503

Merged
lydiahallie merged 12 commits into
mainfrom
claude/docs-bun-v1.3.2-updates
Nov 11, 2025
Merged

docs: update documentation for Bun v1.3.2 features#24503
lydiahallie merged 12 commits into
mainfrom
claude/docs-bun-v1.3.2-updates

Conversation

@robobun

@robobun robobun commented Nov 8, 2025

Copy link
Copy Markdown
Collaborator

Summary

Updates documentation for all major features and changes introduced in Bun v1.3.2 blog post.

Changes

Package Manager

  • ✅ Document configVersion system for controlling default linker behavior
  • ✅ Clarify that "existing projects (made pre-v1.3.2)" use hoisted installs for backward compatibility
  • ✅ Add smart postinstall script optimization with environment variable flags
  • ✅ Document improved Git dependency resolution with HTTP tarball optimization
  • ✅ Add bun list alias for bun pm ls

Testing

  • ✅ Document new onTestFinished lifecycle hook with simple example
  • ✅ Add to lifecycle hooks table in test documentation

Runtime & Performance

  • ✅ Add CPU profiling with --cpu-prof flag documentation
  • ✅ Place after memory usage section for better flow

WebSockets

  • ✅ Add subscriptions getter to existing pub/sub example
  • ✅ Add TypeScript reference for the subscriptions property

Documentation Improvements

All documentation now consistently:

  • Uses "made pre-v1.3.2" to clarify existing project behavior
  • Simplifies default linker explanations with clear references to /docs/pm/isolated-installs
  • Uses /docs/pm/isolated-installs for all internal references
  • Avoids confusing technical details in favor of user-friendly summaries

Files Modified

  • docs/guides/install/add-git.mdx - Added GitHub tarball optimization note
  • docs/pm/cli/install.mdx - Added installation strategies and smart postinstall docs
  • docs/pm/cli/pm.mdx - Added bun list alias
  • docs/pm/isolated-installs.mdx - Updated default behavior section with configVersion table
  • docs/project/benchmarking.mdx - Added CPU profiling section
  • docs/runtime/bunfig.mdx - Clarified install.linker defaults
  • docs/runtime/http/websockets.mdx - Added subscriptions to example and TypeScript interface
  • docs/test/lifecycle.mdx - Added onTestFinished hook documentation

Diff

diff --git a/docs/guides/install/add-git.mdx b/docs/guides/install/add-git.mdx
index 70950e1a63..7f8f3c8d81 100644
--- a/docs/guides/install/add-git.mdx
+++ b/docs/guides/install/add-git.mdx
@@ -33,6 +33,8 @@ bun add git@github.com:lodash/lodash.git
 bun add github:colinhacks/zod
 ```
 
+**Note:** GitHub dependencies download via HTTP tarball when possible for faster installation.
+
 ---
 
 See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
diff --git a/docs/pm/cli/install.mdx b/docs/pm/cli/install.mdx
index 7affb62646..dde268b7e5 100644
--- a/docs/pm/cli/install.mdx
+++ b/docs/pm/cli/install.mdx
@@ -88,6 +88,13 @@ Lifecycle scripts will run in parallel during installation. To adjust the maximu
 bun install --concurrent-scripts 5
 ```
 
+Bun automatically optimizes postinstall scripts for popular packages (like `esbuild`, `sharp`, etc.) by determining which scripts need to run. To disable these optimizations:
+
+```bash terminal icon="terminal"
+BUN_FEATURE_FLAG_DISABLE_NATIVE_DEPENDENCY_LINKER=1 bun install
+BUN_FEATURE_FLAG_DISABLE_IGNORE_SCRIPTS=1 bun install
+```
+
 ---
 
 ## Workspaces
@@ -231,7 +238,7 @@ Bun supports installing dependencies from Git, GitHub, and local or remotely-hos
 
 Bun supports two package installation strategies that determine how dependencies are organized in `node_modules`:
 
-### Hoisted installs (default for single projects)
+### Hoisted installs
 
 The traditional npm/Yarn approach that flattens dependencies into a shared `node_modules` directory:
 
@@ -249,7 +256,15 @@ bun install --linker isolated
 
 Isolated installs create a central package store in `node_modules/.bun/` with symlinks in the top-level `node_modules`. This ensures packages can only access their declared dependencies.
 
-For complete documentation on isolated installs, refer to [Package manager > Isolated installs](/pm/isolated-installs).
+### Default strategy
+
+The default linker strategy depends on whether you're starting fresh or have an existing project:
+
+- **New workspaces/monorepos**: `isolated` (prevents phantom dependencies)
+- **New single-package projects**: `hoisted` (traditional npm behavior)
+- **Existing projects (made pre-v1.3.2)**: `hoisted` (preserves backward compatibility)
+
+The default is controlled by a `configVersion` field in your lockfile. For a detailed explanation, see [Package manager > Isolated installs](/docs/pm/isolated-installs).
 
 ---
 
@@ -319,8 +334,7 @@ dryRun = false
 concurrentScripts = 16 # (cpu count or GOMAXPROCS) x2
 
 # installation strategy: "hoisted" or "isolated"
-# default: "hoisted" (for single-project projects)
-# default: "isolated" (for monorepo projects)
+# default varies by project type - see /docs/pm/isolated-installs
 linker = "hoisted"
 
 
diff --git a/docs/pm/cli/pm.mdx b/docs/pm/cli/pm.mdx
index fc297753d3..9c8faa7da1 100644
--- a/docs/pm/cli/pm.mdx
+++ b/docs/pm/cli/pm.mdx
@@ -115,6 +115,8 @@ To print a list of installed dependencies in the current project and their resol
 
 ```bash terminal icon="terminal"
 bun pm ls
+# or
+bun list
 ```
 
 ```txt
@@ -130,6 +132,8 @@ To print all installed dependencies, including nth-order dependencies.
 
 ```bash terminal icon="terminal"
 bun pm ls --all
+# or
+bun list --all
 ```
 
 ```txt
diff --git a/docs/pm/isolated-installs.mdx b/docs/pm/isolated-installs.mdx
index 73c6748b15..17afe02fe1 100644
--- a/docs/pm/isolated-installs.mdx
+++ b/docs/pm/isolated-installs.mdx
@@ -5,7 +5,7 @@ description: "Strict dependency isolation similar to pnpm's approach"
 
 Bun provides an alternative package installation strategy called **isolated installs** that creates strict dependency isolation similar to pnpm's approach. This mode prevents phantom dependencies and ensures reproducible, deterministic builds.
 
-This is the default installation strategy for monorepo projects.
+This is the default installation strategy for **new** workspace/monorepo projects (with `configVersion = 1` in the lockfile). Existing projects continue using hoisted installs unless explicitly configured.
 
 ## What are isolated installs?
 
@@ -43,8 +43,23 @@ linker = "isolated"
 
 ### Default behavior
 
-- For monorepo projects, Bun uses the **isolated** installation strategy by default.
-- For single-project projects, Bun uses the **hoisted** installation strategy by default.
+The default linker strategy depends on your project's lockfile `configVersion`:
+
+| `configVersion` | Using workspaces? | Default Linker |
+| --------------- | ----------------- | -------------- |
+| `1`             | ✅                | `isolated`     |
+| `1`             | ❌                | `hoisted`      |
+| `0`             | ✅                | `hoisted`      |
+| `0`             | ❌                | `hoisted`      |
+
+**New projects**: Default to `configVersion = 1`. In workspaces, v1 uses the isolated linker by default; otherwise it uses hoisted linking.
+
+**Existing Bun projects (made pre-v1.3.2)**: If your existing lockfile doesn't have a version yet, Bun sets `configVersion = 0` when you run `bun install`, preserving the previous hoisted linker default.
+
+**Migrations from other package managers**:
+
+- From pnpm: `configVersion = 1` (using isolated installs in workspaces)
+- From npm or yarn: `configVersion = 0` (using hoisted installs)
 
 You can override the default behavior by explicitly specifying the `--linker` flag or setting it in your configuration file.
 
diff --git a/docs/project/benchmarking.mdx b/docs/project/benchmarking.mdx
index 1263a06729..2ab8bcafc8 100644
--- a/docs/project/benchmarking.mdx
+++ b/docs/project/benchmarking.mdx
@@ -216,3 +216,26 @@ numa nodes:       1
    elapsed:       0.068 s
    process: user: 0.061 s, system: 0.014 s, faults: 0, rss: 57.4 MiB, commit: 64.0 MiB
 ```
+
+## CPU profiling
+
+Profile JavaScript execution to identify performance bottlenecks with the `--cpu-prof` flag.
+
+```sh terminal icon="terminal"
+bun --cpu-prof script.js
+```
+
+This generates a `.cpuprofile` file you can open in Chrome DevTools (Performance tab → Load profile) or VS Code's CPU profiler.
+
+### Options
+
+```sh terminal icon="terminal"
+bun --cpu-prof --cpu-prof-name my-profile.cpuprofile script.js
+bun --cpu-prof --cpu-prof-dir ./profiles script.js
+```
+
+| Flag                         | Description          |
+| ---------------------------- | -------------------- |
+| `--cpu-prof`                 | Enable profiling     |
+| `--cpu-prof-name <filename>` | Set output filename  |
+| `--cpu-prof-dir <dir>`       | Set output directory |
diff --git a/docs/runtime/bunfig.mdx b/docs/runtime/bunfig.mdx
index 91005c1607..5b7fe49823 100644
--- a/docs/runtime/bunfig.mdx
+++ b/docs/runtime/bunfig.mdx
@@ -497,9 +497,9 @@ print = "yarn"
 
 ### `install.linker`
 
-Configure the default linker strategy. Default `"hoisted"` for single-project projects, `"isolated"` for monorepo projects.
+Configure the linker strategy for installing dependencies. Defaults to `"isolated"` for new workspaces, `"hoisted"` for new single-package projects and existing projects (made pre-v1.3.2).
 
-For complete documentation refer to [Package manager > Isolated installs](/pm/isolated-installs).
+For complete documentation refer to [Package manager > Isolated installs](/docs/pm/isolated-installs).
 
 ```toml title="bunfig.toml" icon="settings"
 [install]
diff --git a/docs/runtime/http/websockets.mdx b/docs/runtime/http/websockets.mdx
index b33f37c29f..174043200d 100644
--- a/docs/runtime/http/websockets.mdx
+++ b/docs/runtime/http/websockets.mdx
@@ -212,6 +212,9 @@ const server = Bun.serve({
       // this is a group chat
       // so the server re-broadcasts incoming message to everyone
       server.publish("the-group-chat", `${ws.data.username}: ${message}`);
+
+      // inspect current subscriptions
+      console.log(ws.subscriptions); // ["the-group-chat"]
     },
     close(ws) {
       const msg = `${ws.data.username} has left the chat`;
@@ -393,6 +396,7 @@ interface ServerWebSocket {
   readonly data: any;
   readonly readyState: number;
   readonly remoteAddress: string;
+  readonly subscriptions: string[];
   send(message: string | ArrayBuffer | Uint8Array, compress?: boolean): number;
   close(code?: number, reason?: string): void;
   subscribe(topic: string): void;
diff --git a/docs/test/lifecycle.mdx b/docs/test/lifecycle.mdx
index 6427175df6..3837f0e948 100644
--- a/docs/test/lifecycle.mdx
+++ b/docs/test/lifecycle.mdx
@@ -6,11 +6,12 @@ description: "Learn how to use beforeAll, beforeEach, afterEach, and afterAll li
 The test runner supports the following lifecycle hooks. This is useful for loading test fixtures, mocking data, and configuring the test environment.
 
 | Hook             | Description                                                |
-| ------------ | --------------------------- |
+| ---------------- | ---------------------------------------------------------- |
 | `beforeAll`      | Runs once before all tests.                                |
 | `beforeEach`     | Runs before each test.                                     |
 | `afterEach`      | Runs after each test.                                      |
 | `afterAll`       | Runs once after all tests.                                 |
+| `onTestFinished` | Runs after a single test finishes (after all `afterEach`). |
 
 ## Per-Test Setup and Teardown
 
@@ -90,6 +91,23 @@ describe("test group", () => {
 });
 ```
 
+### `onTestFinished`
+
+Use `onTestFinished` to run a callback after a single test completes. It runs after all `afterEach` hooks.
+
+```ts title="test.ts" icon="/icons/typescript.svg"
+import { test, onTestFinished } from "bun:test";
+
+test("cleanup after test", () => {
+  onTestFinished(() => {
+    // runs after all afterEach hooks
+    console.log("test finished");
+  });
+});
+```
+
+Not supported in concurrent tests; use `test.serial` instead.
+
 ## Global Setup and Teardown
 
 To scope the hooks to an entire multi-file test run, define the hooks in a separate file.

🤖 Generated with Claude Code

@robobun

robobun commented Nov 8, 2025

Copy link
Copy Markdown
Collaborator Author
Updated 6:14 PM PT - Nov 10th, 2025

@lydiahallie, your commit e274a102225503caf9035dd69a97b40ffc3f3959 passed in Build #31473! 🎉


🧪   To try this PR locally:

bunx bun-pr 24503

That installs a local version of the PR into your bun-24503 executable, so you can run:

bun-24503 --bun

@coderabbitai

coderabbitai Bot commented Nov 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Documentation updates: installer/linker defaults and GitHub tarball note; CLI aliases and postinstall flags; new ServerWebSocket.subscriptions API docs; added onTestFinished lifecycle hook; and CPU profiling guidance in benchmarking docs.

Changes

Cohort / File(s) Change summary
Package manager install & config
docs/guides/install/add-git.mdx, docs/pm/cli/install.mdx, docs/pm/cli/pm.mdx, docs/pm/isolated-installs.mdx, docs/runtime/bunfig.mdx
Added note that GitHub dependencies download via HTTP tarball when possible; documented Bun postinstall optimizations and feature-flags; introduced a "Default strategy" for linker behavior by configVersion/workspace status; added bun list aliases; updated install.linker description and links.
Runtime API — WebSockets
docs/runtime/http/websockets.mdx
Documented new readonly subscriptions: string[] property on ServerWebSocket and added runtime example logging ws.subscriptions.
Testing lifecycle
docs/test/lifecycle.mdx
Added onTestFinished lifecycle hook docs, table entry, examples (sync/async/done), and notes about concurrency and scope.
Benchmarking guide
docs/project/benchmarking.mdx
Added CPU profiling subsection with example commands and flags (--cpu-prof, --cpu-prof-name, --cpu-prof-dir) and related guidance.

Possibly related PRs

Suggested reviewers

  • alii

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change—updating documentation for Bun v1.3.2 features across multiple docs files.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering all major changes, files modified, and improvements, though it doesn't follow the exact template format.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5996050 and e274a10.

📒 Files selected for processing (2)
  • docs/pm/cli/install.mdx (4 hunks)
  • docs/runtime/bunfig.mdx (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Follow existing patterns in similar V8 classes, add comprehensive Node.js parity tests, update all symbol files, and document any special behavior
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-08T03:11:45.286Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/building-bun.mdc:0-0
Timestamp: 2025-10-08T03:11:45.286Z
Learning: Build the debug version using `bun bd` or `bun run build:debug`; the build outputs to `./build/debug/bun-debug` and takes ~2.5 minutes

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-26T01:32:04.844Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24082
File: test/cli/test/coverage.test.ts:60-112
Timestamp: 2025-10-26T01:32:04.844Z
Learning: In the Bun repository test files (test/cli/test/*.test.ts), when spawning Bun CLI commands with Bun.spawnSync for testing, prefer using stdio: ["inherit", "inherit", "inherit"] to inherit stdio streams rather than piping them.

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-04T09:52:49.414Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-10-04T09:52:49.414Z
Learning: Applies to src/js/bun/**/*.{ts,js} : Place Bun-specific modules (e.g., bun:ffi, bun:sqlite) under bun/

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-04T09:52:49.414Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-10-04T09:52:49.414Z
Learning: Run bun bd after changes

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-10-08T03:11:45.286Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/building-bun.mdc:0-0
Timestamp: 2025-10-08T03:11:45.286Z
Learning: Run any command with the debug build via `bun bd <command>`

Applied to files:

  • docs/pm/cli/install.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/js/bun/**/*.{js,ts} : Place Bun API tests under test/js/bun/, separated by category (e.g., test/js/bun/glob/)

Applied to files:

  • docs/pm/cli/install.mdx
🔇 Additional comments (4)
docs/runtime/bunfig.mdx (1)

498-507: Clear and consistent linker configuration documentation.

The description of install.linker defaults is well-articulated, covering all three scenarios (new workspaces, new single-package projects, and existing pre-v1.3.2 projects) with appropriate reference to the detailed configVersion system in the linked documentation. The standardized wording and cross-file consistency reinforce the PR's intent.

docs/pm/cli/install.mdx (3)

91-96: Well-documented postinstall optimization flags.

The new documentation clearly explains Bun's automatic postinstall script optimizations for popular packages and provides the two feature-flag environment variables to disable them. The placement within the Lifecycle scripts section is appropriate, and the formatting is consistent with the rest of the document.


259-267: Excellent "Default strategy" subsection with clear three-case breakdown.

The new subsection provides a concise and accurate explanation of linker strategy defaults across new workspaces, new single-package projects, and existing projects. The consistent use of "made pre-v1.3.2" terminology, the explicit reference to configVersion, and the link to detailed documentation at /pm/isolated-installs make this accessible and well-grounded. The messaging aligns precisely with the equivalent description in docs/runtime/bunfig.mdx.


337-339: Configuration comment clearly explains configVersion behavior.

The TOML code comment concisely documents how configVersion and workspace usage combine to determine the default linker strategy. The mapping (configVersion=1 → isolated if workspaces, else hoisted; configVersion=0 → hoisted) aligns with the "Default strategy" section above and aids users who review the configuration example.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fd107468934356666c7b02651e9288bf2eac7adf and c89926f9880078c11819ee9bc66505dc7949db99.

📒 Files selected for processing (2)
  • docs/pm/isolated-installs.mdx (1 hunks)
  • docs/test/lifecycle.mdx (1 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-09-08T00:41:12.052Z
Learning: Follow existing patterns in similar V8 classes, add comprehensive Node.js parity tests, update all symbol files, and document any special behavior
📚 Learning: 2025-10-19T04:55:33.099Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: test/js/bun/http/node-telemetry.test.ts:27-203
Timestamp: 2025-10-19T04:55:33.099Z
Learning: In test/js/bun/http/node-telemetry.test.ts and the Bun.telemetry._node_binding API, after the architecture refactor, the _node_binding interface only contains two methods: handleIncomingRequest(req, res) and handleWriteHead(res, statusCode). The handleRequestFinish hook and other lifecycle hooks were removed during simplification. Both current methods are fully tested.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-09-20T03:39:41.770Z
Learnt from: pfgithub
Repo: oven-sh/bun PR: 22534
File: test/regression/issue/21830.fixture.ts:14-63
Timestamp: 2025-09-20T03:39:41.770Z
Learning: Bun's test runner supports async describe callbacks, unlike Jest/Vitest where describe callbacks must be synchronous. The syntax `describe("name", async () => { ... })` is valid in Bun.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-10-30T03:48:10.513Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 24063
File: packages/bun-otel/test/context-propagation.test.ts:1-7
Timestamp: 2025-10-30T03:48:10.513Z
Learning: In Bun test files, `using` declarations at the describe block level execute during module load/parsing, not during test execution. This means they acquire and dispose resources before any tests run. For test-scoped resource management, use beforeAll/afterAll hooks instead. The pattern `beforeAll(beforeUsingEchoServer); afterAll(afterUsingEchoServer);` is correct for managing ref-counted test resources like the EchoServer in packages/bun-otel/test/ - the using block pattern should not be used at describe-block level for test resources.
<!-- [/add_learning]

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-09-20T05:38:31.896Z
Learnt from: pfgithub
Repo: oven-sh/bun PR: 22534
File: src/bun.js/test/Order.zig:70-78
Timestamp: 2025-09-20T05:38:31.896Z
Learning: In Bun's test Order.zig, the skip logic for beforeAll and afterAll hooks works by calling setFailureSkipTo at specific times: beforeAll failures skip to the first afterAll (setFailureSkipTo called before afterAll generation), and afterAll failures skip to the end (setFailureSkipTo called after afterAll generation). The timing of these calls relative to group generation determines the correct skip targets.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-10-08T13:48:02.430Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 23373
File: test/js/bun/tarball/extract.test.ts:107-111
Timestamp: 2025-10-08T13:48:02.430Z
Learning: In Bun's test runner, use `expect(async () => { await ... }).toThrow()` to assert async rejections. Unlike Jest/Vitest, Bun does not require `await expect(...).rejects.toThrow()` - the async function wrapper with `.toThrow()` is the correct pattern for async error assertions in Bun tests.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-11-08T04:06:33.198Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24491
File: test/js/bun/transpiler/declare-global.test.ts:17-17
Timestamp: 2025-11-08T04:06:33.198Z
Learning: In Bun test files, `await using` with Bun.spawn() is the preferred pattern for spawned processes regardless of whether they are short-lived or long-running. Do not suggest replacing `await using proc = Bun.spawn(...)` with `const proc = Bun.spawn(...); await proc.exited;`.

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Prefer data-driven tests (e.g., test.each) to reduce boilerplate

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Applied to files:

  • docs/test/lifecycle.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Use shared utilities from test/harness.ts where applicable

Applied to files:

  • docs/test/lifecycle.mdx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format
🔇 Additional comments (4)
docs/test/lifecycle.mdx (1)

38-76: Overall structure and examples are clear and correct.

The new onTestFinished section is well-organized with clear explanation, practical examples, and helpful limitations. The first example effectively demonstrates execution order relative to afterEach, and the second example shows real-world async cleanup use case in a serial test context. The important notes section properly conveys scope and constraints.

docs/pm/isolated-installs.mdx (3)

1-9: Clear and accurate positioning of the feature.

The introduction clearly explains what isolated installs are and establishes the critical context about default behavior—isolated as default for new workspace projects, with backward compatibility for existing projects. The scope and backward compatibility guarantee are well-communicated upfront.


70-147: Technical sections are accurate and well-organized.

The directory structure, resolution algorithm, and comparison table clearly explain how isolated installs differ from hoisted. The advanced features section appropriately covers peer dependencies, backend strategies, and debugging without overcomplicating the documentation.


148-220: Troubleshooting and migration guidance is practical and complete.

The troubleshooting section correctly identifies real compatibility pain points and offers reasonable solutions. Migration guides are clear with concrete steps. The "when to use" section helps users choose the appropriate strategy for their use case.

Note on documentation links (lines 218-220): The related documentation links use appropriate markdown syntax. However, cross-link validity should be verified separately as part of documentation build/deployment testing (e.g., to confirm /pm/workspaces, /pm/lockfile, and /pm/cli/install pages exist in the final documentation).

Comment thread docs/pm/isolated-installs.mdx Outdated
Comment thread docs/test/lifecycle.mdx Outdated
Comment thread docs/test/lifecycle.mdx Outdated
Add documentation for major features introduced in Bun v1.3.2:

## Package Manager
- Document configVersion system and default linker behavior
- Clarify "made pre-v1.3.2" for existing project backward compatibility
- Add smart postinstall script optimization notes
- Document `bun list` alias for `bun pm ls`
- Note GitHub dependency HTTP tarball optimization

## Testing
- Add `onTestFinished` lifecycle hook to table
- Add simple usage example in Per-Scope section

## Performance
- Add CPU profiling section with `--cpu-prof` flags
- Place after memory usage section for better flow

## Documentation Improvements
- Use "/docs/pm/isolated-installs" for all internal references
- Simplify config comments to reference detailed docs
- Remove unnecessary changes (child-process, websockets, installation)
- Make all sections concise and factual

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
autofix-ci Bot and others added 2 commits November 8, 2025 09:14
Add ws.subscriptions to existing pub/sub code example and TypeScript
reference instead of creating a separate section.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
docs/test/lifecycle.mdx (2)

3-3: Update frontmatter description to include onTestFinished.

The description still references only the original four hooks despite the new onTestFinished hook being documented in the page content. This was flagged in a prior review but appears to have been reverted or not carried forward in the current state.

- description: "Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests"
+ description: "Learn how to use beforeAll, beforeEach, afterEach, afterAll, and onTestFinished lifecycle hooks in Bun tests"

94-109: Add done-style callback example for onTestFinished.

The section notes that onTestFinished supports "async and done-style callbacks" (implied by comparison to other hooks), but only the async pattern is shown. A prior review flagged this gap. Add a concise done-style example to fully document both supported patterns.

Consider adding this after the async example:

 test("cleanup after test", () => {
   onTestFinished(() => {
     // runs after all afterEach hooks
     console.log("test finished");
   });
 });

+Done-style example:
+
+```ts title="test.ts" icon="/icons/typescript.svg"
+test("done-style callback", () => {

  • onTestFinished((done) => {
  • setTimeout(() => {
  •  // Perform final cleanup
    
  •  done();
    
  • }, 10);
  • });
    +});
    +```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: Path: .coderabbit.yaml

**Review profile**: ASSERTIVE

**Plan**: Pro

**Disabled knowledge base sources:**

- Linear integration is disabled by default for public repositories

> You can enable these sources in your CodeRabbit configuration.

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between c89926f9880078c11819ee9bc66505dc7949db99 and 3e8f2ccbc54455b5d747ae0a9a8849f04765db54.

</details>

<details>
<summary>📒 Files selected for processing (8)</summary>

* `docs/guides/install/add-git.mdx` (1 hunks)
* `docs/pm/cli/install.mdx` (4 hunks)
* `docs/pm/cli/pm.mdx` (2 hunks)
* `docs/pm/isolated-installs.mdx` (1 hunks)
* `docs/project/benchmarking.mdx` (1 hunks)
* `docs/runtime/bunfig.mdx` (1 hunks)
* `docs/runtime/http/websockets.mdx` (2 hunks)
* `docs/test/lifecycle.mdx` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (20)</summary>

<details>
<summary>📚 Learning: 2025-09-12T22:30:48.490Z</summary>

Learnt from: RiskyMH
Repo: oven-sh/bun PR: 22613
File: src/cli/package_manager_command.zig:0-0
Timestamp: 2025-09-12T22:30:48.490Z
Learning: Commands like bun info and bun whoami that are promoted from pm-only subcommands to top-level commands use manual bun.argv parsing to detect direct invocation vs. pm invocation. This is different from regular commands that should use ctx.positionals.


**Applied to files:**
- `docs/pm/cli/pm.mdx`

</details>
<details>
<summary>📚 Learning: 2025-09-12T22:30:48.490Z</summary>

Learnt from: RiskyMH
Repo: oven-sh/bun PR: 22613
File: src/cli/package_manager_command.zig:0-0
Timestamp: 2025-09-12T22:30:48.490Z
Learning: Promoted pm subcommands like bun info and bun whoami use manual bun.argv parsing because they are "standalone commands" that bypass the normal command flow. They parse arguments manually starting from argv[2], skip flags, then delegate to the corresponding pm functionality (e.g., bun info calls PmViewCommand.view()). This pattern is different from regular commands that use ctx.positionals.


**Applied to files:**
- `docs/pm/cli/pm.mdx`

</details>
<details>
<summary>📚 Learning: 2025-10-19T04:55:33.099Z</summary>

Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: test/js/bun/http/node-telemetry.test.ts:27-203
Timestamp: 2025-10-19T04:55:33.099Z
Learning: In test/js/bun/http/node-telemetry.test.ts and the Bun.telemetry._node_binding API, after the architecture refactor, the _node_binding interface only contains two methods: handleIncomingRequest(req, res) and handleWriteHead(res, statusCode). The handleRequestFinish hook and other lifecycle hooks were removed during simplification. Both current methods are fully tested.


**Applied to files:**
- `docs/test/lifecycle.mdx`

</details>
<details>
<summary>📚 Learning: 2025-09-20T03:39:41.770Z</summary>

Learnt from: pfgithub
Repo: oven-sh/bun PR: 22534
File: test/regression/issue/21830.fixture.ts:14-63
Timestamp: 2025-09-20T03:39:41.770Z
Learning: Bun's test runner supports async describe callbacks, unlike Jest/Vitest where describe callbacks must be synchronous. The syntax describe("name", async () => { ... }) is valid in Bun.


**Applied to files:**
- `docs/test/lifecycle.mdx`

</details>
<details>
<summary>📚 Learning: 2025-10-30T03:48:10.513Z</summary>

Learnt from: theshadow27
Repo: oven-sh/bun PR: 24063
File: packages/bun-otel/test/context-propagation.test.ts:1-7
Timestamp: 2025-10-30T03:48:10.513Z
Learning: In Bun test files, using declarations at the describe block level execute during module load/parsing, not during test execution. This means they acquire and dispose resources before any tests run. For test-scoped resource management, use beforeAll/afterAll hooks instead. The pattern beforeAll(beforeUsingEchoServer); afterAll(afterUsingEchoServer); is correct for managing ref-counted test resources like the EchoServer in packages/bun-otel/test/ - the using block pattern should not be used at describe-block level for test resources.

Comment thread docs/project/benchmarking.mdx Outdated
Comment on lines +220 to +241
## CPU profiling

Profile JavaScript execution to identify performance bottlenecks with the `--cpu-prof` flag.

```sh terminal icon="terminal"
bun --cpu-prof script.js
```

This generates a `.cpuprofile` file you can open in Chrome DevTools (Performance tab → Load profile) or VS Code's CPU profiler.

### Options

```sh terminal icon="terminal"
bun --cpu-prof --cpu-prof-name my-profile.cpuprofile script.js
bun --cpu-prof --cpu-prof-dir ./profiles script.js
```

| Flag | Description |
| ---------------------------- | -------------------- |
| `--cpu-prof` | Enable profiling |
| `--cpu-prof-name <filename>` | Set output filename |
| `--cpu-prof-dir <dir>` | Set output directory |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify CPU profiling flags and output format for Bun v1.3.2.

The new CPU profiling section is well-structured and clearly documented. However, please verify that the flag names and output format are accurate for Bun v1.3.2.


🏁 Script executed:

#!/bin/bash
# Description: Verify CPU profiling flags exist in Bun
# Check the Bun CLI help for the --cpu-prof flag and related options

bun --help | grep -A 10 "cpu-prof"

Length of output: 41


🌐 Web query:

Bun v1.3.2 CPU profiling --cpu-prof flag documentation

💡 Result:

Yes — Bun (v1.3.x) supports V8 CPU profiling via the --cpu-prof flag. Usage and behavior (same basic semantics as Node’s flags):

  • Enable CPU sampling: bun --cpu-prof run ./your-app.js. (Starts V8 CPU profiler and writes a .cpuprofile on exit.) (toolstac.com)
  • Output file: Bun writes a .cpuprofile file to the working directory by default; you can control directory/name with the same flags Node exposes (e.g., --cpu-prof-dir and --cpu-prof-name). (nodejs.org)
  • Sampling interval: the profiler sampling interval can be adjusted with --cpu-prof-interval (interval in microseconds; Node default is 1000 µs). (nodejs.org)
  • Related Bun profiling flags: --heap-prof for heap snapshots and --print-stats for runtime stats. (toolstac.com)

If you want exact CLI help on your installed Bun v1.3.2, run: bun --help or bun --version and bun --help | grep prof to see available profiling flags on that binary. (bun.com)

Citations:


🌐 Web query:

Bun official documentation CPU profiling command syntax

💡 Result:

Short answer — Bun supports CPU profiling via the WebKit inspector (use bun's --inspect flags and the DevTools Profiles panel), programmatic console.profile()/console.profileEnd(), and the JavaScriptCore sampling profiler API.

Examples and syntax:

  • Start Bun with the inspector (open DevTools → Profiles): bun --inspect <script> (also --inspect-brk, --inspect-wait, or specify port/url). [2]
  • Programmatic CPU profile (shows in the inspector Profiles panel):
    • console.profile('label'); ... console.profileEnd('label');. [1]
  • Start JSC sampling profiler programmatically (writes profiler data): Bun.bun:jsc.startSamplingProfiler(optionalDirectory?). [3]

Sources:

  • Console.profile / profileEnd docs. [1]
  • Debugger / --inspect docs (bun --inspect / --inspect-brk / --inspect-wait). [2]
  • bun:jsc.startSamplingProfiler API. [3]

🌐 Web query:

site:bun.sh CPU profiling documentation

💡 Result:

Bun's CPU-profiling docs on bun.sh:

  • console.profile / console.profileEnd — start/stop a JavaScript CPU profile (appears in the inspector Profiles panel). [1][2]
  • bun:jsc.startSamplingProfiler — run JavaScriptCore's sampling profiler (can write profiler output to a directory). [3]
  • General API reference (search these entries in the Bun reference). [4]

References:
[1] https://bun.sh/reference/globals/Console/profile
[2] https://bun.sh/reference/globals/Console/profileEnd
[3] https://bun.sh/reference/bun/jsc/startSamplingProfiler
[4] https://bun.sh/reference


🌐 Web query:

Bun --cpu-prof flag Node.js compatibility CLI profiling

💡 Result:

Short answer

  • Yes — Bun supports a --cpu-prof CLI flag that produces .cpuprofile CPU profile files you can open with tools like speedscope / Chrome DevTools. [1][2]
  • The produced .cpuprofile follows the common V8-style/Chrome-compatible profile format used by Node tooling, so existing tooling that reads .cpuprofile (speedscope, DevTools) works. [3][4]

Notes / practical tips

  • Run: bun --cpu-prof run your-app.js (or bun --cpu-prof --cpu-prof-dir=/path ...). [1][2]
  • Open the generated CPU.*.cpuprofile file in speedscope or Chrome DevTools. [3]
  • Behavior differences: Bun uses JavaScriptCore (not V8), so function names/frames or sampling details may differ from Node/V8 profiles even though the file format is consumable; expect small semantic differences in flamegraphs. (Bun docs show the flags; speedscope/DevTools document .cpuprofile support.) [1][3][4]

Sources

  1. Bun docs / troubleshooting and CLI examples (shows bun --cpu-prof usage). [1]
  2. Bun API / benchmarking pages describing profiling flags. [2]
  3. speedscope (reads .cpuprofile files produced by Node/V8). [3]
  4. Node CLI docs for --cpu-prof / .cpuprofile behavior (format/filenames and options). [4]

🌐 Web query:

Bun "bun --cpu-prof run" exact syntax documentation

💡 Result:

Short answer — Bun accepts the same CPU-profiling style flags at process-start and you run it like:

bun [bun‑flags] --cpu-prof [--cpu-prof-dir

] [--cpu-prof-name ] [--cpu-prof-interval ] run <file|script> [script-args]

Examples:

  • bun --cpu-prof run index.js
  • bun --cpu-prof --cpu-prof-dir=/tmp/profiles run server.js

Notes/sources:

  • bun run CLI docs (how to place Bun flags immediately after bun). [1]
  • Community / troubleshooting examples showing bun --cpu-prof usage. [2]
  • Node.js CLI docs for exact semantics and additional cpu-prof flags (filename, dir, interval) — Bun follows the same flag names/semantics. [3]

Sources:
[1] https://bun.sh/docs/cli/run
[2] https://toolstac.com/tool/bun/troubleshooting-resources
[3] https://nodejs.org/docs/latest-v18.x/api/cli.html#--cpu-prof

If you want, I can fetch the exact file-name pattern Bun produces (and confirm which of the optional cpu-prof-* flags Bun implements) for your current Bun version — tell me your bun --version and I'll look it up.


Fix CPU profiling command syntax—add missing run keyword.

The CPU profiling section has correct flag names and output format, but the command examples are missing the required run keyword. The commands should be:

bun --cpu-prof run script.js
bun --cpu-prof --cpu-prof-name my-profile.cpuprofile run script.js
bun --cpu-prof --cpu-prof-dir ./profiles run script.js

Additionally, consider documenting the --cpu-prof-interval flag (adjusts sampling interval in microseconds) for completeness, though the three main flags cover basic usage.

🤖 Prompt for AI Agents
In docs/project/benchmarking.mdx around lines 220 to 241, the CPU profiling
command examples are missing the required run keyword; update each example to
include run before the script (e.g., bun --cpu-prof run script.js and bun
--cpu-prof --cpu-prof-name my-profile.cpuprofile run script.js, bun --cpu-prof
--cpu-prof-dir ./profiles run script.js) and optionally add a brief line
documenting the --cpu-prof-interval flag (sampling interval in microseconds)
under the Options section.

Convert line endings from CRLF to LF to match repository standards and prevent unnecessary diffs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread docs/pm/cli/install.mdx Outdated
Comment thread docs/runtime/bunfig.mdx Outdated
Comment thread docs/pm/cli/install.mdx Outdated
@lydiahallie lydiahallie merged commit b876938 into main Nov 11, 2025
9 checks passed
@lydiahallie lydiahallie deleted the claude/docs-bun-v1.3.2-updates branch November 11, 2025 02:18
@coderabbitai coderabbitai Bot mentioned this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants