pnpm Workspaces
Purpose
Set up a pnpm-based monorepo so internal packages link cleanly, dependencies stay isolated, and installs are fast and reproducible — the workspace foundation chosen by monorepo-selection, with or without Turborepo on top.
When to Use
- After
monorepo-selection chose pnpm workspaces.
- Not for npm-workspace repos (
npm-workspaces) or single repos.
Inputs
- The package/app inventory and which packages are shared (contracts, types, utils).
- Node/pnpm version policy; whether Turborepo orchestrates (
turborepo-foundation).
Discovery Questions
- What is the workspace layout (
apps/*, packages/*) and which packages are internal-shared?
- Which internal packages depend on which (via the workspace protocol)?
- What Node/pnpm versions are pinned, and how is the lockfile enforced in CI?
Responsibilities
- Define
pnpm-workspace.yaml package globs and a clear apps/ vs packages/ layout.
- Link internal packages with the
workspace: protocol so cross-package deps resolve to local source, not the registry.
- Set the dependency policy: pnpm's strict isolation (no phantom deps) is a feature — each package declares what it imports; avoid loosening hoisting unless a tool genuinely needs it (record why).
- Handle shared-package versioning: internal packages either move in lockstep (unversioned/
workspace:*) or are independently versioned/published — decide and record.
- Enforce reproducibility: committed
pnpm-lock.yaml, --frozen-lockfile in CI, pinned pnpm version (via packageManager field / corepack).
- Coordinate with
docker-foundation (workspace-aware, cached installs in images) and ci-cd (frozen installs, affected-only with Turborepo).
Required Workflow
- Define workspace globs + layout.
- Wire internal deps via
workspace: protocol.
- Set the isolation/hoisting policy (keep strict by default).
- Decide shared-package versioning.
- Enforce lockfile + pinned-version discipline in CI.
Decision Rules
- Keep pnpm's strict isolation — phantom-dependency bugs it prevents are real; loosen only with a recorded reason.
workspace: protocol for all internal deps — never registry versions for local packages.
--frozen-lockfile in CI; a drifting lockfile is a reproducibility bug.
- Pin the package manager version so every environment installs identically.
Rules
- Lockfile committed and frozen in CI.
- Each package declares its own dependencies (no relying on hoisted phantoms).
- Node/pnpm versions pinned across environments.
Anti-Patterns
- Registry versions for internal packages instead of
workspace:.
- Loosening hoisting globally to "fix" a missing declared dependency.
- Uncommitted or unfrozen lockfile → non-reproducible installs.
- Unpinned pnpm version drifting between local and CI.
- Flat, unstructured package layout.
Validation Checklist
Definition of Done
A pnpm-workspace setup with a clear layout, workspace:-linked internal packages, strict dependency isolation, a recorded versioning policy, and frozen, pinned, reproducible installs across environments.
Related Skills
monorepo-selection, turborepo-foundation, npm-workspaces, docker-foundation, ci-cd, ../../security/dependency-security.
Related Knowledge
../../../knowledge/ (package graph, version policy).
Related References
../../../references/devops/ (workspace patterns, when populated).
Context Loading Guidance
- Requires: package inventory, internal dep graph, version policy.
- Does not require: app feature code, unrelated infra.
- May load:
turborepo-foundation, ci-cd.
- Stop when: layout, linking, isolation, versioning, and lockfile discipline are set.
Token Efficiency Guidance
The layout + internal-dep list is the artifact; keep policy to the isolation and versioning decisions.
1---2name: pnpm-workspaces3description: Use to plan a pnpm-workspaces monorepo — workspace layout, internal package linking (workspace protocol), dependency hoisting/isolation policy, versioning of shared packages, and lockfile/CI discipline. Configuration planning; does not scaffold apps.4---56# pnpm Workspaces78## Purpose910Set up a pnpm-based monorepo so internal packages link cleanly, dependencies stay isolated, and installs are fast and reproducible — the workspace foundation chosen by `monorepo-selection`, with or without Turborepo on top.1112## When to Use1314- After `monorepo-selection` chose pnpm workspaces.15- **Not** for npm-workspace repos (`npm-workspaces`) or single repos.1617## Inputs1819- The package/app inventory and which packages are shared (contracts, types, utils).20- Node/pnpm version policy; whether Turborepo orchestrates (`turborepo-foundation`).2122## Discovery Questions2324- What is the workspace layout (`apps/*`, `packages/*`) and which packages are internal-shared?25- Which internal packages depend on which (via the workspace protocol)?26- What Node/pnpm versions are pinned, and how is the lockfile enforced in CI?2728## Responsibilities2930- Define `pnpm-workspace.yaml` **package globs** and a clear `apps/` vs `packages/` layout.31- Link internal packages with the **`workspace:` protocol** so cross-package deps resolve to local source, not the registry.32- Set the **dependency policy**: pnpm's strict isolation (no phantom deps) is a feature — each package declares what it imports; avoid loosening hoisting unless a tool genuinely needs it (record why).33- Handle **shared-package versioning**: internal packages either move in lockstep (unversioned/`workspace:*`) or are independently versioned/published — decide and record.34- Enforce **reproducibility**: committed `pnpm-lock.yaml`, `--frozen-lockfile` in CI, pinned pnpm version (via `packageManager` field / corepack).35- Coordinate with `docker-foundation` (workspace-aware, cached installs in images) and `ci-cd` (frozen installs, affected-only with Turborepo).3637## Required Workflow38391. Define workspace globs + layout.402. Wire internal deps via `workspace:` protocol.413. Set the isolation/hoisting policy (keep strict by default).424. Decide shared-package versioning.435. Enforce lockfile + pinned-version discipline in CI.4445## Decision Rules4647- Keep pnpm's strict isolation — phantom-dependency bugs it prevents are real; loosen only with a recorded reason.48- `workspace:` protocol for all internal deps — never registry versions for local packages.49- `--frozen-lockfile` in CI; a drifting lockfile is a reproducibility bug.50- Pin the package manager version so every environment installs identically.5152## Rules5354- Lockfile committed and frozen in CI.55- Each package declares its own dependencies (no relying on hoisted phantoms).56- Node/pnpm versions pinned across environments.5758## Anti-Patterns5960- Registry versions for internal packages instead of `workspace:`.61- Loosening hoisting globally to "fix" a missing declared dependency.62- Uncommitted or unfrozen lockfile → non-reproducible installs.63- Unpinned pnpm version drifting between local and CI.64- Flat, unstructured package layout.6566## Validation Checklist6768- [ ] Workspace globs + apps/packages layout defined.69- [ ] Internal deps via `workspace:` protocol.70- [ ] Isolation policy set (strict by default; exceptions recorded).71- [ ] Shared-package versioning decided.72- [ ] Frozen lockfile + pinned pnpm in CI.7374## Definition of Done7576A pnpm-workspace setup with a clear layout, `workspace:`-linked internal packages, strict dependency isolation, a recorded versioning policy, and frozen, pinned, reproducible installs across environments.7778## Related Skills7980`monorepo-selection`, `turborepo-foundation`, `npm-workspaces`, `docker-foundation`, `ci-cd`, `../../security/dependency-security`.8182## Related Knowledge8384`../../../knowledge/` (package graph, version policy).8586## Related References8788`../../../references/devops/` (workspace patterns, when populated).8990## Context Loading Guidance9192- **Requires:** package inventory, internal dep graph, version policy.93- **Does not require:** app feature code, unrelated infra.94- **May load:** `turborepo-foundation`, `ci-cd`.95- **Stop when:** layout, linking, isolation, versioning, and lockfile discipline are set.9697## Token Efficiency Guidance9899The layout + internal-dep list is the artifact; keep policy to the isolation and versioning decisions.