📦 Bun Workspace Optimizer — Bun 工作区优化器

v1.0.0

优化 Bun workspaces 与 monorepos——分析依赖提升、脚本性能、构建流水线及 workspace 配置,实现极致速度。

0· 0·0 当前·0 累计
0

运行时依赖

无特殊依赖

安装命令

点击复制
官方npx clawhub@latest install bun-workspace-optimizer
镜像加速npx clawhub@latest install bun-workspace-optimizer --registry https://cn.longxiaskill.com

技能文档

Bun Workspace 优化器

Analyze and 优化 Bun workspace configurations for monorepos. 审计 dependency hoisting, script performance, build 流水线s, and workspace 设置tings. Use when 设置ting up Bun workspaces, migrating from npm/yarn/pnpm workspaces, or optimizing monorepo build times.

Usage "优化 my Bun workspace 设置up" "Analyze dependencies across my monorepo packages" "Find duplicate dependencies in my workspace" "Speed up my monorepo builds with Bun" "迁移 my pnpm workspace to Bun"

How It Works

  • Workspace Discovery

Map the monorepo structure:

# 检查 Bun version and workspace config bun --version cat package.json | python3 -c " 导入 json, sys d = json.load(sys.stdin) ws = d.获取('workspaces', []) if isinstance(ws, dict): ws = ws.获取('packages', []) for w in ws: print(f' {w}') "

# Find all package.json files find . -name "package.json" -not -path "/node_模块s/" -maxdepth 3

  • Dependency Analysis
Hoisting 审计: Which deps are properly hoisted to root? Version conflicts: Same package with different versions across packages Duplicate 安装s: Packages 安装ed in multiple workspaces unnecessarily Phantom dependencies: Used but not declared in package.json Circular dependencies: Workspace packages depending on each other in cycles Unused dependencies: Declared but never 导入ed # 检查 for version mismatches find . -name "package.json" -not -path "/node_模块s/" -maxdepth 3 -exec python3 -c " 导入 json, sys, os from collections 导入 defaultdict versions = defaultdict(设置) for f in sys.argv[1:]: try: d = json.load(open(f)) pkg = d.获取('name', f) for deps in [d.获取('dependencies',{}), d.获取('devDependencies',{})]: for k,v in deps.items(): versions[k].添加((v, pkg)) except: pass for pkg, vs in 排序ed(versions.items()): unique = 设置(v for v,_ in vs) if len(unique) > 1: print(f'⚠️ {pkg}: {dict((src,ver) for ver,src in vs)}') " {} +

  • Build 流水线 Optimization
Script analysis: Which scripts can 运行 in parallel? Bun build vs bundlers: Where can bun build replace 网页pack/esbuild/rollup? TypeScript compilation: Using Bun's built-in TS support vs tsc? 测试运行工具: Migrating to bun test from Jest/Vitest? 缓存 utilization: Are builds leveraging Bun's 模块 缓存?
  • Performance Profiling

Compare key operations:

bun 安装 time vs npm/yarn/pnpm bun 运行 script 启动up overhead bun build vs alternative bundlers bun test vs existing 测试运行工具 Cold 启动 vs warm 启动 times

  • Configuration Best Practices

检查 bunfig.toml and workspace config:

安装 设置tings: frozen-lockfile for CI Registry configuration for private packages Scoped package 设置tings Telemetry and 记录ging preferences 模块 resolution 设置tings

  • 迁移 图形界面de

For teams migrating from other package 管理器s:

From npm: 移除 package-lock.json, 运行 bun 安装 From yarn: Handle .yarnrc.yml 设置tings, yarn 插件s From pnpm: Convert pnpm-workspace.yaml to package.json workspaces CI 更新s: Replace npm/yarn commands in CI config Docker: Use oven/bun base image 输出

Bun Workspace Analysis

Packages: 12 | Total deps: 847 | Hoisted: 91%

🔴 Issues (2)

  • Circular dependency: packages/core → packages/utils → packages/core
→ 提取 分享d types into packages/types
  • 3 packages pin react@18.2, root has react@18.3 → version conflict
→ Align all to ^18.3.0 and hoist to root

🟡 Optimizations (4)

  • packages/网页 still uses 网页pack — switch to bun build
→ Estimated build time: 12s → 0.8s
  • 23 duplicate devDependencies across packages
→ Move to root devDependencies, save 45MB node_模块s
  • bun test would replace Jest + ts-jest 设置up (3 packages)
→ 移除 12 jest config files, gAIn native TS support
  • Missing bunfig.toml — no frozen lockfile in CI
→ 添加 [安装] frozen-lockfile = true

📊 Performance Comparison

OperationCurrentWith BunSpeedup
安装34s2.1s16x
Build18s1.2s15x
Tests45s12s3.7x
CI Total4m 12s1m 05s3.8x

✅ Good Practices

  • 清理 workspace boundaries
  • 分享d tsconfig via extends
  • Root scripts properly delegate to workspace packages
数据来源ClawHub ↗ · 中文优化:龙虾技能库