git - npm 使用 git 信息而不是 package.json 中的版本发布

标签 git npm continuous-integration npm-publish

我正在尝试根据 git 信息找到发布 npm 工件的解决方案。

我查看了 npm versionrelease-it ,但是这些工具会自动执行 git 操作(提交/推送)以在 npm artefact 版本和 git 之间建立链接,它不会从 git 获取信息。

我想发布 npm artefact,其来源带有 git 标识,类似于 git describe --tags --always 的结果。 像这样可以轻松地建立 git/npm 之间的链接,唯一的 git 操作是标记,持续集成管道可以通过 npm publish 发布工件。

git-tag-version似乎是工作的一部分,但没有与人工制品版本建立联系。

我可能会尝试这样做,但也许 npm 中有一些功能可以更轻松地做到这一点?

最佳答案

npm version from-git 似乎离我喜欢做的不远,除了:

  • 它需要一个带注释的标签
  • 它提交更新的 package.json
  • 它没有不同的标识,但最新的标签保持不变

所以最后我使用了:

npm config set git-tag-version=false 
npm version $(git describe --tags)
npm publish

这不会提交包 json 修改并允许使用轻量级标签

关于git - npm 使用 git 信息而不是 package.json 中的版本发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57380839/

相关文章:

git - 使用 Tag 还是 Branch 更好?

git - 如何使用 git 撤消推送的提交?

linux - 找不到npm命令 'serve ',尽管已安装

node.js - 无法在 Node 12.7 中安装 LDAP

continuous-integration - 如何将构建复制到测试服务器?

macos - 如何取消我的计算机与 github 帐户的链接?

git log origin/master..HEAD 但包括 origin/master 本身

javascript - 使用 `react-bootstrap` 和 `npm`

ssh - 允许 CI 访问私有(private) BitBucket 存储库

continuous-integration - 在提交之前如何自动化或促进多平台构建/测试?