mcpField
T
turborepo

turborepo

github.com/shipshitdev開発3987 回インストール1 日前に更新
リポジトリ

turborepo について

turborepo は、Turborepo を使う JavaScript と TypeScript のモノレポ向けガイダンススキルです。タスク設定、キャッシュ、環境変数、フィルタリング、CI のルールと参照先を示します。

主な機能

  1. 01Turborepo タスクの設定
  2. 02キャッシュと出力設定の指針
  3. 03環境変数設定への対応
  4. 04影響を受けるパッケージの抽出
  5. 05モノレポと CI の計画

活用シーン

  1. 01パッケージ間のビルド依存関係の設定
  2. 02ビルドキャッシュミスの調査
  3. 03CI で影響対象のタスクを実行

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/shipshitdev/skills --skill turborepo

インストール後、Claude Code で/turborepoを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

plugin.json
command/
turborepo.md
references/best-practices/
dependencies.md
packages.md
RULE.md
structure.md
references/boundaries/
RULE.md
references/caching/
gotchas.md
remote-cache.md
RULE.md
references/ci/
github-actions.md
patterns.md
RULE.md
vercel.md
references/cli/
commands.md
RULE.md
references/configuration/
global-options.md
gotchas.md
RULE.md
tasks.md
references/environment/
gotchas.md
modes.md
RULE.md
references/filtering/
patterns.md
RULE.md
references/watch/
RULE.md

詳細

Turborepo スキル

Turborepo を使用した JavaScript および TypeScript のモノレポ向けビルドシステムのガイダンスです。

コアとなるルール

  1. ルートタスクではなく、パッケージタスクを作成します。
  2. タスクの動作は turbo.json に登録します。
  3. ルートの package.json から turbo run <task> を呼び出します。
  4. turbo <task> は対話型の単発ターミナルコマンドにのみ使用し、コミットするコードでは使用しません。
  5. dependsOn: ["^build"] で実際のパッケージ間の依存関係を解決できるよう、ワークスペースの依存関係を package.json に宣言します。

基本パターン

// apps/web/package.json
{
  "scripts": {
    "build": "next build",
    "lint": "eslint .",
    "test": "vitest"
  }
}
// turbo.json
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
    },
    "lint": {},
    "test": {
      "dependsOn": ["build"]
    }
  }
}
// root package.json
{
  "scripts": {
    "build": "turbo run build",
    "lint": "turbo run lint",
    "test": "turbo run test"
  }
}

クイックルーティング

タスクに必要なリファレンスファイルのみを読みます。

必要な項目読むファイル
タスク定義、dependsOn、outputs、persistent、パッケージのオーバーライドreferences/configuration/RULE.md、references/configuration/tasks.md
グローバルオプション、デーモン、cacheDir、環境モードreferences/configuration/global-options.md
キャッシュミスまたはリモートキャッシュreferences/caching/RULE.md、references/caching/gotchas.md、references/caching/remote-cache.md
環境変数、.env、strict モードと loose モードreferences/environment/RULE.md、references/environment/modes.md、references/environment/gotchas.md
--affected、--filter、パッケージの選択references/filtering/RULE.md、references/filtering/patterns.md
CI、GitHub Actions、Vercel、turbo-ignorereferences/ci/RULE.md、references/ci/github-actions.md、references/ci/vercel.md、references/ci/patterns.md、references/cli/commands.md
リポジトリ構造、パッケージの作成、依存関係の管理references/best-practices/RULE.md、references/best-practices/structure.md、references/best-practices/packages.md、references/best-practices/dependencies.md
ウォッチモードと長時間実行する開発タスクreferences/watch/RULE.md、references/configuration/tasks.md
パッケージ境界と分離references/boundaries/RULE.md

判断ツリー

