phpdot/bun
Composer 安装命令:
composer require phpdot/bun
包简介
A PHP wrapper around the Bun binary (oven-sh/bun, MIT licensed): manages a hidden Bun runtime and exposes its CLI as console commands.
README 文档
README
A PHP wrapper around the Bun binary. It manages a hidden Bun
binary — downloaded on first use into .phpdot/runtime/, integrity-verified, and pinned to a
reproducible version — and exposes Bun's CLI as console commands and as an injectable service.
This package is a thin wrapper. It does not reimplement a bundler, a package manager, or a runtime; it delegates to the Bun binary.
phpdot/bun is a PHP wrapper around Bun (oven-sh/bun), which is MIT licensed.
Requirements
- PHP 8.4+
ext-curl(registry access and binary download)- A PSR-18 client + PSR-17 factories — bundled by default via
symfony/http-client+nyholm/psr7 ext-pcntl(suggested) — forwardsSIGINT/SIGTERMto long-lived processes (rundev server,build --watch) for clean shutdown- On Alpine/musl, install
libstdc++(apk add libstdc++) — the downloaded Bun binary links against it at runtime. Glibc distros and macOS/Windows already provide it.
Installation
composer require phpdot/bun
Add the runtime directory to your .gitignore — the binary is downloaded per machine, never committed:
/.phpdot/
Configuration
BunConfig is an immutable value object resolved from the container (#[Config('bun')]):
| Setting | Default | Notes |
|---|---|---|
pinnedVersion |
1.3.14 |
Reproducible — never tracks "latest". Override with the BUN_VERSION env var. |
registryUrl |
https://registry.npmjs.org |
Used for search, metadata, and download — point it at a mirror in one place. |
runtimeDir |
.phpdot/runtime |
Where the binary is cached, relative to the project root. |
Console commands
Registered into your phpdot console application (discovered via #[AsCommand]):
# Discovery (uses the npm registry; never needs the binary) bun:search chart --limit=20 # Packages bun:install lodash axios # bun add bun:install --dev typescript # bun add --dev bun:remove lodash # bun remove bun:view react # bun pm view # Run scripts and tools (output streams live; Ctrl-C is forwarded) bun:run dev # bun run dev bun:run dev -- --port 3000 # flags for the script go after -- bun:x prettier src -- --write # bun x — run any installed CLI tool # Bundle bun:build src/index.ts --out-dir=dist --minify --splitting --hashed-names bun:build src/index.ts --watch # long-lived: rebuilds on change, exits cleanly on signal
Passthrough commands (
bun:run,bun:x) forward arguments verbatim. Put flags meant for the script/tool after a--separator so the console does not parse them.
Build-step tools
There is no special-casing for any tool. Install it and run it with bun:x:
bun:install javascript-obfuscator bun:x javascript-obfuscator app.js -- --output app.obf.js
Programmatic use
Inject the Bun service — there is no static entry point or facade:
use PHPdot\Bun\Bun; use PHPdot\Bun\Build\BuildOptions; final class Deploy { public function __construct(private readonly Bun $bun) {} public function bundle(): void { $this->bun->install(['lodash']); $this->bun->build( ['src/index.ts'], new BuildOptions(outDir: 'dist', minify: true, splitting: true, hashedNames: true), ); } }
Each call resolves the binary (downloading it on first use) and streams Bun's output through to the console, returning Bun's exit code.
How it works
PlatformDetectorresolves the host OS, architecture, and (on Linux) libc flavour.BinaryResolverchecks the cached binary; if missing or version-mismatched it acquires a lock and downloads the matching@oven/bun-*npm package, verifies its sha512 integrity, and extracts it.- If the standard x64 binary fails to execute (e.g. no AVX2 / illegal instruction), it falls back to
the
-baselinevariant automatically. - Concurrent first-use downloads are guarded by a file lock.
License
MIT. Bun itself is MIT licensed; redistribution via download preserves that notice.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-17