moon
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemoon - Polyglot Monorepo Build System
moon - 多语言单体仓库构建系统
moon is a Rust-based repository management, task orchestration, and build system for polyglot monorepos. It provides smart caching, dependency-aware task execution, and unified toolchain management.
moon v2 is now available. Runto migrate. Seemoon migrate v2for breaking changes.references/v2-migration.md
moon是一个基于Rust的多语言单体仓库(monorepo)管理、任务编排和构建系统。它提供智能缓存、感知依赖的任务执行以及统一的工具链管理功能。
moon v2 现已发布。 运行进行迁移。请查看moon migrate v2了解破坏性变更。references/v2-migration.md
When to Use moon
适用场景
- Managing monorepos with multiple projects/packages
- Orchestrating tasks across projects with dependencies
- Caching build outputs for faster CI/local builds
- Managing toolchain versions (Node.js, Rust, Python, Go, etc.)
- Generating project and action graphs
- 管理包含多个项目/包的单体仓库
- 跨依赖项目编排任务
- 缓存构建输出以加速CI/本地构建
- 管理工具链版本(Node.js、Rust、Python、Go等)
- 生成项目和任务依赖图
Quick Reference
快速参考
Core Commands
核心命令
bash
moon run <target> # Run task(s)
moon run :lint # Run in all projects
moon run '#tag:test' # Run by tag
moon ci # CI-optimized execution
moon check --all # Run all build/test tasks
moon query projects # List projects
moon project-graph # Visualize dependenciesbash
moon run <target> # 运行任务
moon run :lint # 在所有项目中运行
moon run '#tag:test' # 按标签运行
moon ci # 针对CI优化的执行模式
moon check --all # 运行所有构建/测试任务
moon query projects # 列出所有项目
moon project-graph # 可视化依赖关系Target Syntax
目标语法
| Pattern | Description |
|---|---|
| Specific project and task |
| All projects with this task |
| Projects with tag |
| Upstream dependencies (in deps) |
| Current project (in configs) |
| 模式 | 描述 |
|---|---|
| 指定项目和任务 |
| 在所有包含该任务的项目中运行 |
| 在带有指定标签的项目中运行 |
| 运行上游依赖项目的对应任务 |
| 运行当前项目的对应任务 |
Configuration Files
配置文件
| File | Purpose |
|---|---|
| Workspace settings, project discovery |
| Language versions, package managers (v2) |
| Global inherited tasks (v2) |
| Project-level config and tasks |
v2 Note:→.moon/toolchain.yml(plural),.moon/toolchains.yml→.moon/tasks.yml.moon/tasks/*.yml
| 文件 | 用途 |
|---|---|
| 工作区设置、项目自动发现 |
| 语言版本、包管理器配置(v2版本) |
| 全局可继承任务(v2版本) |
| 项目级配置和任务定义 |
v2版本说明:更名为.moon/toolchain.yml(复数形式),.moon/toolchains.yml调整为.moon/tasks.yml.moon/tasks/*.yml
Workspace Configuration
工作区配置
yaml
undefinedyaml
undefined.moon/workspace.yml
.moon/workspace.yml
$schema: "https://moonrepo.dev/schemas/workspace.json"
projects:
- "apps/*"
- "packages/*"
vcs:
client: "git"
defaultBranch: "main"
pipeline:
archivableTargets:
- ":build"
cacheLifetime: "7 days"
undefined$schema: "https://moonrepo.dev/schemas/workspace.json"
projects:
- "apps/*"
- "packages/*"
vcs:
client: "git"
defaultBranch: "main"
pipeline:
archivableTargets:
- ":build"
cacheLifetime: "7 days"
undefinedProject Configuration
项目配置
yaml
undefinedyaml
undefinedmoon.yml
moon.yml
$schema: "https://moonrepo.dev/schemas/project.json"
language: "typescript"
layer: "application" # v2: 'type' renamed to 'layer'
stack: "frontend"
tags: ["react", "graphql"]
dependsOn:
- "shared-utils"
- id: "api-client" scope: "production"
fileGroups:
sources:
- "src//*"
tests:
- "tests//*"
tasks:
build:
command: "vite build"
inputs:
- "@group(sources)"
outputs:
- "dist"
deps:
- "^:build"
dev:
command: "vite dev"
preset: "server"
v2: Use 'script' for shell features (pipes, redirects)
lint:
script: "eslint . && prettier --check ."
test:
command: "vitest run"
inputs:
- "@group(sources)"
- "@group(tests)"
undefined$schema: "https://moonrepo.dev/schemas/project.json"
language: "typescript"
layer: "application" # v2版本:'type' 重命名为 'layer'
stack: "frontend"
tags: ["react", "graphql"]
dependsOn:
- "shared-utils"
- id: "api-client" scope: "production"
fileGroups:
sources:
- "src//*"
tests:
- "tests//*"
tasks:
build:
command: "vite build"
inputs:
- "@group(sources)"
outputs:
- "dist"
deps:
- "^:build"
dev:
command: "vite dev"
preset: "server"
v2版本:使用 'script' 支持Shell特性(管道、重定向等)
lint:
script: "eslint . && prettier --check ."
test:
command: "vitest run"
inputs:
- "@group(sources)"
- "@group(tests)"
undefinedLayer Types (v2)
层级类型(v2版本)
| Layer | Description |
|---|---|
| Apps, services |
| Shareable code |
| CLIs, scripts |
| E2E/integration tests |
| Templates, generators |
| Infra, config |
| 层级 | 描述 |
|---|---|
| 应用、服务 |
| 可共享代码库 |
| CLI工具、脚本 |
| 端到端/集成测试 |
| 模板、生成器 |
| 基础设施、配置文件 |
Task Configuration
任务配置
Task Fields
任务字段
| Field | Description |
|---|---|
| Command to execute (string or array) |
| Additional arguments |
| Task dependencies |
| Files for cache hashing |
| Files to cache |
| Environment variables |
| Inherit from another task |
| |
| 字段 | 描述 |
|---|---|
| 要执行的命令(字符串或数组) |
| 额外参数 |
| 任务依赖 |
| 用于缓存哈希计算的文件 |
| 要缓存的文件 |
| 环境变量 |
| 继承自其他任务的配置 |
| 预设类型: |
Task Inheritance
任务继承
Tasks can be inherited globally via :
.moon/tasks/*.ymlyaml
undefined任务可通过 实现全局继承:
.moon/tasks/*.ymlyaml
undefined.moon/tasks/node.yml
.moon/tasks/node.yml
inheritedBy:
toolchains: ["javascript", "typescript"]
fileGroups:
sources: ["src/**/*"]
tasks:
lint:
command: "eslint ."
inputs: ["@group(sources)"]
Projects control inheritance:
```yamlinheritedBy:
toolchains: ["javascript", "typescript"]
fileGroups:
sources: ["src/**/*"]
tasks:
lint:
command: "eslint ."
inputs: ["@group(sources)"]
项目可控制继承规则:
```yamlmoon.yml
moon.yml
workspace:
inheritedTasks:
include: ["lint", "test"]
exclude: ["deploy"]
rename:
buildApp: "build"
undefinedworkspace:
inheritedTasks:
include: ["lint", "test"]
exclude: ["deploy"]
rename:
buildApp: "build"
undefinedTask Options
任务选项
yaml
tasks:
example:
command: "cmd"
options:
cache: true # Enable caching
runInCI: "affected" # affected, always, only, false
persistent: true # Long-running process
retryCount: 2 # Retry on failure
timeout: 300 # Seconds
mutex: "resource" # Exclusive lock
priority: "high" # critical, high, normal, lowyaml
tasks:
example:
command: "cmd"
options:
cache: true # 启用缓存
runInCI: "affected" # 可选值:affected, always, only, false
persistent: true # 长期运行进程
retryCount: 2 # 失败后重试次数
timeout: 300 # 超时时间(秒)
mutex: "resource" # 独占锁
priority: "high" # 优先级:critical, high, normal, lowInput Tokens
输入令牌
yaml
inputs:
- "@group(sources)" # File group
- "@globs(tests)" # Glob patterns
- "/tsconfig.base.json" # Workspace root file
- "$NODE_ENV" # Environment variableyaml
inputs:
- "@group(sources)" # 文件组
- "@globs(tests)" # 全局匹配模式
- "/tsconfig.base.json" # 工作区根目录文件
- "$NODE_ENV" # 环境变量Toolchain Configuration
工具链配置
yaml
undefinedyaml
undefined.moon/toolchains.yml (v2: plural)
.moon/toolchains.yml (v2版本:复数形式)
$schema: "https://moonrepo.dev/schemas/toolchains.json"
$schema: "https://moonrepo.dev/schemas/toolchains.json"
JavaScript ecosystem (v2: required for node/bun/deno)
JavaScript生态(v2版本:node/bun/deno必填)
javascript:
packageManager: "pnpm"
inferTasksFromScripts: false
node:
version: "20.10.0"
pnpm:
version: "8.12.0"
javascript:
packageManager: "pnpm"
inferTasksFromScripts: false
node:
version: "20.10.0"
pnpm:
version: "8.12.0"
Alternative runtimes
替代运行时
bun:
version: "1.0.0"
deno:
version: "1.40.0"
typescript:
syncProjectReferences: true
routeOutDirToCache: true
rust:
version: "1.75.0"
bins: ["cargo-nextest", "cargo-llvm-cov"]
go:
version: "1.21.0"
python:
version: "3.12.0"
undefinedbun:
version: "1.0.0"
deno:
version: "1.40.0"
typescript:
syncProjectReferences: true
routeOutDirToCache: true
rust:
version: "1.75.0"
bins: ["cargo-nextest", "cargo-llvm-cov"]
go:
version: "1.21.0"
python:
version: "3.12.0"
undefinedToolchain Tiers
工具链层级
| Tier | Description | Examples |
|---|---|---|
| 3 | Full management | Node.js, Bun, Deno, Rust, Go, Python |
| 2 | Ecosystem integration | PHP, Ruby |
| 1 | Project categorization | Bash, Batch |
| 0 | System execution | Custom tools |
| 层级 | 描述 | 示例 |
|---|---|---|
| 3 | 完全管理 | Node.js、Bun、Deno、Rust、Go、Python |
| 2 | 生态系统集成 | PHP、Ruby |
| 1 | 项目分类 | Bash、Batch |
| 0 | 系统级执行 | 自定义工具 |
CI Integration
CI集成
yaml
undefinedyaml
undefinedGitHub Actions
GitHub Actions
-
uses: actions/checkout@v4 with: fetch-depth: 0 # Required for affected detection
-
uses: moonrepo/setup-toolchain@v0 with: auto-install: true
-
run: moon ci :build :test
-
uses: moonrepo/run-report-action@v1 if: success() || failure() with: access-token: ${{ secrets.GITHUB_TOKEN }}
undefined-
uses: actions/checkout@v4 with: fetch-depth: 0 # 检测变更项目所需
-
uses: moonrepo/setup-toolchain@v0 with: auto-install: true
-
run: moon ci :build :test
-
uses: moonrepo/run-report-action@v1 if: success() || failure() with: access-token: ${{ secrets.GITHUB_TOKEN }}
undefinedParallelization with Matrix
矩阵并行化
yaml
strategy:
matrix:
shard: [0, 1, 2, 3]
steps:
- run: moon ci --job ${{ matrix.shard }} --job-total 4yaml
strategy:
matrix:
shard: [0, 1, 2, 3]
steps:
- run: moon ci --job ${{ matrix.shard }} --job-total 4Affected Detection
变更检测
bash
moon run :test --affected # Only affected projects
moon run :lint --affected --status staged # Only staged files
moon ci :test --base origin/main # Compare against base
moon query changed-files # v2: renamed from touched-filesbash
moon run :test --affected # 仅运行变更项目的任务
moon run :lint --affected --status staged # 仅针对暂存文件
moon ci :test --base origin/main # 与基准分支对比
moon query changed-files # v2版本:从touched-files重命名Docker Support
Docker支持
bash
moon docker scaffold <project> # Generate Docker layers
moon docker setup # Install toolchain in Docker
moon docker prune # Prune for production
moon docker file <project> # Generate Dockerfilebash
moon docker scaffold <project> # 生成Docker分层配置
moon docker setup # 在Docker中安装工具链
moon docker prune # 清理生产环境无用资源
moon docker file <project> # 生成DockerfileMoon Query Language (MQL)
Moon查询语言(MQL)
bash
undefinedbash
undefinedFilter projects
过滤项目
moon query projects "language=typescript && projectType=library"
moon run :build --query "tag=react"
moon query projects "language=typescript && projectType=library"
moon run :build --query "tag=react"
Operators: =, !=, , !, &&, ||
操作符:=, !=, , !, &&, ||
Fields: project, language, stack, tag, task, taskType
字段:project, language, stack, tag, task, taskType
undefinedundefinedAdditional Resources
更多资源
For detailed configuration options, consult:
- - Complete workspace.yml reference
references/workspace-config.md - - Task configuration and inheritance patterns
references/task-config.md - - v1 to v2 migration guide
references/v2-migration.md - - Full CLI command reference
references/cli-reference.md
如需详细配置选项,请参考:
- - 完整的workspace.yml配置参考
references/workspace-config.md - - 任务配置与继承模式
references/task-config.md - - v1到v2迁移指南
references/v2-migration.md - - 完整CLI命令参考
references/cli-reference.md
Examples
示例
- - Complete workspace configuration
examples/workspace.yml - - Full project configuration
examples/moon.yml - - GitHub Actions CI workflow
examples/ci-workflow.yml
- - 完整工作区配置示例
examples/workspace.yml - - 完整项目配置示例
examples/moon.yml - - GitHub Actions CI工作流示例
examples/ci-workflow.yml