虽然 -alpha 和 -beta 是常见的预发布标签,但它们不是由 SemVer 定义的。 -alpha.1、-alpha.2、-beta.1 等也相当常见。该规范将预发布标签定义为一系列点分隔的字母数字或数字字符字段。 SemVer 规范在某些示例中使用了 alpha 和 beta,但规范没有定义它们。如果你不告诉它,NPM 无法知道你想使用什么标签。它显然默认为数字预发布标签,这是有道理的,因为 SemVer 允许(-1、-2、-3 提供所有必要的语义)。
NPM 文档很烂,幸运的是我从来不用 NPM。见https://docs.npmjs.com/cli/version。特别是:
newversion 参数应该是有效的 semver 字符串、semver.inc 的有效第二个参数(patch、minor、major、prepatch、preminor、premajor、prerelease 之一)或 from-git。
查看提供的链接(https://github.com/npm/node-semver#functions),他们似乎指的是增加指定的版本字段。在 package.json 文件中版本字符串上没有 alpha 标记的情况下,将缺少的数字预发布标记附加为 -1 是很有意义的。
我刚刚测试了这个理论:
> echo Test > test.txt
> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (packageTest)
version: (1.0.0) 0.1.0-alpha.0
description: Test package.
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to D:\TMP\Joseph\packageTest\package.json:
{
"name": "packageTest",
"version": "0.1.0-alpha.0",
"description": "Test package.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes)
> npm version prerelease
v0.1.0-alpha.1
> cat package.json
{
"name": "packageTest",
"version": "0.1.0-alpha.1",
"description": "Test package.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
正如预期的那样。