Workspace
pnpm has built-in support for monorepositories (AKA multi-package repositories, multi-project repositories, or monolithic repositories). You can create a workspace to unite multiple projects inside a single repository.
A workspace must have a pnpm-workspace.yaml
file in its
root. A workspace also may have an .npmrc
in its root.
If you are looking into monorepo management, you might also want to look into Bit.
Bit uses pnpm under the hood but automates a lot of the things that are currently done manually in a traditional workspace managed by pnpm/npm/Yarn. There's an article about bit install
that talks about it: Painless Monorepo Dependency Management with Bit.
Workspace protocol (workspace:)
By default, pnpm will link packages from the workspace if the available packages
match the declared ranges. For instance, foo@1.0.0
is linked into bar
if
bar
has "foo": "^1.0.0"
in its dependencies and foo@1.0.0
is in the workspace. However, if bar
has
"foo": "2.0.0"
in dependencies and foo@2.0.0
is not in the workspace,
foo@2.0.0
will be installed from the registry. This behavior introduces some
uncertainty.
Luckily, pnpm supports the workspace:
protocol. When
this protocol is used, pnpm will refuse to resolve to anything other than a
local workspace package. So, if you set "foo": "workspace:2.0.0"
, this time
installation will fail because "foo@2.0.0"
isn't present in the workspace.
This protocol is especially useful when the link-workspace-packages option is
set to false
. In that case, pnpm will only link packages from the workspace if
the workspace:
protocol is used.