Monorepos & Workspaces (npm, pnpm & Turborepo)

Master monorepo package management using npm workspaces, pnpm workspaces, and Turborepo task pipeline caching for fast, modular multi-package projects.

Package Managers6 min readConcept 19 of 24

What are Workspaces and Monorepos?

A monorepo (monolithic repository) is a version control pattern where multiple projects, applications, and shared libraries reside inside a single repository. Workspaces are package manager features native to npm, pnpm, and Yarn that link these internal packages together automatically.

Instead of publishing shared UI components or utility functions to an external npm registry during development, workspaces create local symlinks inside node_modules. This allows applications like apps/web to import internal packages like @myorg/ui instantly with live code updates.

Why manage projects with monorepos and build orchestrators?

Separate repositories force developers to publish, version, and reinstall internal packages every time a shared component changes. Monorepos unify your codebase so changes across multiple applications and libraries can be made in a single atomic git commit.

However, running builds and tests across dozens of packages sequentially is slow. Build orchestrators like Turborepo and Nx analyze your monorepo dependency graph to execute tasks in parallel, skipping unneeded work via intelligent local and remote computation caching.

How Workspaces Link Packages and Turborepo Orchestrates Pipelines

In npm workspaces, the root package.json defines a workspaces array listing package directories such as apps/* and packages/*. Running npm install automatically hoists shared dependencies to root node_modules and symlinks internal packages.

In pnpm workspaces, packages are defined in pnpm-workspace.yaml, and internal dependencies use the explicit workspace:* protocol inside package.json. Turborepo then uses a turbo.json file where dependsOn: ["^build"] instructs the task runner to build shared internal packages before compiling dependent applications.

Interactive Monorepo Workspace & Turborepo Pipeline Simulator

Explore workspace symlinks, simulate topological build execution graphs, and test Turborepo computation caching in real time.

// Monorepo Configuration (TURBO)
// turbo.json Pipeline Config
{ "tasks": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] } } }
Manager:
Monorepo Workspace File Architecture
my-monorepo/
├── turbo.json
├── packages/
└── ui/ (@myorg/ui v1.0.0)
├── apps/
├── web/ (imports @myorg/ui)
└── docs/ (imports @myorg/ui)
├── Local Workspace Symlinks:
node_modules/@myorg/ui -> symlink to packages/ui

Interactive Monorepo Workspace & Turborepo Task Pipeline Simulator

Remember this

  • Workspaces link local internal packages using symlinks in npm or workspace:* protocols in pnpm.
  • Turborepo uses turbo.json with dependsOn: ["^build"] to establish topological dependency build order.
  • Turborepo caches build inputs and outputs, delivering instant FULL TURBO execution when code is unchanged.
  • Avoid circular dependencies between internal packages to prevent broken build pipelines and undefined exports.

Done with this concept?

Mark it complete to track your progress. No login needed.