Skip to content
索引

Lerna-Lite

Lerna-Lite是原版Lerna的超轻版

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, Lerna's dependencies were really out of date) Lerna repo 近 2 年无人维护(2022 年初,Lerna 的依赖项真的过时了)

    • this is no longer the case since Nrwl, the company behind Nx, took over stewardship of Lerna 自从Nx背后的公司Nrwl接管了Lerna的管理权以来,情况不再如此。
      • please note that Lerna-Lite fork was created couple months before Nrwl took over Lerna 请注意,Lerna-Lite 分叉是在 Nrwl 接管 Lerna 之前几个月创建的。
      • we now replicate Lerna's PRs when possible (except Nx specific code will not be replicated) 我们现在尽可能复制 Lerna 的 PR(除了 Nx 特定的代码不会被复制)
  2. A desire to create a smaller and a lighter alternative compared to the original all-in-one Lerna tool 与原始的多合一 Lerna 工具相比,希望创建一个更小、更轻的替代品

    • Lerna-Lite is entirely modular, all commands are totally optional (install only what you really need). Lerna-Lite是完全模块化的,所有命令都是完全可选的(只安装你真正需要的命令)。
  3. Rewrote the lib in TypeScript and build the project as ESM since v2.0 (you can still use it in a CJS environment) 在 TypeScript 中重写了库,并从 v2.0 开始将项目构建为 ESM(您仍然可以在 CJS 环境中使用它)

  4. Replicated a few opened PRs from Lerna and add a few unique features into Lerna-Lite (see number 6 below) 从 Lerna 复制了一些打开的 PR,并在 Lerna-Lite 中添加了一些独特的功能(见下面的数字 6)

  5. Lerna is becoming another Nx branded product (Lerna >=5.5 now requires Nx while not required in Lerna-Lite) Lerna正在成为另一个Nx品牌的产品(Lerna >=5.5现在需要Nx,而在Lerna-Lite中不需要)

    • if you already use Nx then it's probably better to use Lerna, but if you are not then Lerna-Lite is preferred 如果您已经在使用 Nx,那么最好使用 Lerna,但如果您不是,那么 Lerna-Lite 是首选
    • if you use other tools like TurboRepo and install Lerna (original) you end up downloading 2 similar tools 如果您使用其他工具(如 TurboRepo)并安装 Lerna(原始),您最终会下载 2 个类似的工具
    • even TypeScript is now required in Lerna >=6 (even for a JS monorepo) however not required in Lerna-Lite 甚至 TypeScript 现在在 Lerna 中也是必需的 >=6(即使是 JS monorepo),但在 Lerna-Lite 中不需要
  6. Added a few unique features that are available currently only in Lerna-Lite: 添加了一些目前仅在 Lerna-Lite 中可用的独特功能:

    • workspace: protocol support () Lerna added support for that too six months later in v6 workspace: 协议支持 () 六个月后,Lerna 在 v6 中也添加了对此的支持

    • --dry-run to preview version/publish and changelogs locally --dry-run在本地预览版本/发布和更改日志

    • lerna version --changelog-header-message "msg" it could be used to add sponsor badges in changelogs Lerna 版本 --changelog-header-message “msg” 它可用于在变更日志中添加发起人徽章

    • lerna version --changelog-include-commits-client-login to add PR contributors lerna 版本 --changelog-include-commits-client-login 以添加 PR 贡献者

    • lerna version --allow-peer-dependencies-update if you want your peer deps to also be updated lerna 版本 --allow-peer-dependencies-update 如果你希望你的对等部门也被更新

    • lerna version --skip-bump-only-releases to avoid cluttering your GitHub releases in independent mode lerna 版本 --skip-bump-only-release,以避免在模式中 independent 混乱您的 GitHub 发布

    • lerna publish --remove-package-fields

      (remove certain fields from package.json before publishing) lerna publish --remove-package-fields (在发布之前删除 package.json 某些字段)

      • ie: Lerna-Lite itself uses it to remove scripts and devDependencies 即:Lerna-Lite 本身使用它来删除 scriptsdevDependencies

On a final note, the best feature of Lerna-Lite (versus Lerna) has to be its modularity. A large portion of the users are only interested in version/publish commands but on the other hand, a small minority are only interested in other commands like run/exec. Lerna-Lite offers this flexibility by allowing the user to install only the command(s) that he/she is interested in using (see installation below). Lastly from the list above, the number 5 could be a concern for some users who are not interested to use Nx (like me) and still want to have the power of Lerna but keep their download to the bare minimum. 最后,Lerna-Lite(与Lerna相比)的最佳功能必须是其模块化。很大一部分用户只对版本/发布命令感兴趣,但另一方面,少数用户只对其他命令感兴趣,如 run/exec。Lerna-Lite 通过允许用户仅安装他/她感兴趣的命令来提供这种灵活性(请参阅下面的安装)。最后,从上面的列表中,数字 5 可能是一些对使用 Nx 不感兴趣的用户(像我一样)并且仍然希望拥有 Lerna 的强大功能但将下载保持在最低限度的用户的关注点。

