Bun 1.3.5 Adds Native PTY Support and Compile‑Time Dead‑Code Elimination
Version 1.3.5 of the Bun runtime introduces native PTY support, compile‑time feature flags that enable dead‑code elimination, and accurate Unicode string width handling, along with several other improvements such as V8 type‑check APIs, S3 upload options, and numerous bug fixes.
Bun 1.3.5 was released with a set of low‑level enhancements that are especially relevant for developers building CLI tools or aiming for minimal bundle sizes.
1. Native PTY Support: Can Bun Run Vim?
The release adds a built‑in Bun.Terminal API that creates and manages pseudo‑terminals (PTY). Previously, interactive tools like vim or htop required complex third‑party libraries or hacks because they depend on a TTY environment for colors, cursor movement, and user input.
With the new terminal option, a child process can be mounted to a PTY directly:
const commands = ["echo Hello from PTY!", "exit"];
const proc = Bun.spawn(["bash"], {
terminal: {
cols: 80,
rows: 24,
data(terminal, data) {
process.stdout.write(data);
if (data.includes("$")) {
terminal.write(commands.shift() + "
");
}
},
},
});
await proc.exited;
proc.terminal.close();When a PTY is attached, process.stdout.isTTY becomes true, enabling:
Color output to render correctly.
Interactive prompts to work as expected.
Embedding a vim editor inside custom tools.
Note: PTY support currently works on Linux and macOS; Windows is not yet supported.
2. Compile‑time Feature Flags: Cutting Unused Code at Build Time
Bun now standardizes compile‑time feature flags. By importing feature from bun:bundle, developers can write branches that are resolved during bundling.
import { feature } from "bun:bundle";
if (feature("PREMIUM")) {
// This code is included only when the PREMIUM flag is enabled
initPremiumFeatures();
}
if (feature("DEBUG")) {
// This code is removed entirely when DEBUG is disabled
console.log("Debug mode");
}Running bun build --feature=PREMIUM ./app.ts replaces feature("PREMIUM") with true and feature("DEBUG") with false. Combined with minification, the false branches are eliminated completely, leaving no dead code.
Smaller bundles : Unused code never reaches the final artifact.
Increased safety : Debug or internal test code cannot leak into production.
Greater flexibility : Enables easy A/B testing or separate free/paid builds.
3. Bun.stringWidth: Accurate Emoji Alignment
Unicode width calculation has long been problematic. The new implementation of Bun.stringWidth correctly treats complex emojis (e.g., 🇺🇸, 👋🏽, 👨👩👧) as occupying two character cells, handles zero‑width characters like soft hyphens, and properly ignores ANSI escape sequences.
Better emoji support : Complex emojis are measured as width 2 instead of inconsistent values.
Zero‑width character handling : Invisible characters such as Word Joiner are counted as width 0.
ANSI escape sequence handling : Color codes and hyperlink sequences no longer inflate string length.
This improvement is a boon for developers building CLI tables, progress bars, and other text‑based UI components.
4. Other Notable Improvements
V8 type‑check API : New C++ APIs like v8::Value::IsMap() and IsArray() improve native addon compatibility.
S3 upload support : The contentDisposition option lets the built‑in S3 client control whether a file is downloaded or previewed.
.npmrc variable expansion : Fixed issues where environment variables inside quotes were ignored, aligning behavior with native npm.
Numerous bug fixes : Includes fixes for high CPU usage on macOS, fetch proxy authentication, and WebSocket crashes on Windows.
Reference: Bun v1.3.5 Release Blog
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
