如何安装最新版本的 npm 包 [英] How to install the latest possible version of an npm package

查看:845
本文介绍了如何安装最新版本的 npm 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何安装 npm 包的最新可用版本?'@latest' 肯定不会获取最新的 - 我认为这意味着最新的稳定版或其他东西.

How do I install the latest available version of an npm package? '@latest' sure doesn't fetch the latest - I assume it means the latest stable or something.

我已经使用 hack 一段时间了,因为我似乎找不到任何关于此的信息:

I've been using a hack for a while because I cannot seem to find any info on this:

npm i extract-text-webpack-plugin@X 

X"导致它失败并转储所有可能的版本,然后我复制并粘贴正确的版本而不是X".有点可笑.

The 'X' causes it to fail and dump all possible versions where I then copy and paste the correct one instead of the 'X'. Kinda ridiculous.

我尝试过诸如最新版本"之类的 3rd 方软件包,但它们都无法获得最新版本.

I've tried 3rd party packages like 'latest-version' but they all fail to get the very latest version.

似乎没有官方这样做.例如,在撰写本文时,最新版本的 extract-text-webpack-plugin2.0.0-beta.4.但是这样做:

There doesn't seem to be an official to do this. For example at the time of writing the latest version of extract-text-webpack-plugin is 2.0.0-beta.4. However doing:

npm i extract-text-webpack-plugin@latest

将安装'1.0.1'

我可以通过执行查看最新版本

I can see the latest version by doing

npm info pkg versions --json (without --json it will cut off when there are many versions)

由于缺乏实际的工具,我想这将是一些 grep 工作.

For lack of an actual tool I guess its going to be some grep work.

推荐答案

Version 1.0.1 是该包的最新"版本 - 至少发布到 npm 注册表(标记latest)

来自 cli/dist-tag.强调我的.

From the docs for cli/dist-tag. Emphasis mine.

标签可用于提供别名而不是版本号.

Tags can be used to provide an alias instead of version numbers.

例如,一个项目可能会选择有多个开发流,并为每个流使用不同的标签,例如稳定版、测试版、开发版、金丝雀.

For example, a project might choose to have multiple streams of development and use a different tag for each stream, e.g., stable, beta, dev, canary.

默认情况下,npm 使用 latest 标签来标识包的当前版本,并且 npm install(不带任何 @ 或 @ 说明符)安装最新的标签.通常,项目仅对稳定发布版本使用最新标签,而对不稳定版本(如预发布)使用其他标签.

By default, the latest tag is used by npm to identify the current version of a package, and npm install (without any @ or @ specifier) installs the latest tag. Typically, projects only use the latest tag for stable release versions, and use other tags for unstable versions such as prereleases.

默认情况下,除了最新的,没有标签对 npm 本身有任何特殊意义.

By default, other than latest, no tag has any special significance to npm itself.

如果您想要测试版,请从 GitHub 安装,或明确使用标签.

If you want the beta releases, then install from GitHub, or use the tags explicitly.

$ npm install webpack/extract-text-webpack-plugin

通过阅读手册可以清楚地说明这一点.

更清楚:

latest 是一个隐式标签,附加到显式发布的包的任何已发布版本em> 标签 (--tag).

latest is an implicit tag, attached to any published version of a package that was not published with an explicit tag (--tag).

安装xyz@latest 只需在注册表中查找标记latest 的版本.对于这个包,它是 1.0.1 版本.就是这样.这里没有什么特别的.@latest 不会拉取发布到 npm

Installing xyz@latest simply looks up the release tagged as latest in the registry. In the case of this package, that's release 1.0.1. That's it. There's nothing special going on here. @latest does not pull the most recent version published to npm

列为测试版的版本标记不同.显然,它们都没有被标记为 latest,所以尝试使用 @latest 来获取一个是没有意义的.

The versions listed as betas were tagged differently. Obviously none of them were tagged as latest, so trying to use @latest to get one is pointless.

来自注册表:

'dist-tags': { latest: '1.0.1', beta: '2.0.0-beta.4' }

同样,使用 GitHub 版本获取前沿信息,或明确使用版本/标签.

Again, use the GitHub releases for the bleeding edge, or use the versions/tags explicitly.

$ npm install extract-text-webpack-plugin@beta

给你,专为你设计:

把它压缩成一个 shell 脚本,你就可以开始了:

Condense this into a shell script, and you're good to go:

$ npm install extract-text-webpack-plugin@$(recent-version extract-text-webpack-plugin)

这篇关于如何安装最新版本的 npm 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