Giter VIP home page Giter VIP logo

lerna-lite's Introduction

Lerna-Lite ๐Ÿ‰

License: MIT TypeScript Conventional Changelog lerna--lite

Actions Status codecov jest NPM downloads npm

Lerna-Lite is a super light version of the original Lerna


๐Ÿ“ข Lerna-Lite has a new lerna watch command

Watch for file changes within packages and execute commands from the root of the repository. This solves a common problem for package-based monorepos, which is to trigger rebuilds of packages when their files changed. Head over to the lerna watch documentation for more details.

๐Ÿ“ข Lerna-Lite now supports pnpm/yarn workspace: protocol

Take 30sec. to complete this 1 question poll survey ๐Ÿ”˜ if you are using this feature. It's a simple poll to find out which package manager is the most popular with this new workspace: protocol feature. Thanks

Lerna-Lite itself is now also using pnpm workspaces with the workspace: protocol as well ๐ŸŽ‰


Who is using Lerna-Lite

Here are some of the largest projects using the Lerna-Lite fork

Jest ย  | ย  React Navigation ย  | ย  Format.JS ย  | ย  Vee-Validate ย  | ย  Volar ย  | ย  Standard Notes

License

MIT License

About Lerna-Lite

Lerna-Lite differs from the original Lerna since it only has a limited subset of commands from Lerna, which itself has 15 commands, while Lerna-Lite only includes half of them (and a few of them are optional). Lerna was originally built as an all-in-one tool, however nowadays Workspaces are available in all package managers and the need for an all-in-one tool ,which includes built-in workspaces functionalities, is no longer necessary. Lerna-Lite is built around this new reality and its CLI is only including the minimum commands which are init, publish and version, while other commands are available as optional and separate installation (exec, list, run, ...). In summary, Lerna-Lite is more modular than the original Lerna and so you'll end up installing less dependencies, this also makes it more versatile to use with other tools like Turborepo, pnpm and others...

As a summary, Lerna-Lite assumes, and requires you to pre-setup your Workspace through your favorite package manager (npm, pnpm, yarn) that will take care of the symlinks (Lerna-Lite does not include the bootstrap, add and link commands hence the need for a workspace pre-setup), so make sure that your workspace is properly setup before adding Lerna-Lite.

For more info on how to setup a workspace, choose the best option for you: npm 7+ / Yarn classic / Yarn 2+ / pnpm

Why create this lib/fork?

Below are the main reasons as to why this fork was created:

  1. Lerna repo was unmaintained for nearly 2 years (in early 2022, dependencies were really out of date)
    • this is no longer the case since Nrwl took over stewardship of Lerna (we now keep PRs in sync with them when possible), but the next few points are still valid
  2. a desire to create a smaller and more modular lib that is lighter than the original all-in-one Lerna
    • it's smaller since we only copied half of Lerna's commands and many of them are totally optional.
    • the main goal of this fork was to only keep version and publish commands in the core and make everything else as optional packages (choose and install what you really need).
  3. rewrite the lib in TypeScript for type checking and to be compatible with ESM in the future
  4. replicate a few opened PRs (fixes and features) from Lerna and also add extra features in Lerna-Lite
  5. Lerna v5+ is installing Nx as a required dependency (want it or not), while it remains optional in Lerna-Lite
    • even if Nx can be a nice addition with lerna run and useNx (which we did add), it should and will always be optional in Lerna-Lite, it's your decision.
  6. Lerna v5+ is also enforcing useWorkspaces option to be enabled, but this can have undesired effects (you might want to track only the packages folder with Lerna and not other folders like demo or website). Again, that will not be enforced in Lerna-Lite, in fact it's the opposite, I personally prefer to just use packages in lerna.json (especially with pnpm)
  7. add few extra features that currently only exists in Lerna-Lite

This lib will help you with

Version and Publish commands (included with the CLI)

  • Automate the rolling of new Versions (independent or fixed version) of all your workspace packages.
    • it will automatically Commit/Tag your new Version & create new GitHub/GitLab Release (when enabled).
  • Automate, when enabled, the creation of Changelogs for all your packages by reading all Conventional Commits and a merged one in the project root.
  • Automate, when enabled, the repository Publishing of your new version for all your packages (NPM or other platforms).

