Bun Package Manager by secondsky/claude-skills
npx skills add https://github.com/secondsky/claude-skills --skill 'Bun Package Manager'Bun 的包管理器是一个显著更快的替代品,用于取代 npm、yarn 和 pnpm。比 npm install 快达 25 倍。
# 安装所有依赖项
bun install
# 添加包
bun add react react-dom
bun add -D typescript @types/react
# 移除包
bun remove lodash
# 更新包
bun update
# 运行包二进制文件
bunx create-next-app
| 命令 | 描述 |
|---|---|
bun install | 安装所有依赖项 |
bun add <pkg> | 添加依赖项 |
bun add -D <pkg> |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 添加开发依赖项 |
bun add -O <pkg> | 添加可选依赖项 |
bun add --peer <pkg> | 添加对等依赖项 |
bun remove <pkg> | 移除依赖项 |
bun update [pkg] | 更新依赖项 |
bunx <pkg> | 运行包二进制文件 |
bun pm cache rm | 清除缓存 |
# 生产模式(不安装 devDependencies)
bun install --production
# 锁定 lockfile(CI/CD)
bun install --frozen-lockfile
bun ci # 简写形式
# 模拟运行
bun install --dry-run
# 详细/静默模式
bun install --verbose
bun install --silent
# 强制重新安装
bun install --force
# 全局包
bun install -g cowsay
Bun 使用 bun.lock(自 v1.2 起为基于文本的格式):
# 生成文本 lockfile
bun install --save-text-lockfile
# 从二进制 bun.lockb 升级
bun install --save-text-lockfile --frozen-lockfile --lockfile-only
rm bun.lockb
{
"name": "my-monorepo",
"workspaces": ["packages/*", "apps/*"]
}
跨工作区运行命令:
# 在匹配的包中运行
bun run --filter 'pkg-*' build
# 在所有工作区中运行
bun run --filter '*' test
# 为特定包安装依赖
bun install --filter 'pkg-a'
Bun 默认不运行来自依赖项的生命周期脚本(出于安全考虑)。将受信任的包加入白名单:
{
"trustedDependencies": ["my-trusted-package"]
}
# 跳过所有生命周期脚本
bun install --ignore-scripts
# 并发执行脚本
bun install --concurrent-scripts 5
强制指定嵌套依赖项的特定版本:
{
"overrides": {
"lodash": "4.17.21"
}
}
也支持 Yarn 风格的决议:
{
"resolutions": {
"lodash": "4.17.21"
}
}
{
"dependencies": {
"dayjs": "git+https://github.com/iamkun/dayjs.git",
"lodash": "git+ssh://github.com/lodash/lodash.git#4.17.21",
"zod": "github:colinhacks/zod",
"react": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
"bun-types": "npm:@types/bun"
}
}
传统的扁平化 node_modules:
bun install --linker hoisted
类似 pnpm 的严格隔离:
bun install --linker isolated
隔离安装防止“幽灵依赖”——包只能访问已声明的依赖项。
# GitHub Actions
- uses: oven-sh/setup-bun@v2
- run: bun ci # 使用冻结的 lockfile
# 为不同平台安装
bun install --cpu=x64 --os=linux
| 错误 | 原因 | 解决方法 |
|---|---|---|
Cannot find module | 缺少依赖项 | 运行 bun install |
Lockfile mismatch | package.json 已更改 | 运行 bun install |
Peer dependency | 缺少对等依赖项 | 使用 bun add 添加对等依赖项 |
Lifecycle script failed | 不受信任的包 | 添加到 trustedDependencies |
Bun 自动迁移 pnpm-lock.yaml:
bun install # 自动转换为 bun.lock
工作区配置移至 package.json:
{
"workspaces": {
"packages": ["apps/*", "packages/*"],
"catalog": {
"react": "^18.0.0"
}
}
}
只需运行 bun install - Bun 会读取 package-lock.json 和 yarn.lock。
加载 references/cli-commands.md 当:
加载 references/workspaces.md 当:
加载 references/migration.md 当:
每周安装次数
–
代码仓库
GitHub 星标数
93
首次出现
–
安全审计
Bun's package manager is a dramatically faster replacement for npm, yarn, and pnpm. Up to 25x faster than npm install.
# Install all dependencies
bun install
# Add packages
bun add react react-dom
bun add -D typescript @types/react
# Remove packages
bun remove lodash
# Update packages
bun update
# Run package binaries
bunx create-next-app
| Command | Description |
|---|---|
bun install | Install all dependencies |
bun add <pkg> | Add dependency |
bun add -D <pkg> | Add dev dependency |
bun add -O <pkg> | Add optional dependency |
bun add --peer <pkg> | Add peer dependency |
bun remove <pkg> | Remove dependency |
bun update [pkg] | Update dependencies |
bunx <pkg> | Run package binary |
bun pm cache rm | Clear cache |
# Production mode (no devDependencies)
bun install --production
# Frozen lockfile (CI/CD)
bun install --frozen-lockfile
bun ci # shorthand
# Dry run
bun install --dry-run
# Verbose/Silent
bun install --verbose
bun install --silent
# Force reinstall
bun install --force
# Global packages
bun install -g cowsay
Bun uses bun.lock (text-based since v1.2):
# Generate text lockfile
bun install --save-text-lockfile
# Upgrade from binary bun.lockb
bun install --save-text-lockfile --frozen-lockfile --lockfile-only
rm bun.lockb
{
"name": "my-monorepo",
"workspaces": ["packages/*", "apps/*"]
}
Run commands across workspaces:
# Run in matching packages
bun run --filter 'pkg-*' build
# Run in all workspaces
bun run --filter '*' test
# Install for specific packages
bun install --filter 'pkg-a'
Bun does not run lifecycle scripts from dependencies by default (security). Whitelist trusted packages:
{
"trustedDependencies": ["my-trusted-package"]
}
# Skip all lifecycle scripts
bun install --ignore-scripts
# Concurrent scripts
bun install --concurrent-scripts 5
Force specific versions for nested dependencies:
{
"overrides": {
"lodash": "4.17.21"
}
}
Yarn-style resolutions also supported:
{
"resolutions": {
"lodash": "4.17.21"
}
}
{
"dependencies": {
"dayjs": "git+https://github.com/iamkun/dayjs.git",
"lodash": "git+ssh://github.com/lodash/lodash.git#4.17.21",
"zod": "github:colinhacks/zod",
"react": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
"bun-types": "npm:@types/bun"
}
}
Traditional flat node_modules:
bun install --linker hoisted
pnpm-like strict isolation:
bun install --linker isolated
Isolated prevents "phantom dependencies" - packages can only access declared dependencies.
# GitHub Actions
- uses: oven-sh/setup-bun@v2
- run: bun ci # frozen lockfile
# Install for different platform
bun install --cpu=x64 --os=linux
| Error | Cause | Fix |
|---|---|---|
Cannot find module | Missing dependency | Run bun install |
Lockfile mismatch | package.json changed | Run bun install |
Peer dependency | Missing peer | bun add the peer |
Lifecycle script failed |
Bun automatically migrates pnpm-lock.yaml:
bun install # Auto-converts to bun.lock
Workspace config moves to package.json:
{
"workspaces": {
"packages": ["apps/*", "packages/*"],
"catalog": {
"react": "^18.0.0"
}
}
}
Simply run bun install - Bun reads package-lock.json and yarn.lock.
Load references/cli-commands.md when:
Load references/workspaces.md when:
Load references/migration.md when:
Weekly Installs
–
Repository
GitHub Stars
93
First Seen
–
Security Audits
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
107,800 周安装
Google Apps Script 自动化脚本教程 - 免费实现 Google Sheets 与 Workspace 自动化
604 周安装
LangChain AI社交内容创作技能:自动化生成LinkedIn/Twitter图文帖
617 周安装
CLI-Anything:基于Codex的通用命令行工具构建框架,自动化生成CLI套件
613 周安装
stop-slop:AI写作优化工具 - 消除陈词滥调,提升文本真实性与可读性
631 周安装
智能外联草拟工具:基于调研的个性化邮件与LinkedIn消息生成器 | 销售与营销自动化
635 周安装
Top-Design 世界级数字设计技能:掌握Awwwards获奖设计标准与评分体系
658 周安装
| Untrusted package |
Add to trustedDependencies |