-
Notifications
You must be signed in to change notification settings - Fork 3
Technical Guidelines
Lerna is a popular tool for managing JavaScript projects with multiple packages, optimizing the workflow around managing multi-package repositories with git and your package manager.
Before you can use Lerna, you need to install it globally on your machine:
npm install --g lerna
- Bootstrap the project
We use a thing called Workspaces to link any cross-dependencies. This allows us to install all node_modules for each package, and also hoist common dependencies to the root of your project. This was previously done by using
lerna bootstrap
but thebootstrap
command got deprecated in favour of the NPM solution. This process is done by running:
npm install
- Add a new package
You can add a new package to the monorepo with the
lerna create
command:
lerna create package-name
- Installing modules
To install dependencies across all packages in a Lerna-managed monorepo, you can use the
lerna add
command. This command adds a package to the packages in the monorepo.
lerna add package-name --scope=some-package
Replace package-name
with the name of the package you want to install, and some-package with the name of the specific package(s) you want to add the dependency to. If you want to add the dependency to all packages, you can omit the --scope
flag:
lerna add package-name
This command will add the specified package as a dependency in all of your Lerna packages.
No, adding a module to the
package.json
of the root of your monorepo will not automatically add it to all of your packages. The rootpackage.json
and thepackage.json
files in each package are separate. If you add a module to thedevDependencies
ordependencies
in the rootpackage.json
, it will only be installed at the root level. It will not be available to the individual packages unless you specifically import it in those packages.
Yes, you can use the
lerna run test
command or more specifically call one of the test-scripts defined in the rootpackage.json
of the monorepo.
"scripts": {
"test:unit": "lerna run test:unit",
"test:integration": "lerna run test:integration",
}