Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lerna 101

Lerna 101

Basics of Lerna and Monorepo, presented at catch.com.au

Avatar for mattyao1984

mattyao1984

March 06, 2019
Tweet

More Decks by mattyao1984

Other Decks in Technology

Transcript

  1. LERNA 101 What’s A Monorepo? ▸ The repository contains more

    than one logical project ▸ These projects are most likely unrelated, loosely connected or can be connected by other means (via dependency) ▸ Google has one single Monstrous Monorepo with 9 millions unique source files.
  2. LERNA 101 What do we have now - Cotd &

    Unity ▸ Large codebase with multiple modules / components ▸ Share resources within the big repo ▸ No package management per module ▸ No tagged version per module ▸ No independent installation
  3. LERNA 101 What do we have now - Micro Services

    ▸ Smaller codebase ▸ Module has its own config ▸ Independent installation available ▸ Dedicated CI/CD ▸ Tagged version per module
  4. LERNA 101 What’s Lerna? ▸ A tool for managing a

    javascript projects with multiple packages. ▸ Started by people behind Babel to manage more than 100 packages.
  5. LERNA 101 Lerna CLI ▸ npm install lerna -g ▸

    Lerna init ▸ Lerna bootstrap ▸ Lerna run ▸ Lerna publish
  6. LERNA 101 Lerna modes ▸ Fixed / Locked mode (default)

    ▸ Independent mode: lerna init —independent
  7. LERNA 101 Structure and Strategy ▸ Yarn handles deps ▸

    Lerna handles tasks across 
 multiple packages ▸ One folder per package ▸ Build a generator so all packages have similar 
 structure ▸ Each package defines only its
 runtime deps ▸ Each package contains required
 own configurations, such as Babel, 
 eslint etc. But these configuration can be imported 
 from a shared location. ▸ All packages can have their own versions or 
 they can just have one big version in lerna.json
  8. LERNA 101 Benefits ▸ Manage multiple packages from high-level ▸

    One place to manage CI/CD and release scripts ▸ One place to manage PR ▸ Bootstrap makes linking much easier ▸ Publish makes release much easier ▸ Changes and diff can be tracked easily across packages ▸ You can target single package with —scope ▸ Two modes to manage package versions ▸ Lerna import can absorb existing GitHub repos
  9. LERNA 101 Any downside? ▸ One large repo is not

    friendly to new developers ▸ Bootstrap may take very long time for the first time and longer when it grows bigger ▸ Tests take long time to run if you don’t target a package ▸ Webpack needs to be configured carefully ▸ Who owns this repo?
  10. LERNA 101 Who are using Lerna? ▸ Babel ▸ Create-react-app

    ▸ React-router ▸ Jest ▸ Storybook ▸ Vue-cli ▸ Many many more
  11. LERNA 101 Resources ▸ Monorepos in the wild ▸ Monorepos

    in Git ▸ lerna.io ▸ Monorepo setup with Lerna