lerna version主要的工作为标识出在上一个 tag 版本以来更新的 monorepo package,然后为这些包 prompt 出版本,在用户完成选择之后修改相关包的版本信息并且将相关的变动 commit 然后打上 tag 推送到 git remote

1.设置属性configProperties
这一部分比较简单,主要是检查一些传进来的参数是否符合规范

--conventional-commit:按照常规提交规范自动生成 package version。
fix类型提交转换为PATCH发行版。feat类型提交转换为MINOR发行版。BREAKING CHANGE无论类型如何,提交中的提交都应转换为MAJOR发行版。
--create-release:使用此标志运行时,lerna version将基于更改的包建立正式的GitHub或GitLab版本
2.初始化initialize

git相关的检验
具体的检验逻辑:
校验本地是否有没有被commit内容
判断当前的分支是否正常
判断当前分支是否在remote存在
判断当前分支是否在lerna.json允许的 allowBranch设置之中
判断当前分支提交是否落后于remote
收集更新包

而collectUpdates函数的主要逻辑如下:

执行 runLifeCycle 函数
这一步就是用于执行 lerna.json 里面用户设置的一些生命周期函数次

构建tasks队列并执行

任务1:获得需要更新的 version

任务2:设置version

任务3:确认更新

3.执行命令execute


更新包的版本
更新包的package.json版本号
跟pkg有关的依赖也一起更新
更新pkg-lock.json

通过git add 将上述修改提交到缓存区

将上述add到缓存区的内容commit并打上tag

push到远程

参考引用:https://juejin.cn/post/6935765350067732516
网友评论