monorepo-management – skill Lập trình cho agent AI
Thành thạo quản lý monorepo với Turborepo, Nx và pnpm workspaces để xây dựng kho nhiều package hiệu quả, dễ mở rộng với build được tối ưu và quản lý dependency. Dùng khi thiết lập monorepo, tối ưu build hoặc quản lý dependency dùng chung.
Cài skill monorepo-management bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/monorepo-management-e8f42.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /monorepo-management – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/monorepo-management-e8f42.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $monorepo-management – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/monorepo-management-e8f42.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /monorepo-management – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/monorepo-management-e8f42.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /monorepo-management – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Monorepo Management
Build efficient, scalable monorepos that enable code sharing, consistent tooling, and atomic changes across multiple packages and applications.
When to Use This Skill
- Setting up new monorepo projects
- Migrating from multi-repo to monorepo
- Optimizing build and test performance
- Managing shared dependencies
- Implementing code sharing strategies
- Setting up CI/CD for monorepos
- Versioning and publishing packages
- Debugging monorepo-specific issues
Core Concepts
1. Why Monorepos?
Advantages:
- Shared code and dependencies
- Atomic commits across projects
- Consistent tooling and standards
- Easier refactoring
- Simplified dependency management
- Better code visibility
Challenges:
- Build performance at scale
- CI/CD complexity
- Access control
- Large Git repository
2. Monorepo Tools
Package Managers:
- pnpm workspaces (recommended)
- npm workspaces
- Yarn workspaces
Build Systems:
- Turborepo (recommended for most)
- Nx (feature-rich, complex)
- Lerna (older, maintenance mode)
Turborepo Setup
Initial Setup
# Create new monorepo
npx create-turbo@latest my-monorepo
cd my-monorepo
# Structure:
# apps/
# web/ - Next.js app
# docs/ - Documentation site
# packages/
# ui/ - Shared UI components
# config/ - Shared configurations
# tsconfig/ - Shared TypeScript configs
# turbo.json - Turborepo configuration
# package.json - Root package.jsonConfiguration
// turbo.json
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false,
"persistent": true
},
"type-check": {
"dependsOn": ["^build"],
"outputs": []
}
}
}// package.json (root)
{
"name": "my-monorepo",
"private": true,
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"test": "turbo run test",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"clean": "turbo run clean && rm -rf node_modules"
},
"devDependencies": {
"turbo": "^2.0.0",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
},
"packageManager": "[email protected]"
}pnpm reads workspace packages only from pnpm-workspace.yaml, so declare them there (see references/details.md). Turborepo 2 renamed pipeline to tasks and rejects a turbo.json that still uses pipeline; run npx @turbo/codemod migrate to upgrade a 1.x config.
Package Structure
// packages/ui/package.json
{
"name": "@repo/ui",
"version": "0.0.0",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./button": {
"import": "./dist/button.js",
"types": "./dist/button.d.ts"
}
},
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
"lint": "eslint src/",
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@repo/tsconfig": "workspace:*",
"tsup": "^7.0.0",
"typescript": "^5.0.0"
},
"dependencies": {
"react": "^18.2.0"
}
}Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
1. Consistent Versioning: Lock dependency versions across workspace
2. Shared Configs: Centralize ESLint, TypeScript, Prettier configs
3. Dependency Graph: Keep it acyclic, avoid circular dependencies
4. Cache Effectively: Configure inputs/outputs correctly
5. Type Safety: Share types between frontend/backend
6. Testing Strategy: Unit tests in packages, E2E in apps
7. Documentation: README in each package
8. Release Strategy: Use changesets for versioning
Common Pitfalls
- Circular Dependencies: A depends on B, B depends on A
- Phantom Dependencies: Using deps not in package.json
- Incorrect Cache Inputs: Missing files in Turborepo inputs
- Over-Sharing: Sharing code that should be separate
- Under-Sharing: Duplicating code across packages
- Large Monorepos: Without proper tooling, builds slow down
Publishing Packages
# Using Changesets
pnpm add -Dw @changesets/cli
pnpm changeset init
# Create changeset
pnpm changeset
# Version packages
pnpm changeset version
# Publish
pnpm changeset publish# .github/workflows/release.yml
- name: Create Release Pull Request or Publish
uses: changesets/action@v1
with:
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}Skill liên quan
- cto-advisor – Hướng dẫn lãnh đạo kỹ thuật cho đội ngũ kỹ sư, quyết định kiến trúc và chiến lược công…
- cto-review – /c-level-agents:cto-review [plan] — Rà soát kiến trúc và khả năng mở rộng. Nợ kỹ thuật…
- imessage – Gửi và nhận iMessage/SMS qua CLI imsg trên macOS.
- multi-reviewer-patterns – Điều phối code review song song trên nhiều khía cạnh chất lượng, với khử trùng lặp phát…
- inference-sh-cli – Chạy hơn 150 ứng dụng AI (hình ảnh, video, LLM) qua inference.sh CLI.
- nodejs-backend-patterns – Xây dựng dịch vụ backend Node.js sẵn sàng cho production với Express/Fastify, triển khai…
- decision-logger – Kiến trúc bộ nhớ hai lớp cho các quyết định của cuộc họp ban giám đốc. Quản lý bản ghi…
- azure-security-keyvault-keys-java – SDK Azure Key Vault Keys cho Java để quản lý khóa mật mã. Dùng khi tạo, quản lý hoặc sử…