タスクを設定する
Configure a task?
├─ Define dependencies or outputs → configuration/tasks.md
├─ Handle environment variables → environment/RULE.md
├─ Set package-specific overrides → configuration/RULE.md#package-configurations
├─ Add persistent/watch behavior → configuration/tasks.md + watch/RULE.md
└─ Tune global options → configuration/global-options.md
キャッシュをデバッグする
Cache issue?
├─ Outputs not restored → add or fix `outputs`
├─ Unexpected misses → caching/gotchas.md
├─ Remote cache issue → caching/remote-cache.md
└─ Env or .env drift → environment/gotchas.md
変更された項目のみを実行する
Need changed packages only?
├─ Default path → `turbo run <task> --affected`
├─ Custom comparison base → add `--affected-base=...`
└─ Custom package selection → filtering/RULE.md + filtering/patterns.md
CI を設定する
CI setup?
├─ GitHub Actions → ci/github-actions.md
├─ Vercel deployment → ci/vercel.md
├─ Remote cache in CI → caching/remote-cache.md
└─ Skip unchanged work → ci/patterns.md + cli/commands.md
モノレポを構成する
Repo/package structure?
├─ apps/ vs packages/ layout → best-practices/RULE.md
├─ Create internal package → best-practices/packages.md
├─ Workspace dependency management → best-practices/dependencies.md
└─ Enforce package boundaries → boundaries/RULE.md

重大なアンチパターン

  • Turborepo を完全に迂回するルートスクリプト。ルートスクリプトでは、アプリ固有のタスクロジックを埋め込むのではなく、turbo run を呼び出します。
  • package.json、CI、スクリプトにコミットされた turbo build または turbo lint コマンド。コミットするコードでは turbo run ... を使用します。
  • ワークスペースの依存関係を宣言して ^build を使用する代わりに、兄弟パッケージをコンパイルする手動の prebuild チェーン。
  • ファイルを書き出すタスクに outputs がないこと。タスクをキャッシュ可能と判断する前に、実際のスクリプトを確認します。
  • env から環境変数が漏れている、または inputs から .env ファイルが漏れているために、古いキャッシュがヒットすること。
  • モノレポのルートレベルに .env ファイルを置くこと。パッケージ間に見えにくい結合を生みます。
  • パッケージ API を通じてインポートせず、相対インポートやファイルの階層をたどってパッケージ境界を越えること。
  • パッケージごとのオーバーライドでルートの turbo.json を煩雑にすること。代わりにパッケージごとの turbo.json ファイルを使用します。

詳しい例については、以下を参照してください。

  • references/configuration/gotchas.md
  • references/caching/gotchas.md
  • references/environment/gotchas.md
  • references/best-practices/structure.md
  • references/best-practices/packages.md

よくある設定

標準的なビルドと開発
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    }
  }
}
キャッシュを正しく無効化しながら並列タスクを実行するための中継ノード
{
  "tasks": {
    "transit": {
      "dependsOn": ["^transit"]
    },
    "lint": {
      "dependsOn": ["transit"]
    }
  }
}

タスクを並列実行できる一方で、依存関係にあるソースの変更をキャッシュ無効化に反映する必要がある場合に使用します。

ウォッチモードのパターン

ファイル変更の監視ループには turbo watch を使用し、スクリプト内で即席に作成した turbo run ... --watch パターンは使用しません。persistent、interruptible、または with を設定する前に、references/watch/RULE.md を読んでください。

検証チェックリスト

  • コードまたは CI でコミットされているすべてのコマンドは、turbo run ... を使用しています。
  • タスクはパッケージのスクリプトに記述し、ルートのスクリプトは委譲のみを行います。
  • dependsOn は実際の依存関係に一致しています。上流のパッケージには ^task、同じパッケージ内の前提タスクには task を使用します。
  • キャッシュ可能なファイル生成タスクでは、outputs を宣言しています。
  • 関連する環境変数は env または globalEnv に記述しています。
  • 関連する .env ファイルは inputs に含めています。
  • ワークスペースのパッケージ間のインポートには、相対ソースパスではなくパッケージ名を使用しています。
  • CI では、デフォルトですべてを再ビルドするのではなく、適切な場合に --affected またはフィルターを使用しています。

参照ドキュメント

Turborepo の公式ドキュメント(ライブラリ v2.9.7-canary.12)に基づいています:apps/docs/content/docs/ — https://turborepo.dev/docs

コメント