简体   繁体   English

“ npm init”并使用非标准标准

[英]“npm init” and using non-semver standards

When creating a new node.js project, the following is run first: 创建新的node.js项目时,首先运行以下命令:

npm init

And there is a series of questions that will help initialize the package.json file. 还有一系列问题将有助于初始化package.json文件。 One of those questions is about version . 这些问题之一是关于version

The version number that is supplied as an answer should strictly follow the semver standard. 作为答案提供的版本号应严格遵循semver标准。 Now, what if I would like to use a different versioning standard that does not adhere to semver? 现在,如果我想使用不遵循semver的其他版本控制标准怎么办? How to enforce using different version standard? 如何使用不同的版本标准执行? Can I also supply the new rules for the new standard to be used instead of semver to enforce the new versioning standard? 我是否也可以提供要使用的新标准的新规则,而不是使用semver来实施新的版本控制标准?

Thanks. 谢谢。

You should never violate the contracts that are inherent in using a particular packaging/distribution tool. 您绝不应该违反使用特定包装/分发工具所固有的合同。 In this case, npm require SemVer because it provides a useful communications channel between publishers and consumers that is easily automated. 在这种情况下,npm需要SemVer,因为它在发布者和消费者之间提供了一个易于自动化的有用的通信渠道。 Since your versioning scheme makes no distinction between bug fixes, new features and breaking changes, the best that you can do is apply a mapping from it onto SemVer, if you must use npm as your packaging scheme. 由于版本控制方案在错误修复,新功能和重大更改之间没有区别,因此,如果必须使用npm作为打包方案,则最好的办法是将其映射到SemVer。 There's two ways I can think of to accomplish this. 我可以通过两种方法来实现这一目标。

  1. Use 0.0.1 for all versions and append a -prerelease that contains your actual sequential version. 对所有版本使用0.0.1,并附加包含实际序列版本的-prerelease。 These will sort as you expect them to do provided each of the dotted prerelease fields is pure numeric and they will always be legal in terms of semantic versioning. 只要每个点缀的预发行字段都是纯数字,它们就会按照您的期望进行排序,并且就语义版本而言它们始终是合法的。
  2. User 0.0.X, where X is the most significant field of your versioning scheme and you place the remaining values in the -prerelease tag as pure numeric doted fields. 用户0.0.X,其中X是版本控制方案中最重要的字段,您将其余值作为纯数字变量字段放置在-prerelease标记中。

Either of these schemes is legal SemVer and announces to all consumers that any new version is potentially a breaking change. 这些方案中的任何一个都是合法的SemVer,并向所有消费者宣布任何新版本都可能是一项重大更改。 The 0.0 prefix in SemVer essentially means all bets are off. SemVer中的0.0前缀本质上意味着所有投注均关闭。 This way, consumers willing to accept risk can automatically update to your latest version and those who are unwilling to accept such risks can avoid them. 这样,愿意接受风险的消费者可以自动更新到您的最新版本,而那些不愿意接受此类风险的消费者可以避免使用。

Examples based on your comments: 根据您的评论的示例:

0.0.1-2018.01
0.0.1-2018.02
0.0.1-2019.03

0.0.2018-01
0.0.2018-02
0.0.2019-03

After providing examples above, I personally prefer the second variation over the first one, but as far as the SemVer rules are concerned, they are literally equal. 在提供了上述示例之后,我个人更喜欢第二个版本而不是第一个版本,但是就SemVer规则而言,它们实际上是相等的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM