npm 语义化发布_使用npm的语义版本控制

npm 语义化发布

If there’s one great thing in Node.js packages, is that all agreed on using Semantic Versioning for their version numbering.

如果Node.js软件包中有一件很棒的事情,那就是所有人都同意使用语义版本控制来为其版本编号。

The Semantic Versioning concept is simple: all versions have 3 digits: x.y.z.

语义版本控制的概念很简单:所有版本都有3位数字: xyz

  • the first digit is the major version

    第一位是主要版本
  • the second digit is the minor version

    第二个数字是次要版本
  • the third digit is the patch version

    第三位数是补丁版本

When you make a new release, you don’t just up a number as you please, but you have rules:

发布新版本时,您不仅可以随心所欲地增加数字,还可以遵循以下规则:

  • you up the major version when you make incompatible API changes

    当您进行不兼容的API更改时,您可以升级到主要版本
  • you up the minor version when you add functionality in a backward-compatible manner

    当您以向后兼容的方式添加功能时,您可以升级次要版本
  • you up the patch version when you make backward-compatible bug fixes

    进行向后兼容的错误修复时,您可以升级补丁程序版本

The convention is adopted all across programming languages, and it is very important that every npm package adheres to it, because the whole system depends on that.

该约定在所有编程语言中npm ,每个npm软件包都必须遵守该约定,因为整个系统都依赖npm ,这一点非常重要。

Why is that so important?

为什么这么重要?

Because npm set some rules we can use in the package.json file to choose which versions it can update our packages to, when we run npm update.

因为npm设置了一些规则,所以当我们运行npm update时,可以在package.json文件中使用它来选择将软件包更新到的npm update

The rules use those symbols:

规则使用这些符号:

  • ^

    ^

  • ~

    ~

  • >

    >

  • >=

    >=

  • <

    <

  • <=

    <=

  • =

    =

  • -

    -

  • ||

    ||

Let’s see those rules in detail:

让我们详细了解这些规则:

  • ^: if you write ^0.13.0 when running npm update it can update to patch and minor releases: 0.13.1, 0.14.0 and so on.

    ^ :如果你写^0.13.0运行时, npm update :它可以更新打补丁和次要版本0.13.10.14.0等等。

  • ~: if you write ~0.13.0, when running npm update it can update to patch releases: 0.13.1 is ok, but 0.14.0 is not.

    ~ :如果编写~0.13.0 ,则在运行npm update时可以更新到补丁程序版本: 0.13.1可以,但0.14.0不能。

  • >: you accept any version higher than the one you specify

    > :您接受比您指定的版本更高的任何版本

  • >=: you accept any version equal to or higher than the one you specify

    >= :您接受等于或高于您指定的版本的任何版本

  • <=: you accept any version equal or lower to the one you specify

    <= :您接受等于或低于您指定的版本的任何版本

  • <: you accept any version lower to the one you specify

    < :您接受低于指定版本的任何版本

  • =: you accept that exact version

    = :您接受该确切版本

  • -: you accept a range of versions. Example: 2.1.0 - 2.6.2

    - :您接受各种版本。 例如: 2.1.0 - 2.6.2

  • ||: you combine sets. Example: < 2.1 || > 2.6

    || :您组合套。 示例: < 2.1 || > 2.6 < 2.1 || > 2.6

You can combine some of those notations, for example use 1.0.0 || >=1.1.0 <1.2.0 to either use 1.0.0 or one release from 1.1.0 up, but lower than 1.2.0.

您可以合并其中的一些符号,例如,使用1.0.0 || >=1.1.0 <1.2.0 1.0.0 || >=1.1.0 <1.2.0 ,以使用1.0.0或从1.1.0起的一个发行版,但低于1.2.0。

There are other rules, too:

还有其他规则:

  • no symbol: you accept only that specific version you specify (1.2.1)

    无符号:您仅接受指定的特定版本( 1.2.1 )

  • latest: you want to use the latest version available

    latest :您想使用可用的最新版本

翻译自: https://flaviocopes.com/npm-semantic-versioning/

npm 语义化发布

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值