Lerna is a wrapper around package manager that optimizes the workflow around publishing multi-package repositories with git and yarn
You can no longer work on a single package by cd-ing into it, and using normal npm/yarn scripts.
This is because of the way lerna hoists commands up to the root level. When working on a single package, instead run the lerna command with a scope of that package name.
Example:
lerna run build
lerna run build --scope 'packageName'
lerna run test --scope 'packageName'
Npm/Yarn command | Lerna Command | Desc |
---|---|---|
install | bootstrap | Install all packages dependencies and link any cross-dependencies |
hoisting is just a way to install all dependencies up to the root directory of lerna (the topmost directory) (no node_modules directory at every project). The tools must follows the Node module resolution algorithm to find them. Lerna does not create symlink. See also: hosting in yarn
and –parallel for installing dependencies
See lerna link - Symlink together all Lerna packages that are dependencies of each other in the current Lerna repo.
hosted on GitHub: https://github.com/lerna/lerna#git-hosted-dependencies
Package hosted in git
{
"name": "pkg-2",
"version": "1.0.0"
}
{
"name": "pkg-1",
"version": "1.0.0",
"dependencies": {
"pkg-2": "github:example-user/pkg-2#v1.0.0"
}
}
Instead of running npm install in order to install dependencies, you should run lerna bootstrap.
See FAQ
Bootstrap:
yarn global add lerna
lerna bootstrap
lerna notice cli v3.13.4
lerna info Bootstrapping 1 package
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 1 package
lerna add eslint --dev
# then
lerna bootstrap
lerna add eslint packages\myPackage
# then
lerna bootstrap
Example of output:
lerna notice cli v3.13.4
lerna info versioning independent
lerna info Adding eslint in 3 packages
lerna notice filter excluding "component-*"
lerna info filter [ '!component-*' ]
lerna info Bootstrapping 3 packages
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 3 packages
- Test will run first Pretest
cd MonoRepoRoot
lerna run test
lerna notice cli v3.13.4
lerna info versioning independent
lerna info Executing command in 1 package: "yarn run test"
lerna info run Ran npm script 'test' in 'micro-now' in 15.0s:
yarn run v1.15.2
$ eslint src
$ jest
console.log src/router.js:3
/api/profiles/(?<id>[^/]*)
console.log src/router.js:4
backend/api/profiles/profile.js?id=$id
Done in 14.12s.
lerna success run Ran npm script 'test' in 1 package in 15.0s:
lerna success - micro-now
#scope is for package names ?
lerna publish --scope="pkg-*"
The link command base concept of all monorepo that symlink together all Lerna packages that are dependencies of each other in the current Lerna repo.
lerna link
bootstrap link also
yarn global add verdaccio