lerna development process (entry and exit)

Lerna common api summary:

lerna bootstrap install dependencies
clay clean Delete node_modules under each package
clay init Create new lerna library
clay art show package list
the clay changed Show packages that have been modified since the last relase tag, option pass list
clay diff Show the differences of packages that have been modified since the last relase tag, execute git diff
lerna exec

Execute arbitrary commands in each package directory

the clay run Execute the script commands in each package's package.json

clay add

Add a package version as a dependency of each package
clay imports import package
lerna link Link libraries that reference each other
lerna create New package
lerna publish release

Note: You can use lerna [command] -h to find the usage and parameters of a single command

lerna bootstrap 

Executing this command will do the following four things:

  1. Install dependencies for each package
  2. Link interdependent libraries into specific directories
  3. Execute npm run prepublish
  4. Execute npm run prepare

The parameters are as follows

-- --production --no-optional Specify the parameters of the npm client  

--hoist

Install dependencies to node_modules in the root directory  

--ignore

ignored packets --ignore test-* ignore packages whose name starts with test
--scope  specified package The meaning of the parameter refers to the name of the package

--ignore-scripts

Does not execute lifecycle script commands, such as prepare  

--registry <url>

Specified registry  

--npm-client

Specify the npm client for installation yarn bootstrap --npm-client=yarn

--use-workspace

Use yarn workspace, never used  

--night

Call npm ci by default instead of npm install , use options to modify settings npm ci Similar  npm-install , but it is intended for use in automated environments such as testbenches, continuous integration and deployment.
--skip-git No git commit or tag will be created  
--skip-npm will not publish the package to npm  
--canary Can be used to release each commit independently without tag lerna publish --canary

Remarks: npm ci will delete the node_modules folder, and there must be a package-lock.json file

——————————————————————————————————————————————————

lerna list lists the packages contained in the current lerna library

 

--json

Displayed in json format  

--all

Show packages containing private  

--long

Show more extended information  

——————————————————————————————

the clay changed

Show packages that have been modified since the last relase tag, option pass list

——————————————————————————————————————————————————

clay diff

Show the differences of packages that have been modified since the last relase tag, execute git diff

——————————————————————————————————————————————————

lerna exec

Execute arbitrary commands in each package directory

--concurrency

The default command is executed in parallel, we can set the concurrency to 1 (global parameter) lerna exec --concurrency 1 -- ls -la

--scope

Set the included package lerna exec --scope my-component -- ls -la

--stream

Cross-parallel output results lerna exec --stream -- babel src -d lib

--parallel

 Execute command with unlimited concurrency, streaming prefixed output.  

--no-bail

Continue executing command despite non-zero exit in a given package.  

lerna run option 同lerna exec

执行每个包package.json中的脚本命令

——————————————————————————————————————————————————

lerna init  

创建一个新的lerna库或者是更新lerna版本

默认lerna有两种管理模式, 固定模式和独立模式

  • 固定模式  --exact

固定模式,通过lerna.json的版本进行版本管理。当你执行lerna publish命令时, 如果距离上次发布只修改了一个模块,将会更新对应模块的版本到新的版本号,然后你可以只发布修改的库。

这种模式也是Babel使用的方式。如果你希望所有的版本一起变更, 可以更新minor版本号,这样会导致所有的模块都更新版本。

  • 独立模式 --independent

独立模式,init的时候需要设置选项 --independent. 独立模式允许管理者对每个库单独改变版本号,每次发布的时候,你需要为每个改动的库指定版本号。这种情况下, lerna.json的版本号不会变化了, 默认为independent

——————————————————————————————————————————————————

lerna clean

删除各个包下的node_modules

——————————————————————————————————————————————————

lerna import

导入指定git仓库的包作为lerna管理的包

--flatten

如果有merge冲突, 用户可以使用这个选项所谓单独的commit lerna import ~/Product --flatten

--dest

可以指定导入的目录(lerna.json中设定的目录) lerna import ~/Product --dest=utilities

lerna add

添加一个包的版本为各个包的依赖

lerna add <package>[@version] [--dev] [--exact]

lerna link

链接互相引用的库

——————————————————————————————————————————————————

lerna create

新建包

——————————————————————————————————————————————————

lerna.json解析

{
  "version": "1.1.3",
  "npmClient": "npm",
  "command": {
    "publish": {
      "ignoreChanges": [
        "ignored-file",
        "*.md"
      ],
      "allowBranch": ["master", "feature/*"]
    },
    "bootstrap": {
      "ignore": "component-*",
      "npmClientArgs": ["--no-package-lock"]      
    }
  },
  "packages": ["packages/*"]
}

 

lerna发布相关

1,lerna publish做哪些事情

  • 运行lerna updated来决定哪一个包需要被publish
  • 如果有必要,将会更新lerna.json中的version
  • 将所有更新过的的包中的package.json的version字段更新
  • 将所有更新过的包中的依赖更新
  • 为新版本创建一个git commit或tag
  • 将包publish到npm上

2, lerna publish发布失败后怎样操作,如下:采用 from-package

Positionals

bump from-git

In addition to the semver keywords supported by lerna versionlerna publish also supports the from-git keyword. This will identify packages tagged by lerna version and publish them to npm. This is useful in CI scenarios where you wish to manually increment versions, but have the package contents themselves consistently published by an automated process.

bump from-package

Similar to the from-git keyword except the list of packages to publish is determined by inspecting each package.json and determining if any package version is not present in the registry. Any versions not present in the registry will be published. This is useful when a previous lerna publish failed to publish all packages to the registry.

具体参见:https://github.com/lerna/lerna/tree/master/commands/publish#readme

3,  symlink 的问题

如果我们的package中有webpack,那么其中的loader很有可能会出问题

假设 package 下面有一个包 pkg1 ,依赖 package 下面的另一个包 pkg2 。
运行 lerna bootstrap 之后, pkg1/node_modules 下就会出现 pkg2 的 symlink 。

我们遇到的问题是在pkg2中有一个TS文件,export出去。pkg1中去引入,但是发现总是没有命中真实的loader。

如果使用 webpack 系列工具来编译运行 pkg1 ,由于 webpack loader 判断路径默认是按照真实路径来的,所以 pkg2 对应到的路径是 [project root]/package/pkg2 ,而不是 [project root]/package/pkg1/node_modules/pkg2

这样一来,如果需要 pkg2 中的源码过 pkg1 的 loader (比如 pkg2 中的 TS 通过 pkg1 的 ts-loader),就需要特殊配置。这和不涉及 symlink 的真实场景存在较大差异。
同时,很多配置(比如 postcssrc 、 babelrc 、 eslintrc 等)是以 resolve 到的文件去解析的。

所以此时其实很希望 webpack loader 基于 symlink 的路径去解析判断 include / exclude 等配置,而不是按照真实文件的路径。

所以需要配置webpack 的 resolve.symlinks 来解决这个问题,具体参见官方文档

4,指定cnpm源无效

gitlab issue publish时不接受参数,只能使用npm仓库。
但是旧版本 2.x 的支持,本人测试,截止到3.3.2,3.x的lerna指定cnpm源publish均无效。

 


参考:https://www.jianshu.com/p/2f9c05b119c9

https://www.jianshu.com/p/8b7e6025354b

 

Guess you like

Origin blog.csdn.net/qdmoment/article/details/95629850