你可以在github上閱讀本文。
關於npm version prerelease的作用我這裏不再贅述,你可以查看這個文章。我只是記錄一下關於npm version與npm dist-tag的使用:
第一步:發佈第一個穩定版本
npm publish//1.0.0
第二步:修改文件繼續發佈第二個版本
git add -A && git commit -m "c"
npm version patch
npm publish//1.0.1
第三步:繼續修改文件發佈一個prerelease版本
git add -A && git commit -m "c"
npm version prerelease
npm publish --tag -beta//版本[email protected]
第四步:繼續修改發佈第二個prerelease版本
git add -A && git commit -m "c"
npm version prerelease
npm publish --tag -beta//版本[email protected]
第五步:npm info查看我們的版本信息
{ name: 'n-n-n-n',
'dist-tags': { latest: '1.0.1', '-beta': '1.0.2-1' },
versions: [ '1.0.0', '1.0.1', '1.0.2-0', '1.0.2-1' ],
maintainers: [ 'liangklfang <[email protected]>' ],
time:
{ modified: '2017-04-01T12:17:56.755Z',
created: '2017-04-01T12:15:23.605Z',
'1.0.0': '2017-04-01T12:15:23.605Z',
'1.0.1': '2017-04-01T12:16:24.916Z',
'1.0.2-0': '2017-04-01T12:17:23.354Z',
'1.0.2-1': '2017-04-01T12:17:56.755Z' },
homepage: 'https://github.com/liangklfang/n#readme',
repository: { type: 'git', url: 'git+https://github.com/liangklfang/n.git' },
bugs: { url: 'https://github.com/liangklfang/n/issues' },
license: 'ISC',
readmeFilename: 'README.md',
version: '1.0.1',
description: '',
main: 'index.js',
scripts: { test: 'echo "Error: no test specified" && exit 1' },
author: '',
gitHead: '8123b8addf6fed83c4c5edead1dc2614241a4479',
dist:
{ shasum: 'a60d8b02222e4cae74e91b69b316a5b173d2ac9d',
tarball: 'https://registry.npmjs.org/n-n-n-n/-/n-n-n-n-1.0.1.tgz' },
directories: {} }
我們只要注意下面者兩個部分:
'dist-tags': { latest: '1.0.1', '-beta': '1.0.2-1' },
versions: [ '1.0.0', '1.0.1', '1.0.2-0', '1.0.2-1' ],
其中最新的穩定版本和最新的beta版本可以在dist-tags中看到,而versions數組中存儲的是所有的版本。
第六步:npm dist-tag命令
npm dist-tag ls n-n-n-n
即npm dist-tag獲取到所有的最新的版本,包括prerelease與穩定版本,得到下面結果:
-beta: 1.0.2-1
latest: 1.0.1
第七步:當我們的prerelease版本已經穩定了,重新設置爲穩定版本
npm dist-tag add n-n-n-n@1.0.2-1 latest
此時你通過npm info查看可以知道:
{ name: 'n-n-n-n',
'dist-tags': { latest: '1.0.2-1', '-beta': '1.0.2-1' },
versions: [ '1.0.0', '1.0.1', '1.0.2-0', '1.0.2-1' ],
maintainers: [ 'liangklfang <[email protected]>' ],
time:
{ modified: '2017-04-01T12:24:55.800Z',
created: '2017-04-01T12:15:23.605Z',
'1.0.0': '2017-04-01T12:15:23.605Z',
'1.0.1': '2017-04-01T12:16:24.916Z',
'1.0.2-0': '2017-04-01T12:17:23.354Z',
'1.0.2-1': '2017-04-01T12:17:56.755Z' },
homepage: 'https://github.com/liangklfang/n#readme',
repository: { type: 'git', url: 'git+https://github.com/liangklfang/n.git' },
bugs: { url: 'https://github.com/liangklfang/n/issues' },
license: 'ISC',
readmeFilename: 'README.md',
version: '1.0.2-1',
description: '',
main: 'index.js',
scripts: { test: 'echo "Error: no test specified" && exit 1' },
author: '',
gitHead: '03189d2cc61604aa05f4b93e429d3caa3b637f8c',
dist:
{ shasum: '41ea170a6b155c8d61658cd4c309f0d5d1b12ced',
tarball: 'https://registry.npmjs.org/n-n-n-n/-/n-n-n-n-1.0.2-1.tgz' },
directories: {} }
主要關注如下:
'dist-tags': { latest: '1.0.2-1', '-beta': '1.0.2-1' },
versions: [ '1.0.0', '1.0.1', '1.0.2-0', '1.0.2-1' ]
此時latest版本已經是prerelease版本”1.0.2-1”了!此時用戶如果直接運行npm install就會安裝我們的prerelease版本了,因爲版本已經更新了!
參考資料: