moon について
moon は、複数言語のモノレポ向けリポジトリ管理・ビルドシステムです。開発チームが依存関係に基づくタスク実行、成果物のキャッシュ、ツールチェーン管理を行えます。
主な機能
- 01依存関係に基づくタスク実行
- 02ビルド成果物のキャッシュ
- 03ツールチェーンのバージョン管理
- 04プロジェクトと依存関係のグラフ生成
- 05影響を受けるプロジェクトの検出
活用シーン
- 01依存プロジェクトをまたぐテスト実行
- 02CI とローカルでの再ビルド削減
- 03モノレポ内の言語バージョン管理
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ hyperb1iss/ moonrepo-skill --skill moonインストール後、Claude Code で/moonを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
examples/ci-workflow.ymlmoon.ymlworkspace.ymlreferences/cli-reference.mdtask-config.mdv2-migration.mdworkspace-config.md詳細
moon - ポリグロットモノレポのビルドシステム
moon は、ポリグロットモノレポ向けの、Rust ベースのリポジトリ管理、タスクオーケストレーション、ビルドシステムです。スマートキャッシュ、依存関係を考慮したタスク実行、統一されたツールチェーン管理を提供します。
moon v2 が利用可能になりました。 移行するには
moon migrate v2を実行してください。破壊的変更についてはreferences/v2-migration.mdを参照してください。
moon を使う場面
- 複数のプロジェクト/パッケージを含むモノレポの管理
- 依存関係のあるプロジェクト間でのタスクのオーケストレーション
- CI/ローカルビルドを高速化するためのビルド出力のキャッシュ
- ツールチェーンのバージョン管理(Node.js、Rust、Python、Go など)
- プロジェクトグラフとアクショングラフの生成
クイックリファレンス
主なコマンド
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 dependencies
ターゲット構文
| パターン | 説明 |
|---|---|
project:task | 特定のプロジェクトとタスク |
:task | このタスクを持つすべてのプロジェクト |
#tag:task | タグを持つプロジェクト |
^:task | 上流の依存関係(deps 内) |
~:task | 現在のプロジェクト(configs 内) |
設定ファイル
| ファイル | 用途 |
|---|---|
.moon/workspace.yml | ワークスペース設定、プロジェクトの検出 |
.moon/toolchains.yml | 言語のバージョン、パッケージマネージャー(v2) |
.moon/tasks/*.yml | グローバルに継承されるタスク(v2) |
moon.yml | プロジェクトレベルの設定とタスク |
v2 に関する注意:
.moon/toolchain.yml→.moon/toolchains.yml(複数形)、.moon/tasks.yml→.moon/tasks/*.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"
プロジェクト設定
# 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)"
レイヤーの種類(v2)
| レイヤー | 説明 |
|---|---|
application | アプリ、サービス |
library | 共有可能なコード |
tool | CLI、スクリプト |
automation | E2E/統合テスト |
scaffolding | テンプレート、ジェネレーター |
configuration | インフラ、設定 |
タスク設定
タスクのフィールド
| フィールド | 説明 |
|---|---|
command | 実行するコマンド(文字列または配列) |
args | 追加の引数 |
deps | タスクの依存関係 |
inputs | キャッシュのハッシュ計算対象となるファイル |
outputs | キャッシュするファイル |
env | 環境変数 |
extends | 別のタスクから継承 |
preset | server または utility |
タスクの継承
.moon/tasks/*.yml を介して、タスクをグローバルに継承できます。
# .moon/tasks/node.yml
inheritedBy:
toolchains: ["javascript", "typescript"]
fileGroups:
sources: ["src/**/*"]
tasks:
lint:
command: "eslint ."
inputs: ["@group(sources)"]
プロジェクト側で継承を制御します。
# moon.yml
workspace:
inheritedTasks:
include: ["lint", "test"]
exclude: ["deploy"]
rename:
buildApp: "build"
タスクのオプション
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, low
入力トークン
inputs:
- "@group(sources)" # File group
- "@globs(tests)" # Glob patterns
- "/tsconfig.base.json" # Workspace root file
- "$NODE_ENV" # Environment variable
ツールチェーン設定
# .moon/toolchains.yml (v2: plural)
$schema: "https://moonrepo.dev/schemas/toolchains.json"
# JavaScript ecosystem (v2: required for node/bun/deno)
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"
ツールチェーンのティア
| ティア | 説明 | 例 |
|---|---|---|
| 3 | 完全な管理 | Node.js、Bun、Deno、Rust、Go、Python |
| 2 | エコシステムとの統合 | PHP、Ruby |
| 1 | プロジェクトの分類 | Bash、Batch |
| 0 | システムによる実行 | カスタムツール |
CI との統合
# 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 }}
マトリックスによる並列化
strategy:
matrix:
shard: [0, 1, 2, 3]
steps:
- run: moon ci --job ${{ matrix.shard }} --job-total 4
影響を受けるプロジェクトの検出
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-files
Docker のサポート
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 Dockerfile
Moon クエリ言語(MQL)
# Filter projects
moon query projects "language=typescript && projectType=library"
moon run :build --query "tag=react"
# Operators: =, !=, ~, !~, &&, ||
# Fields: project, language, stack, tag, task, taskType
参考資料
設定オプションの詳細については、以下を参照してください。
references/workspace-config.md- workspace.yml の完全なリファレンスreferences/task-config.md- タスク設定と継承パターンreferences/v2-migration.md- v1 から v2 への移行ガイドreferences/cli-reference.md- CLI コマンドの完全なリファレンス
例
examples/workspace.yml- ワークスペースの完全な設定examples/moon.yml- プロジェクトの完全な設定examples/ci-workflow.yml- GitHub Actions の CI ワークフロー
コメント
Markdown 対応