Yarn workspaces6/5/2023 Yarn mainatains just one yarn.lock at the monorepo root when workspaces are enabled.While using monorepos with yarn workspaces you get some benefits out of the box: It’ll generate package-lock.json per package and this makes it difficult to run any npm commands like install/uninstall from within the packages directory itself. There’s an open issue here.Ģ.lock files doesn’t plays well when using npm as the npmClient in lerna i.e "npmClient": "yarn". This issue also persists when you want to remove some dependencies from within some package for eg: remove some dependencies from package-2 using npm uninstall. Ideally it should have linked it locally but npm is not aware about lerna. But if you run npm install from package-2 it’ll fail as it will go and find package-1 which is listed as a dependency but it won’t be able to find it on the npm registry as it’s not published. Assume you have the above directory structure and now if you run npm install from monorepo root everything will work fine and all your packages would be linked locally.npm install fails when you run it from anywhere except the root of the monorepo. We can of course use it but there are few things that I would like to highlight about why I prefer yarn over npm over here:ġ. What about npm? Can’t we use monorepos with Lerna and npm? Yarn’s bootstrapping algorithm has proven out to optimise resolution of the packages better over lerna and optimises. When you configure lerna with "npmClient": "yarn" yarn’s bootstarpping algorithm kicks in instead of lerna’s. It doesn’t gives you any commands or utilities that Lerna gives you to manage your packages within monorepos. Yarn Workspaces handles just the bootstrapping part of monorepos i.e install all the dependencies of the packages inside your monorepo and link them internally.It also provides you with other useful commands like lerna version similar to npm version for bumping your package versions, lerna publish similar to npm publish for publishing your packages and many more. Lerna provides a command for this i.e lerna bootstrap. One of the main tasks when you are working with monorepos is bootstrap i.e install all the dependencies of the packages inside your monorepo and link them internally with the help of symlink so you can make changes in one of these packages locally and use those changes in other packages without the need of publishing those changes to registry.
0 Comments
Leave a Reply. |