Erazihel
Erazihel

Reputation: 7605

How to avoid install of packages in monorepo using Yarn

I built a monorepo using Lerna and Yarn workspaces.

Everything works fine but everytime I install a new dependency on a package (let's call him A) using:

yarn add <package_name>

Yarn adds it and then triggers the install script of all the packages in the monorepo, even the ones that A doesn't rely on.

It there anyway to avoid this? It takes a few moment to install them for no reason at all.

Upvotes: 15

Views: 8638

Answers (3)

xdeepakv
xdeepakv

Reputation: 8125

Using scope add the package to the particular module.

lerna add some_package_1 --scope=some_module_x

More: https://github.com/lerna/lerna/tree/master/commands/add#readme

Upvotes: 6

Viktor Vlasenko
Viktor Vlasenko

Reputation: 2502

You can try Yarn 2 with nodeLinker: node-modules in .yarnrc.yml. Yarn 2 guarantees to trigger rebuild only on packages that have their dependencies changed, this is something that was not guaranteed by Yarn 1. However there will still be a very rare case when seemingly unrelated packages be rebuilt if they are hoisted differently after adding new package, but this will happen very rarely.

Upvotes: 4

Ezrqn Kemboi
Ezrqn Kemboi

Reputation: 937

Try adding to the specific workspace with:-

yarn workspace <workspace_name> add <package_name>

For some docs check here

Upvotes: 13

Related Questions