monorepo-navigator by borghei/claude-skills
npx skills add https://github.com/borghei/claude-skills --skill monorepo-navigator层级: 强大 类别: 工程 / 构建系统 维护者: Claude Skills 团队
在任何规模下导航、管理和优化 monorepo。涵盖 Turborepo、Nx、pnpm workspaces 和 Lerna/Changesets,用于跨包影响分析、仅对受影响包进行选择性构建、依赖关系图可视化、远程缓存配置、从多仓库迁移到 monorepo 并保留 git 历史记录,以及带有自动化变更日志的协调包发布。
monorepo, Turborepo, Nx, pnpm workspaces, Changesets, dependency graph, remote cache, affected packages, selective builds, cross-package impact, npm publishing, workspace protocol
workspace:* 协议广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 需求 | Turborepo | Nx | pnpm Workspaces | Changesets |
|---|---|---|---|---|
| 简单的任务运行器 | 最佳 | 良好 | 不适用 | 不适用 |
| 远程缓存 | 内置 | Nx Cloud | 不适用 | 不适用 |
| 代码生成 | 否 | 最佳 | 不适用 | 不适用 |
| 依赖管理 | 不适用 | 不适用 | 最佳 | 不适用 |
| 包发布 | 不适用 | 不适用 | 不适用 | 最佳 |
| 插件生态系统 | 有限 | 广泛 | 不适用 | 不适用 |
| 配置复杂度 | 最小 | 中等 | 最小 | 最小 |
推荐的现代技术栈: pnpm workspaces + Turborepo + Changesets
my-monorepo/
├── apps/
│ ├── web/ # Next.js 前端
│ │ ├── package.json # 依赖 @repo/ui, @repo/utils
│ │ └── ...
│ ├── api/ # Express/Fastify 后端
│ │ ├── package.json # 依赖 @repo/db, @repo/utils
│ │ └── ...
│ └── mobile/ # React Native 应用
│ ├── package.json
│ └── ...
├── packages/
│ ├── ui/ # 共享的 React 组件
│ │ ├── package.json # @repo/ui
│ │ └── ...
│ ├── utils/ # 共享的工具函数
│ │ ├── package.json # @repo/utils
│ │ └── ...
│ ├── db/ # 数据库客户端 + 模式
│ │ ├── package.json # @repo/db
│ │ └── ...
│ ├── types/ # 共享的 TypeScript 类型
│ │ ├── package.json # @repo/types (无运行时依赖)
│ │ └── ...
│ └── config/ # 共享配置 (tsconfig, eslint)
│ ├── tsconfig.base.json
│ └── eslint.base.js
├── turbo.json # Turborepo 流水线配置
├── pnpm-workspace.yaml # 工作空间包位置
├── package.json # 根脚本, devDependencies
└── .changeset/ # Changeset 配置
└── config.json
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"globalEnv": ["NODE_ENV", "CI"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json", "package.json"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
"env": ["NEXT_PUBLIC_*"]
},
"test": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tests/**", "vitest.config.*"],
"outputs": ["coverage/**"]
},
"lint": {
"dependsOn": ["^build"],
"inputs": ["src/**", ".eslintrc.*", "tsconfig.json"]
},
"typecheck": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
# 运行所有任务
turbo run build
# 仅运行受影响的包(与 main 分支比较)
turbo run build test --filter='...[origin/main]'
# 为特定包及其依赖项运行
turbo run build --filter=@repo/web...
# 仅为特定包运行(无依赖项)
turbo run test --filter=@repo/ui
# 试运行以查看将执行什么
turbo run build --dry=json
# 查看依赖关系图
turbo run build --graph=graph.html
# 总结缓存使用情况
turbo run build --summarize
packages:
- 'apps/*'
- 'packages/*'
// packages/ui/package.json
{
"name": "@repo/ui",
"version": "0.0.0",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@repo/types": "workspace:*"
}
}
// apps/web/package.json
{
"name": "@repo/web",
"dependencies": {
"@repo/ui": "workspace:*",
"@repo/utils": "workspace:*"
}
}
# 安装所有工作空间依赖项
pnpm install
# 向特定包添加依赖项
pnpm add zod --filter @repo/api
# 将工作空间包添加为依赖项
pnpm add @repo/utils --filter @repo/web --workspace
# 在特定包中运行脚本
pnpm --filter @repo/web dev
# 在所有拥有该脚本的包中运行脚本
pnpm -r run build
# 列出所有包
pnpm -r ls --depth -1
# 使用 turbo 查看哪些包依赖 @repo/ui
turbo run build --filter='...@repo/ui' --dry=json | \
jq '.tasks[].package' -r | sort -u
# 手动:搜索包的导入
grep -r "from '@repo/ui'" apps/ packages/ --include="*.ts" --include="*.tsx" -l
# 生成 HTML 可视化
turbo run build --graph=dependency-graph.html
# 生成 DOT 格式用于自定义渲染
turbo run build --graph=deps.dot
# 从 package.json 文件快速生成 Mermaid 图
echo "graph TD"
for pkg in packages/*/package.json apps/*/package.json; do
name=$(jq -r '.name' "$pkg")
jq -r '.dependencies // {} | keys[] | select(startswith("@repo/"))' "$pkg" | while read dep; do
echo " $name --> $dep"
done
done
# 登录到 Vercel(一次性)
turbo login
# 将仓库链接到 Vercel 团队
turbo link
# CI:设置环境变量
# TURBO_TOKEN=<vercel-token>
# TURBO_TEAM=<team-slug>
# 验证远程缓存是否工作
turbo run build --summarize
# 查找 "Remote cache: hit" 条目
# 使用 ducktape/turborepo-remote-cache
docker run -p 3000:3000 \
-e STORAGE_PROVIDER=local \
-e STORAGE_PATH=/cache \
ducktape/turborepo-remote-cache
# 配置 turbo 以使用它
# turbo.json:
# { "remoteCache": { "apiUrl": "http://cache-server:3000" } }
# .github/workflows/ci.yml
name: CI
on:
pull_request:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 为 --filter 比较所需
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
# 仅对受影响的包进行 lint/test/build
- run: turbo run lint test build --filter='...[origin/main]'
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
# 安装 changesets
pnpm add -D -w @changesets/cli @changesets/changelog-github
# 初始化
pnpm changeset init
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }],
"commit": false,
"fixed": [],
"linked": [["@repo/ui", "@repo/utils"]],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch"
}
# 1. 开发人员为其更改添加 changeset
pnpm changeset
# 交互式:选择包、升级类型 (patch/minor/major)、摘要
# 2. 发布前:消费 changesets 并提升版本
pnpm changeset version
# 更新 package.json 版本和 CHANGELOG.md 文件
# 3. 发布到 npm
pnpm changeset publish
# 将 workspace:* 替换为实际版本并发布
# 1. 使用 filter-repo 保留 git 历史记录
# 在每个源仓库中:
git filter-repo --to-subdirectory-filter packages/ui
git filter-repo --to-subdirectory-filter apps/api
# 2. 创建 monorepo 并合并历史记录
mkdir monorepo && cd monorepo && git init
git remote add ui ../old-ui-repo
git fetch ui --no-tags
git merge ui/main --allow-unrelated-histories
git remote add api ../old-api-repo
git fetch api --no-tags
git merge api/main --allow-unrelated-histories
# 3. 设置工作空间配置
# 添加 pnpm-workspace.yaml, turbo.json, 根 package.json
# 4. 更新内部导入
# 将 "ui-package" 导入更改为 "@repo/ui"
# 将 npm 版本更改为 "workspace:*"
# 5. 验证
pnpm install
turbo run build test
| 陷阱 | 修复方法 |
|---|---|
在每个 PR 上运行 turbo run build 而不带 --filter | 在 CI 中始终使用 --filter='...[origin/main]' |
workspace:* 破坏 npm 发布 | 使用 pnpm changeset publish,它会自动替换 |
| 不相关文件更改时所有包都重建 | 调整 turbo.json 中的 inputs 以排除文档、配置文件 |
| 共享的 tsconfig 破坏跨包类型检查 | 每个包都从根扩展,但覆盖 rootDir/outDir |
| 迁移期间丢失 git 历史记录 | 在合并之前使用 git filter-repo --to-subdirectory-filter |
| CI 中的远程缓存未命中 | 验证 TURBO_TOKEN 和 TURBO_TEAM;使用 --summarize 检查 |
| 包之间的导入循环 | 使用 madge --circular 检测;将共享代码重构到新包中 |
packages/types 是纯 TypeScript — 无运行时代码,无依赖项,构建最快每周安装数
1
仓库
GitHub 星标数
29
首次出现
今天
安全审计
已安装于
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
Tier: POWERFUL Category: Engineering / Build Systems Maintainer: Claude Skills Team
Navigate, manage, and optimize monorepos at any scale. Covers Turborepo, Nx, pnpm workspaces, and Lerna/Changesets for cross-package impact analysis, selective builds on affected packages only, dependency graph visualization, remote caching configuration, migration from multi-repo to monorepo with preserved git history, and coordinated package publishing with automated changelogs.
monorepo, Turborepo, Nx, pnpm workspaces, Changesets, dependency graph, remote cache, affected packages, selective builds, cross-package impact, npm publishing, workspace protocol
workspace:* protocol replacement during publish| Requirement | Turborepo | Nx | pnpm Workspaces | Changesets |
|---|---|---|---|---|
| Simple task runner | Best | Good | N/A | N/A |
| Remote caching | Built-in | Nx Cloud | N/A | N/A |
| Code generation | No | Best | N/A | N/A |
| Dependency management | N/A | N/A | Best | N/A |
| Package publishing | N/A | N/A | N/A | Best |
| Plugin ecosystem | Limited | Extensive | N/A |
Recommended modern stack: pnpm workspaces + Turborepo + Changesets
my-monorepo/
├── apps/
│ ├── web/ # Next.js frontend
│ │ ├── package.json # depends on @repo/ui, @repo/utils
│ │ └── ...
│ ├── api/ # Express/Fastify backend
│ │ ├── package.json # depends on @repo/db, @repo/utils
│ │ └── ...
│ └── mobile/ # React Native app
│ ├── package.json
│ └── ...
├── packages/
│ ├── ui/ # Shared React components
│ │ ├── package.json # @repo/ui
│ │ └── ...
│ ├── utils/ # Shared utilities
│ │ ├── package.json # @repo/utils
│ │ └── ...
│ ├── db/ # Database client + schema
│ │ ├── package.json # @repo/db
│ │ └── ...
│ ├── types/ # Shared TypeScript types
│ │ ├── package.json # @repo/types (no runtime deps)
│ │ └── ...
│ └── config/ # Shared configs (tsconfig, eslint)
│ ├── tsconfig.base.json
│ └── eslint.base.js
├── turbo.json # Turborepo pipeline config
├── pnpm-workspace.yaml # Workspace package locations
├── package.json # Root scripts, devDependencies
└── .changeset/ # Changeset config
└── config.json
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"globalEnv": ["NODE_ENV", "CI"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json", "package.json"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
"env": ["NEXT_PUBLIC_*"]
},
"test": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tests/**", "vitest.config.*"],
"outputs": ["coverage/**"]
},
"lint": {
"dependsOn": ["^build"],
"inputs": ["src/**", ".eslintrc.*", "tsconfig.json"]
},
"typecheck": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
# Run all tasks
turbo run build
# Run only affected packages (compared to main)
turbo run build test --filter='...[origin/main]'
# Run for a specific package and its dependencies
turbo run build --filter=@repo/web...
# Run for a specific package only (no deps)
turbo run test --filter=@repo/ui
# Dry run to see what would execute
turbo run build --dry=json
# View dependency graph
turbo run build --graph=graph.html
# Summarize cache usage
turbo run build --summarize
packages:
- 'apps/*'
- 'packages/*'
// packages/ui/package.json
{
"name": "@repo/ui",
"version": "0.0.0",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@repo/types": "workspace:*"
}
}
// apps/web/package.json
{
"name": "@repo/web",
"dependencies": {
"@repo/ui": "workspace:*",
"@repo/utils": "workspace:*"
}
}
# Install all workspace dependencies
pnpm install
# Add a dependency to a specific package
pnpm add zod --filter @repo/api
# Add a workspace package as dependency
pnpm add @repo/utils --filter @repo/web --workspace
# Run a script in a specific package
pnpm --filter @repo/web dev
# Run a script in all packages that have it
pnpm -r run build
# List all packages
pnpm -r ls --depth -1
# Using turbo to see what depends on @repo/ui
turbo run build --filter='...@repo/ui' --dry=json | \
jq '.tasks[].package' -r | sort -u
# Manual: search for imports of a package
grep -r "from '@repo/ui'" apps/ packages/ --include="*.ts" --include="*.tsx" -l
# Generate HTML visualization
turbo run build --graph=dependency-graph.html
# Generate DOT format for custom rendering
turbo run build --graph=deps.dot
# Quick Mermaid diagram from package.json files
echo "graph TD"
for pkg in packages/*/package.json apps/*/package.json; do
name=$(jq -r '.name' "$pkg")
jq -r '.dependencies // {} | keys[] | select(startswith("@repo/"))' "$pkg" | while read dep; do
echo " $name --> $dep"
done
done
# Login to Vercel (one-time)
turbo login
# Link repo to Vercel team
turbo link
# CI: set environment variables
# TURBO_TOKEN=<vercel-token>
# TURBO_TEAM=<team-slug>
# Verify remote cache works
turbo run build --summarize
# Look for "Remote cache: hit" entries
# Using ducktape/turborepo-remote-cache
docker run -p 3000:3000 \
-e STORAGE_PROVIDER=local \
-e STORAGE_PATH=/cache \
ducktape/turborepo-remote-cache
# Configure turbo to use it
# turbo.json:
# { "remoteCache": { "apiUrl": "http://cache-server:3000" } }
# .github/workflows/ci.yml
name: CI
on:
pull_request:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for --filter comparisons
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
# Only lint/test/build affected packages
- run: turbo run lint test build --filter='...[origin/main]'
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
# Install changesets
pnpm add -D -w @changesets/cli @changesets/changelog-github
# Initialize
pnpm changeset init
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }],
"commit": false,
"fixed": [],
"linked": [["@repo/ui", "@repo/utils"]],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch"
}
# 1. Developer adds a changeset for their changes
pnpm changeset
# Interactive: select packages, bump type (patch/minor/major), summary
# 2. Before release: consume changesets and bump versions
pnpm changeset version
# Updates package.json versions and CHANGELOG.md files
# 3. Publish to npm
pnpm changeset publish
# Replaces workspace:* with real versions and publishes
# 1. Preserve git history using filter-repo
# In each source repo:
git filter-repo --to-subdirectory-filter packages/ui
git filter-repo --to-subdirectory-filter apps/api
# 2. Create monorepo and merge histories
mkdir monorepo && cd monorepo && git init
git remote add ui ../old-ui-repo
git fetch ui --no-tags
git merge ui/main --allow-unrelated-histories
git remote add api ../old-api-repo
git fetch api --no-tags
git merge api/main --allow-unrelated-histories
# 3. Set up workspace configuration
# Add pnpm-workspace.yaml, turbo.json, root package.json
# 4. Update internal imports
# Change "ui-package" imports to "@repo/ui"
# Change npm versions to "workspace:*"
# 5. Verify
pnpm install
turbo run build test
| Pitfall | Fix |
|---|---|
Running turbo run build without --filter on every PR | Always use --filter='...[origin/main]' in CI |
workspace:* breaks npm publish | Use pnpm changeset publish which replaces automatically |
| All packages rebuild when unrelated file changes | Tune inputs in turbo.json to exclude docs, config files |
| Shared tsconfig breaks type-checks across packages | Each package extends root but overrides rootDir/ |
packages/types is pure TypeScript — no runtime code, no dependencies, fastest to buildWeekly Installs
1
Repository
GitHub Stars
29
First Seen
Today
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装
| N/A |
| Config complexity | Minimal | Moderate | Minimal | Minimal |
outDir| Git history lost during migration | Use git filter-repo --to-subdirectory-filter before merging |
| Remote cache misses in CI | Verify TURBO_TOKEN and TURBO_TEAM; check with --summarize |
| Import cycles between packages | Use madge --circular to detect; refactor shared code to a new package |