Lerna commands #
I have been experimenting with Lerna to manage mono repositories in javascript projects.
Lerna provides a mechanism to run a command on each package in our mono repository with one cli. Here, I write down some of the commands I have been using:
lerna boostrap: this commands links internal depencies between projects, similar to whatyarn link, but for all packages of our mono repository. That way, when change happens in a package, all packages depending on it will have the use changes;lerna clean: it will clean thenode_modulesfolder for allpackagesin our mono repository;lerna add a-dependency --scope=@scoped/package: will installa-dependencyat our internal package which name (atpackage.json) is@scoped/package. A more realistic example, could be:lerna add lodash --scope=utils;
lerna add a-dependency --scope=@scoped/package --dev: same as the previous one, buta-dependencyis installed asdevDependencies(package.json);lerna run a-package-command: it will executea-package-commandfor all packages at the mono repository. Thisa-package-commandis expected to be defined onscriptsproperty ofpackage.jsonfor each package existing at the mono repository. This is very useful, becauselerna, besides, executing it for allpackages, execute it in the correct order, for example, if we havepackage-awhich depends frompackage-b, the command will be executed forpackage-b. If we think on package builds, it is very useful becausepackage-bneeds to be built beforepackage-a. Some more realistic examples, could be:lerna run build;lerna run test;lerna run lint;
lerna run a-package-command --scope=@scoped/package: same as the previous one, but execute the command only for@scoped/package;lerna exec a-bash-command: same asrun, but now the command does not to be defined atpackage.json, but it is expected to be executable;lerna publish from-package: publish packages on a defined registry. We could define the registry explicity using:yarn lerna publish from-package --yes --registry http://localhost:4873;
lerna changed: show whichpackageshave changed since lastpublish;
Published