This lib will help you with 这个库将帮助您

Note all commands are optional in Lerna-Lite, refer to the Installation table for more info 请注意,所有命令在 Lerna-Lite 中都是可选的,有关详细信息,请参阅安装表

Version and Publish commands 版本控制和发布命令

  • Automate the creation of new Versions ( independent or fixed version) of all your workspace packages. 自动创建所有工作区包的新版本( independent 或固定版本)。
    • it will automatically Commit/Tag your new Version & create new GitHub/GitLab Release (when enabled). 它将自动提交/标记您的新版本并创建新的GitHub / GitLab版本(启用时)。
  • Automate, when enabled, the creation of Changelogs for all your packages by reading all Conventional Commits. 启用后,通过读取所有常规提交,自动为所有包创建更改日志。
  • Automate, the repository Publishing of your new version(s) for all your packages (on NPM or other platforms). 自动化存储库发布所有软件包的新版本(在 NPM 或其他平台上)。

Other optional commands 其他可选命令

  • Changed command, when installed, will list all local packages that have changed since the last tagged release Changed 命令在安装后将列出自上次标记版本以来已更改的所有本地软件包
  • Diff command, when installed, will show git diff of all packages or a single package since the last release Diff 命令在安装后,将显示自上一版本以来所有软件包或单个软件包的 git diff
  • Exec command, when installed, will help you execute shell commands in parallel and in topological order. Exec 命令在安装后,将帮助您并行和按拓扑顺序执行 shell 命令。
  • 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. 运行命令,安装后,将帮助您并行和拓扑顺序运行 npm 脚本。
  • Watch command, when installed, will watch for changes within all packages and execute certain commands watch 命令在安装后将监视所有包中的更改并执行某些命令

Lerna-Lite 支持 pnpm/yarn workspace: 协议

This lib will help you with 这个库将帮助您

Note all commands are optional in Lerna-Lite, refer to the Installation table for more info 请注意,所有命令在 Lerna-Lite 中都是可选的,有关详细信息,请参阅安装表

Version and Publish commands 版本控制和发布命令

  • Automate the creation of new Versions ( independent or fixed version) of all your workspace packages. 自动创建所有工作区包的新版本( independent 或固定版本)。
    • it will automatically Commit/Tag your new Version & create new GitHub/GitLab Release (when enabled). 它将自动提交/标记您的新版本并创建新的GitHub / GitLab版本(启用时)。
  • Automate, when enabled, the creation of Changelogs for all your packages by reading all Conventional Commits. 启用后,通过读取所有常规提交,自动为所有包创建更改日志。
  • Automate, the repository Publishing of your new version(s) for all your packages (on NPM or other platforms). 自动化存储库发布所有软件包的新版本(在 NPM 或其他平台上)。

Other optional commands 其他可选命令

  • Changed command, when installed, will list all local packages that have changed since the last tagged release Changed 命令在安装后将列出自上次标记版本以来已更改的所有本地软件包
  • Diff command, when installed, will show git diff of all packages or a single package since the last release Diff 命令在安装后,将显示自上一版本以来所有软件包或单个软件包的 git diff
  • Exec command, when installed, will help you execute shell commands in parallel and in topological order. Exec 命令在安装后,将帮助您并行和按拓扑顺序执行 shell 命令。
  • 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. 运行命令,安装后,将帮助您并行和拓扑顺序运行 npm 脚本。
  • Watch command, when installed, will watch for changes within all packages and execute certain commands watch 命令在安装后将监视所有包中的更改并执行某些命令

getting Started 开始

Let's start by installing Lerna-Lite CLI as a dev dependency to your project and then run the init command to get started (see init#readme for all options). Note that the CLI must be installed at all time, then proceed by installing any other optional commands (the CLI is only including the init command), refer to the Installation table for more info. 让我们首先将 Lerna-Lite CLI 作为项目的开发依赖项安装,然后运行 init 命令以开始使用(有关所有选项,请参阅 init#readme)。请注意,必须始终安装 CLI,然后继续安装任何其他可选命令(CLI 仅包含 init 该命令),有关详细信息,请参阅安装表。

sh
# install Lerna-Lite CLI locally or globally (`init` is the only command installed)
$ 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
# install Lerna-Lite CLI locally or globally (`init` is the only command installed)
$ 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.json 配置文件和一个文件夹,因此您的 packages 文件夹现在应如下所示:

