2021-09-09 Lerna

2021-09-09  本文已影响0人  FConfidence

lerna bootstrap

默认是npm i,因为我们指定过yarn,so,run yarn install,会把所有包的依赖安装到根node_modules.

lerna list

列出所有的包,如果与你文夹里面的不符,进入那个包运行yarn init -y解决

lerna diff [package?]

列出所有或者软件包自上次发布以来的修改情况

lerna import <path-to-external-repository>

导入本地已经存在的包

lerna add packageName --scope=workspacePackageName

lerna add lodash --scope=my-component

lerna run

运行npm script,可以指定具体的package。

lerna run <script> -- [..args] # 运行所有包里面的有这个script的命令
$ lerna run --scope my-component test

$ lerna run <script> -- [..args] # 在所有包下运行指定

# 例如
$ lerna run test # 运行所有包的 test 命令
$ lerna run build # 运行所有包的 build 命令
$ lerna run --parallel watch # 观看所有包并在更改时发报,流式处理前缀输出

$ lerna run --scope my-component test # 运行 my-component 模块下的 test

lerna exec

运行任意命令在每个包

$ lerna exec -- < command > [..args] # runs the command in all packages
$ lerna exec -- rm -rf ./node_modules
$ lerna exec -- protractor conf.js
lerna exec --scope my-component -- ls -la

lerna link

项目包建立软链,类似npm link

lerna clean

删除所有包的node_modules目录

lerna changed

列出下次发版lerna publish 要更新的包。

原理:
需要先git add,git commit 提交。
然后内部会运行git diff --name-only v版本号 ,搜集改动的包,就是下次要发布的。并不是网上人说的所有包都是同一个版全发布。

如果forcePublish为true 那么所有的包都会change发布
 "command": {
    "version": {
      "forcePublish": true
    },
 }

lerna publish

会打tag,上传git,上传npm。
如果你的包名是带scope的例如:"name": "@gp0320/gpwebpack",
那需要在packages.json添加

"publishConfig": {
  "access": "public"
},

提交对项目的更新

运行该命令会执行如下的步骤:

  1. 运行lerna updated来决定哪一个包需要被publish
  2. 如果有必要,将会更新lerna.json中的version
  3. 将所有更新过的的包中的package.json的version字段更新
  4. 将所有更新过的包中的依赖更新
  5. 为新版本创建一个git commit或tag
  6. 将包publish到npm上
$ lerna publish  用于发布更新 
$ lerna publish --skip-git     # 不会创建git commit或tag 
$ lerna publish --skip-npm   # 不会把包publish到npm上 |

lerna ls

显示packages下的各个package的version

lerna publish 相关参数

lerna publish [--dist-tag=tag名]

image.png

如图所示,控制台会让用户选择要发版的版本号(最后一个可以自定义)

dist-tag选项可以发版一个其他分支的包,在测试时比较有用!

image.png

测试时可以发布一个beta版(--dist-tag=beta),通过手动@版本号安装(npm install 默认安装latest)

参考

http://www.sosout.com/2018/07/21/lerna-repo.html

https://www.bilibili.com/read/cv4948266

上一篇 下一篇

猜你喜欢

热点阅读