MonoRepo Manager - Lerna

About

Lerna is a wrapper around package manager that optimizes the workflow around publishing multi-package repositories with git and yarn

Issues

Architecture

Run

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:

  • Global for all packages
lerna run build
  • Only for one package
lerna run build --scope 'packageName'
lerna run test --scope 'packageName'

Command Mapping

Npm/Yarn command Lerna Command Desc
install bootstrap Install all packages dependencies and link any cross-dependencies

Dependency

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

Dev Dependency

  • devDependencies can be pulled up to the root package.json of a Lerna repo

Cross Packages Dependency

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"
  }
}

Command

Bootstrap

Instead of running npm install in order to install dependencies, you should run lerna bootstrap.

See FAQ

Bootstrap:

  • Installing all packages dependencies
  • Linking any cross-dependencies
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

Add

  • A dev dependency to all package
lerna add eslint --dev
# then
lerna bootstrap
  • A dependency to one package
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

Run

- 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

Publish

#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

Note

Verdaccio

yarn global add verdaccio





Discover More
Javascript - MonoRepo

in the Javascript context When starting with monorepo, integrate first the leaf projects of the dependency graph (ie project without dependency). To use the library locally without publishing to...



Share this page:
Follow us:
Task Runner