lerna-repo/
  packages/
    package-a
  package.json
  lerna.json
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. Also note that you can optionally add comments to your lerna.json config file since it is also able to parse JSON5 file format. 请注意,不会创建, package-a 此处显示它只是为了帮助阐明结构。有关 lerna.json 该文件的更多信息和完整详细信息,您可以阅读lerna.json Wiki。另请注意,您可以选择向 lerna.json 配置文件添加注释,因为它也可以解析 JSON5 文件格式。

Finally install the commands that are of interest to you (publish, version, run, exec, ...) 最后安装您感兴趣的命令( , , publishversionrun exec ...

$ npm i @lerna-lite/publish -D
$ npm i @lerna-lite/publish -D

Installation 安装

Lerna-Lite is entirely modular, as opposed to Lerna, and installing the CLI locally or globally will only provide you the init command. Please make sure to install other commands that you are interested in (see table below). Lerna-Lite 是完全模块化的,与Lerna相反,在本地或全局安装 CLI 只会为您提供 init 命令。请确保安装您感兴趣的其他命令(见下表)。

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"). 如果您不熟悉 Lerna-Lite,您还可以运行 lerna init 命令,该命令将以最少的设置为您创建。 lerna.json 如果使用 npm 以外的其他客户端,请确保更新 中的 npmClient lerna.json 属性(例如: "npmClient": "yarn""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. 注意 请确保您已创建配置文件 lerna.json 并使用固定或 independent 模式定义 version 属性。如果您缺少其中任何一个,则会引发错误。

JSON Schema JSON 架构

You can add the $schema property into your lerna.json to take advantage of Lerna-Lite JSON Schema (lerna init can help setting it up for you). This will help with the developer experience, users will be able to see what properties are valid with their types and a brief description of what each option does (descriptions are pulled from their associated lerna command options documentation). 您可以将属性添加到您的 $schema lerna.json 属性中以利用 Lerna-Lite JSON 模式( lerna init 可以帮助您设置它)。这将有助于开发人员体验,用户将能够看到哪些属性对其类型有效,以及每个选项的简要说明(描述从其关联的 lerna 命令选项文档中提取)。

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",
}
{
  "$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",
}

Separate / Optional Installs 单独/可选安装

Command 命令Install 安装Description 描述
☁️ publish ☁️ 发布npm i @lerna-lite/publish -Dpublish each workspace package 发布每个工作区包
📑 version 📑 版本npm i @lerna-lite/version -Dcreate new version for each workspace package 为每个工作区包创建新版本
🕜 changed 🕜 改变npm i @lerna-lite/changed -Dlist local packages changed since last release 列出自上一版本以来更改的本地包
🌓 diff 🌓 差异npm i @lerna-lite/diff -Dgit diff all packages since the last release git 差异自上一版本以来的所有软件包
👷 exec 👷 执行npm i @lerna-lite/exec -Dexecute an command in each workspace package 在每个工作区包中执行命令
📖 list 📖 列表npm i @lerna-lite/list -Dlist local packages 列出本地包
🏃 run 🏃 跑npm i @lerna-lite/run -Drun npm script in each workspace package 在每个工作区包中运行 npm 脚本
👓 watch 👓 看npm i @lerna-lite/watch -Dwatch for changes & execute commands when fired 触发时观察更改并执行命令

Note since the publish package depends on the version package, you could simply install @lerna-lite/publish to automatically gain access to both commands. 请注意, publish 由于包依赖于 version 包,因此您只需安装 @lerna-lite/publish 即可自动访问这两个命令。

Usage 用法

Add custom NPM scripts or simply run the commands in your shell with the Lerna-Lite CLI, you can see below some very basic script samples. 添加自定义 NPM 脚本或简单地使用 Lerna-Lite CLI 在 shell 中运行命令,您可以在下面看到一些非常基本的脚本示例。

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

Migration for existing Lerna users 现有 Lerna 用户的迁移

Migrating from Lerna, should be fairly easy to just replace Lerna with Lerna-Lite in your dependencies, then install the commands that you are interested in and that's about it. The CLI commands and options are the same, except that all commands are optional installs (that is the biggest difference with Lerna). Take a look at the steps shown below: 从 Lerna 迁移应该相当容易,只需在您的依赖项中将 Lerna 替换为 Lerna-Lite,然后安装您感兴趣的命令,仅此而已。CLI 命令和选项是相同的,除了所有命令都是可选安装(这是与 Lerna 的最大区别)。看看下面显示的步骤:

Note as opposed to Lerna v7 and higher, the useWorkspace is not enabled by default in Lerna-Lite and we still recommend to use either useWorkspaces for Yarn/NPM or use the default packages in lerna.json for pnpm users. The useWorkspaces has some drawback since some of the packages could be unrelated to the project releases (ie: website, examples) and for this use case the packages/* defined in lerna.json could be better (i.e. Jest uses this approach). 请注意,与 Lerna v7 及更高版本相反,在 Lerna-Lite 中默认不启用,我们仍然建议对 Yarn/NPM 使用, useWorkspace 或者对 pnpm 用户 useWorkspaces lerna.json 使用默认值 packages 。它 useWorkspaces 有一些缺点,因为某些包可能与项目发布无关(即:网站,示例),并且对于此用例, packages/* 定义的内容 lerna.json 可能会更好(即Jest使用此方法)。

  1. remove Lerna from your local & global dependencies 从本地和全局依赖项中删除 Lerna
npm uninstall lerna      # OR yarn remove lerna -W
npm uninstall -g lerna   # OR yarn global remove lerna
npm uninstall lerna      # OR yarn remove lerna -W
npm uninstall -g lerna   # OR yarn global remove lerna
  1. install Lerna-Lite CLI which will provide you, and only, the init command 安装 Lerna-Lite CLI,它将为您提供并且仅提供 init 命令
# Lerna CLI (includes `init`)
npm install @lerna-lite/cli -D
# Lerna CLI (includes `init`)
npm install @lerna-lite/cli -D
  1. finally install any of the optional Lerna-Lite command(s) that you wish to use (changed, diff, exec, list, run, publish, version and/or watch) refer to installation table above 最后安装任何您希望使用的可选 Lerna-Lite 命令( changed diff 、、 execlist run publish version 和/或 watch )请参阅上面的安装表
# install any of the optional commands (refer to installation table)
npm install @lerna-lite/publish -D
# install any of the optional commands (refer to installation table)
npm install @lerna-lite/publish -D
  1. review your lerna.json config file and remove any unrelated command options, for example bootstrap does not exist in Lerna-Lite so there's no need to keep that config 查看您的 lerna.json 配置文件并删除任何不相关的命令选项,例如 bootstrap Lerna-Lite 中不存在,因此无需保留该配置
{
    "npmClient": "yarn",
    "command": {
        "version": {
            "conventionalCommits": true
        },
-       "bootstrap": {
-           "npmClientArgs": ["--no-package-lock"]
-       }
    }
}
{
    "npmClient": "yarn",
    "command": {
        "version": {
            "conventionalCommits": true
        },
-       "bootstrap": {
-           "npmClientArgs": ["--no-package-lock"]
-       }
    }
}

Note after publishing your next release with conventional-changelog, you might see a lot of diff changes across your changelog.md files after switching to Lerna-Lite and that is totally expected since Lerna-Lite has code in place to remove empty lines that were added by Lerna for no reason. 请注意,在使用常规更改日志发布下一个版本后,切换到 Lerna-Lite 后,您可能会在 changelog.md 文件中看到很多差异更改,这完全是意料之中的,因为 Lerna-Lite 具有适当的代码来删除 Lerna 无缘无故添加的空行。

Lerna-Lite Full List of Packages Lerna-Lite 软件包的完整列表

Package Name 包名称Version 版本Description 描述Changes 变化
@lerna-lite/clinpmLerna-Lite CLI required to execute any command 执行任何命令所需的 Lerna-Lite CLIchangelog 更新日志
@lerna-lite/corenpmLerna-Lite core & shared methods (internal use) Lerna-Lite 核心和共享方法(内部使用)changelog 更新日志
@lerna-lite/initnpmSetup your monorepo to use Lerna-Lite 设置您的单存储库以使用 Lerna-Litechangelog 更新日志
@lerna-lite/publishnpmPublish packages in the current workspace 在当前工作区中发布包changelog 更新日志
@lerna-lite/versionnpmBump Version & write Changelogs 凹凸版本和写入更改日志changelog 更新日志
@lerna-lite/execnpmExecute shell command in current workspace 在当前工作区中执行 shell 命令changelog 更新日志
@lerna-lite/changednpmList local packages that changed since last release 列出自上次发布以来更改的本地包changelog 更新日志
@lerna-lite/diffnpmDiff all packages or a single package since last release 比较自上一版本以来的所有包或单个包changelog 更新日志
@lerna-lite/listnpmList local packages 列出本地包changelog 更新日志
@lerna-lite/listablenpmListable utils used by list and changed commands (internal use) 可 list 列出的实用程序和 changed 命令(内部使用)changelog 更新日志
@lerna-lite/filter-packagesnpmLerna-Lite filtering package utils used by optional commands (internal use) 可选命令使用的 Lerna-Lite 过滤包实用程序(内部使用)changelog 更新日志
@lerna-lite/profilernpmLerna-Lite Profiler used by some optional commands (internal use) Lerna-Lite Profiler 由一些可选命令使用(内部使用)changelog 更新日志
@lerna-lite/runnpmRun npm scripts in current workspace 在当前工作区中运行 npm 脚本changelog 更新日志
@lerna-lite/watchnpmWatch for changes within packages and execute commands 监视包中的更改并执行命令changelog 更新日志

Released under the MIT License.