如何使用npm版本控制将package.json版本包含在-alpha中.
运行npm版本 将碰撞package.js文件的版本,但我想将-alpha postfix添加到版本,但我无法,因为它没有在文档中说明,但它由semver本身支持.
实际结果:
> npm version prerelease
> v0.2.1-1
预期结果:
> v0.2.1-alpha
最佳答案 虽然-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.特别是:
The newversion argument should be a valid semver string, a valid second argument to 07001 (one of patch, minor, major, prepatch, preminor, premajor, prerelease), or 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"
}
正如所料.