[转] 合理使用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版本了,因为版本已经更新了!

参考资料:

NPM模块的TAG管理

npm-dist-tag

npm-version

node-semver

猜你喜欢

转载自www.cnblogs.com/chris-oil/p/9046357.html
NPM
今日推荐