Monorepo (pnpm + Turborepo)
Pathrule2 Rules • 2 Memories • 1 Skill
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.
Suggested path map
Pathrule places each piece on the matching path, so your assistant only sees it where it belongs. This is the scoping you get on import; you can adjust it in your workspace.
Rules
2Every task declares outputs, inputs, and env/turbo.jsonA task that omits outputs, inputs, or env hashing will cache wrong results or never hit cache.
| 1 | Turborepo only caches and replays a task correctly when its hash is complete. Configure each task in `turbo.json` so the hash reflects exactly what the task reads and writes. |
| 2 | |
| 3 | - Set `outputs` to every artifact the task produces (for example `[".next/**", "!.next/cache/**"]` or `["dist/**"]`); a missing `outputs` means nothing is restored from cache. |
| 4 | - Add build-time `env` and `globalEnv` entries for any variable that changes output, and run with `envMode: "strict"` so undeclared vars cannot silently leak into a build. |
| 5 | - Use `dependsOn: ["^build"]` to build upstream packages first, and mark `dev`/`watch` tasks `persistent: true` with `cache: false`. |
| 6 | - Narrow `inputs` only when you understand the default; the safe default already hashes all tracked files in the package. |
Import packages only through their public entry/packagesReaching into another package's src or dist by relative or deep path breaks boundaries and caching.
| 1 | Internal packages are consumed by their name and `exports` map, never by reaching across folders. This keeps Turborepo Boundaries valid and the dependency graph honest. |
| 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 that package's `package.json` with `"@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 exported. |
| 6 | - Run `turbo boundaries` in CI to catch cross-package imports and undeclared dependencies before merge. |
Memories
2Skills
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 plus Turborepo monorepo, covering task hashing, caching, package boundaries, catalog-pinned versions, and shared configs. 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 | - [ ] Every new or changed `turbo.json` task sets `outputs` covering all produced artifacts (and excludes cache dirs like `!.next/cache/**`). |
| 9 | - [ ] Build-affecting env vars are declared in the task `env` or `globalEnv`, and `envMode` is `strict`. |
| 10 | - [ ] `dependsOn` uses `^build` for upstream packages; `dev`/`watch` tasks are `persistent: true` and `cache: false`. |
| 11 | - [ ] New cross-package usage imports by package name (`@repo/*` via `exports`), never by relative or deep `src`/`dist` paths. |
| 12 | - [ ] Each used workspace package is declared with `workspace:*` in the consuming package's `package.json`. |
| 13 | - [ ] `turbo boundaries` and the build pass with a clean dependency graph; no implicit deps. |
| 14 | - [ ] Shared dependency versions use `catalog:` (or a named catalog) instead of hard-coded ranges. |
| 15 | - [ ] `pnpm-lock.yaml` is committed and reflects the install; only one version of each shared dep is resolved. |
| 16 | - [ ] TypeScript, ESLint, and Tailwind extend the shared `@repo/*-config` packages rather than duplicating config. |
| 17 | - [ ] `packageManager` is pinned in the root `package.json` and matches the pnpm version used in CI. |
Why this pattern
Monorepo task pipelines silently lose cache hits and packages drift across boundaries as the repo grows.
Built for Teams running a JavaScript or TypeScript monorepo on pnpm workspaces and Turborepo..
Keeps your assistant from:
- 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
- License
- Apache-2.0
- Version
- 1.0.0
- Updated
- 2026-06-09