Other useful, but optional, commands

  • Changed command, when installed, will list all local packages that have changed since the last tagged release
  • Diff command, when installed, will show git diff of all packages or a single package since the last release
  • Exec command, when installed, will help you execute shell commands in parallel and in topological order.
  • List command, when installed, will list all workspace local packages
  • Run command, when installed, will help you run npm script in parallel and in topological order.
  • Watch command, when installed, will watch for changes within packages and execute commands

README Badge

lerna--lite

[![lerna--lite](https://img.shields.io/badge/maintained%20with-lerna--lite-e137ff)](https://github.com/lerna-lite/lerna-lite)

Getting Started

Let's start by installing Lerna as a dev dependency of your project and run the init command to get started (see init#readme for all options).

# install Lerna-Lite globally
$ npm install -g @lerna-lite/cli # pnpm add -g @lerna-lite/cli

# create your monorepo and initialize lerna-lite
$ mkdir lerna-repo
$ cd lerna-repo
$ lerna init

# for npm/yarn (only) workspaces add --use-workspaces
$ lerna init --use-workspaces

This will create a lerna.json configuration file as well as a packages folder, so your folder should now look like this:

lerna-repo/
  packages/
    package-a
  package.json
  lerna.json

Note that package-a will not be created, it is only shown here to help clarify the structure. For more info and full details about the lerna.json file, you can read the lerna.json Wiki.

Installation

Run the following commands to install Lerna-Lite in your project and/or install it globally by adding the -g option.

If you are new to Lerna-Lite, you could also run the lerna init command which will create the lerna.json for you with a minimal setup. If you are using a different client other than npm, then make sure to update the npmClient property in lerna.json (for example: "npmClient": "yarn" or "pnpm").

Note please make sure that you have a lerna.json config file created and a version property defined with either a fixed or independent mode. An error will be thrown if you're missing any of them.

JSON Schema

You can add the $schema property into your lerna.json to take advantage of Lerna-Lite JSON Schema (lerna init will automatically configure this for you). This will help with the developer experience, users will be able to see what properties are valid with a brief description of what they do (each description are pulled from their associated lerna command options documentation).

lerna.json
{
  "$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
  // ...
}

or from a CDN

{
  "$schema": "https://raw.githubusercontent.com/lerna-lite/lerna-lite/main/packages/cli/schemas/lerna-schema.json",
}

CLI Installation

npm i @lerna-lite/cli -D -W

Minimum CLI install to get started with Lerna-Lite, that will give you access to the following list of commands:

Command Description
๐Ÿ› ๏ธ init create/initialize a new Lerna-Lite repo
๐Ÿ“‘ version create new version for each workspace package
โ˜๏ธ publish publish each workspace package

Note: Lerna-Lite CLI is only including 4 built-in commands by default (shown in table above), all other commands are optional commands and must be installed separately as shown in the table below.

Separate / Optional Installs

Command Install Description
๐Ÿ•œ changed npm i @lerna-lite/changed -D -W list local packages changed since last release
๐ŸŒ“ diff npm i @lerna-lite/diff -D -W git diff all packages since the last release
๐Ÿ‘ท exec npm i @lerna-lite/exec -D -W execute an command in each workspace package
๐Ÿ“– list npm i @lerna-lite/list -D -W list local packages
๐Ÿƒ run npm i @lerna-lite/run -D -W run npm script in each workspace package
๐Ÿ‘“ watch npm i @lerna-lite/watch -D -W watch for changes within packages and execute commands when fired

Usage

Add custom NPM Scripts or simply run the commands in a shell with Lerna-Lite CLI, you can see below very basic lerna scripts samples.

// package.json / npm scripts
"scripts": {
  "new-version": "lerna version",
  "new-publish": "lerna publish from-package",
  "run-tests": "lerna run test",        // optional `run` command
}

Migration for existing Lerna Users

If you are migrating from Lerna, it should be fairly easy to just replace Lerna with Lerna-Lite in your dependencies and that's about it, the CLI commands are the same, take a look at the quick steps shown below:

  1. remove Lerna from your local & global dependencies
npm uninstall lerna -W   # OR yarn remove lerna -W
npm uninstall -g lerna   # OR yarn global remove lerna
  1. install Lerna-Lite CLI to get access to built-in init, version and publish commands
# Lerna CLI (includes `init`, `version` and `publish` commands)
npm install @lerna-lite/cli -D -W
  1. optionally install changed, diff, exec, list, run and/or watch commands (refer to installation table above)
# install any of the optional commands (refer to installation table)
npm install @lerna-lite/run -D -W

Note you might see a lot of diff changes in your changelog.md files, that is totally normal since Lerna-Lite has code in place to remove all these extra empty lines that Lerna was adding for no reason.

Project Demo?

You want to see a project demo? Sure, you're looking at it ๐Ÿ˜‰

Yes indeed, this lib was originally created as an NPM Workspace and later changed to a pnpm workspaces for the sole purpose of demoing and testing its own code. All changelogs and published versions are created and published by the lib itself, how sweet is that? You will also find that Lerna-Lite project has its own lerna.json config file to run properly (take a look to see how it works).

See it in Action ๐ŸŽฆ

You can see a small video of a new version release on this Release Demo - Wiki to demonstrate its usage. Confused with all these options? Perhaps taking a look at some of the references shown below might help you get started.

Good Lerna Tutorials / References

Contributions

PR

Feel free to contribute any Pull Request. Also please note that I'm just a simple developer & user of this lib, the same as you are, my knowledge of the library is also limited but together we can make it better.

Development / Contributions

If you wish to contribute to the project, please follow these steps:

Note: this project uses pnpm workspaces, you can install pnpm by following their installation or simply run npx pnpm to run any of the pnpm scripts shown below:

  1. clone the lib:
    • git clone https://github.com/lerna-lite/lerna-lite
  2. install with pnpm from the root:
    • pnpm install OR npx pnpm install
  3. run a full TypeScript (TSC) build
    • pnpm build OR npx pnpm build
  4. add/run Jest unit tests (make sure to run the previous steps first):
    • pnpm jest (full test coverage)
    • pnpm jest:watch (watch mode)
  5. you can also troubleshoot/debug via the VSCode debugger launch configs that were setup for each command

Troubleshooting

If you have problems running the lib and your problems are related to Git commands that were executed, then we suggest to first try with the --dry-run option to see if it helps in finding the error(s) you may have. Another great, and possibly much more useful suggestion, is to search in the original Lerna issues list and see if any solution could help you (remember that Lerna-Lite is a fork of the original code from Lerna and it works the same way). Lastly, if that is not enough and you wish to troubleshoot yourself, then read this Troubleshooting - Wiki to possibly troubleshoot yourself in your own environment.

Lerna-Lite Full List of Packages

Package Name Version Description Changes
@lerna-lite/cli npm Lerna-Lite Init/Info/Version/Publish comands CLI changelog
@lerna-lite/core npm Lerna-Lite core & shared methods (internal use) changelog
@lerna-lite/init npm create a new Lerna-Lite repo changelog
@lerna-lite/publish npm Publish packages in the current workspace changelog
@lerna-lite/version npm Bump Version & write Changelogs changelog
@lerna-lite/exec npm Execute shell command in current workspace changelog
@lerna-lite/changed npm List local packages that changed since last release changelog
@lerna-lite/diff npm Diff all packages or a single package since last release changelog
@lerna-lite/list npm List local packages changelog
@lerna-lite/listable npm Listable utils used by list and changed commands (internal use) changelog
@lerna-lite/filter-packages npm Lerna-Lite filtering package utils used by optional commands (internal use) changelog
@lerna-lite/profiler npm Lerna-Lite Profiler used by some optional commands (internal use) changelog
@lerna-lite/run npm Run npm scripts in current workspace changelog
@lerna-lite/watch npm Watch for changes within packages and execute commands changelog

lerna-lite's People

Contributors

ghiscoding avatar renovate-bot avatar dependabot[bot] avatar renovate[bot] avatar ahrbil avatar xueran avatar azu avatar brammitch avatar jacobsoderblom avatar ghost91- avatar heilmela avatar mrazauskas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.