このページは英語でのみご覧いただけます。
Monorepo (pnpm + Turborepo)
Pathruleルール3件 • メモリ2件 • スキル1件
A pattern bundle for JavaScript and TypeScript monorepos built on pnpm workspaces and Turborepo. It codifies the rules that keep task pipelines deterministic and cacheable, package boundaries explicit, and dependency versions unified. Use it so AI agents and humans both extend the repo without breaking the cache or leaking cross-package imports.
推奨されるパスの配置
Pathruleは各要素を対応するパスに配置するため、アシスタントはそれが属する場所でだけ参照します。これはインポート時に適用されるスコープで、ワークスペースで調整できます。
/ ワークスペースのルート
Pin the pnpm version in packageManager and CI
monorepo-pnpm-turborepo-review
turbo.json/
Every Turborepo task declares outputs, inputs, and env
packages/
Import workspace packages only through their exported public entry
Share base tooling configs as internal workspace packages
pnpm-workspace.yaml/
Pin shared dependency versions with pnpm catalogs
ルール
3Every Turborepo task declares outputs, inputs, and env/turbo.json高強制A task that omits outputs, inputs, or env entries will cache wrong results or never restore from cache.
| 1 | Turborepo only caches and replays a task correctly when its hash covers everything the task reads and produces. Configure each task so the hash is complete. |
| 2 | |
| 3 | - Set `outputs` to every artifact the task produces (for example `[".next/**", "!.next/cache/**"]` or `["dist/**"]`); a missing `outputs` means cache restores nothing. |
| 4 | - Add build-time `env` entries for every variable that affects output, and set `envMode: "strict"` so undeclared variables cannot silently influence a build and invalidate the hash. |
| 5 | - Use `dependsOn: ["^build"]` to build upstream packages first; mark `dev`/`watch` tasks `persistent: true` and `cache: false`. |
| 6 | - Enabling Turborepo Remote Cache (`turbo login && turbo link`) shares hits across CI machines and branches; configure `remoteCache: { enabled: true }` in `turbo.json` and use the Vercel Remote Cache or a self-hosted Turborepo Cache Server. |
Import workspace packages only through their exported public entry/packages高強制Deep or relative imports across packages bypass the exports map and break Turborepo's dependency graph.
| 1 | Internal packages are consumed by their name and `exports` field, never by reaching across folder boundaries. This keeps the dependency graph honest and Turborepo Boundaries valid. |
| 2 | |
| 3 | - Import a workspace package as `@repo/ui` (resolved via its `package.json` `exports`), never as `../../packages/ui/src/...`. |
| 4 | - Declare every workspace package you use in the consuming package's `package.json` as `"@repo/ui": "workspace:*"`; an undeclared import is an implicit dependency Turborepo cannot track. |
| 5 | - Keep each package's public surface in its `exports` field and avoid deep subpath imports unless they are explicitly listed there. |
| 6 | - Run `turbo boundaries` in CI to catch cross-package violations and undeclared dependencies before merge. |
Pin the pnpm version in packageManager and CI/root高強制A mismatched pnpm version between local and CI silently resolves different lockfile entries and breaks reproducibility.
| 1 | The `packageManager` field and the CI install action must agree on the exact pnpm version so the lockfile is interpreted identically everywhere. |
| 2 | |
| 3 | - Set `"packageManager": "pnpm@x.y.z"` (full semver) in the root `package.json`; this is enforced by Corepack when enabled. |
| 4 | - Pin the same version in CI: for GitHub Actions, use `pnpm/action-setup` with an explicit `version` matching the `packageManager` field. |
| 5 | - Commit `pnpm-lock.yaml`; never add it to `.gitignore`. |
| 6 | - Run `pnpm install --frozen-lockfile` in CI so an out-of-date lockfile fails the build rather than silently resolving. |
メモリ
2スキル
1monorepo-pnpm-turborepo-review/rootChecklist to review a pnpm + Turborepo monorepo change before merge.
| 1 | --- |
| 2 | name: monorepo-pnpm-turborepo-review |
| 3 | description: Review checklist for changes in a pnpm workspaces and Turborepo monorepo, covering task hashing and caching, package boundaries, catalog-pinned versions, shared configs, and pnpm version pinning. Use before merging any change that touches turbo.json, pnpm-workspace.yaml, package.json files, or cross-package imports. |
| 4 | --- |
| 5 | |
| 6 | # Monorepo (pnpm + Turborepo) review |
| 7 | |
| 8 | ## Task pipeline and caching |
| 9 | |
| 10 | - [ ] Every new or changed `turbo.json` task sets `outputs` covering all produced artifacts and excludes cache dirs (e.g. `!.next/cache/**`). |
| 11 | - [ ] Build-affecting env vars are declared in the task `env` or `globalEnv`; `envMode` is `strict`. |
| 12 | - [ ] `dependsOn` uses `^build` for upstream packages; `dev`/`watch` tasks are `persistent: true` and `cache: false`. |
| 13 | - [ ] Remote cache is configured if the team uses one (`turbo login` run, `remoteCache.enabled: true` in `turbo.json`). |
| 14 | |
| 15 | ## Package boundaries |
| 16 | |
| 17 | - [ ] New cross-package usage imports by package name (`@repo/*` via `exports`), never by relative or deep `src`/`dist` paths. |
| 18 | - [ ] Each workspace package used is declared with `workspace:*` in the consuming package's `package.json`. |
| 19 | - [ ] `turbo boundaries` and the build pass with no implicit dependencies. |
| 20 | |
| 21 | ## Dependencies and versions |
| 22 | |
| 23 | - [ ] Shared dependency versions use `catalog:` or a named `catalog:` instead of hard-coded ranges. |
| 24 | - [ ] `pnpm-lock.yaml` is committed and reflects the current install; only one resolved version of each shared dep. |
| 25 | - [ ] `packageManager` in the root `package.json` matches the pnpm version pinned in CI (`pnpm/action-setup` `version` field). |
| 26 | - [ ] CI installs with `--frozen-lockfile`. |
| 27 | |
| 28 | ## Shared config |
| 29 | |
| 30 | - [ ] TypeScript, ESLint, and Tailwind extend the shared `@repo/*-config` packages rather than duplicating config. |
| 31 | - [ ] Config package changes bust the cache in all downstream packages (listed as `devDependency workspace:*`). |
このパターンを使う理由
Monorepo task pipelines silently lose cache hits and packages drift across boundaries as the repo grows.
対象:Teams running a JavaScript or TypeScript monorepo on pnpm workspaces and Turborepo.
アシスタントが次のことをしないようにします。
- Cache misses from unset outputs or env vars left out of a task hash
- Cross-package imports that bypass the package's public entry and break boundaries
- Duplicate dependency versions because packages pin their own ranges instead of using the catalog
- ライセンス
- Apache-2.0
- バージョン
- 1.0.1
- 更新日
- 2026-08-25