Робочий простір
pnpm має вбудовану підтримку монорепозиторіїв (також відомих як репозиторії з декількома пакунками, репозиторії з декількома проєктами або монолітні репозиторії). Ви можете створити робочий простір, щоб обʼєднати кілька проєктів в одному репозиторії.
A workspace must have a pnpm-workspace.yaml
file in its
root. A workspace also may have an .npmrc
in its root.
Якщо ви розглядаєте управління монорепозиторіями, ви також можете розглянути Bit.
Bit використовує pnpm під капотом, але автоматизує багато речей, які зараз виконуються вручну в традиційному робочому просторі, керованому pnpm/npm/Yarn. There's an article about bit install
that talks about it: Painless Monorepo Dependency Management with Bit.
Протокол робочого простору (workspace:)
If link-workspace-packages is set to true
, 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. Така поведінка вносить певну невизначеність.
Luckily, pnpm supports the workspace:
protocol. При використанні цього протоколу pnpm відмовлятиметься виконувати перетворення на будь-що, окрім пакунків локального робочого простору. 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.