简体   繁体   English

如何安装npm软件包的最新可能版本

[英]How to install the latest possible version of an npm package

How do I install the latest available version of an npm package? 如何安装npm软件包的最新可用版本? '@latest' sure doesn't fetch the latest - I assume it means the latest stable or something. '@latest'肯定不会获取最新的-我认为这意味着最新的马stable之类的东西。

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 

The 'X' causes it to fail and dump all possible versions where I then copy and paste the correct one instead of the 'X'. “ X”导致它失败并转储所有可能的版本,然后在其中复制并粘贴正确的版本而不是“ X”。 Kinda ridiculous. 有点可笑。

I've tried 3rd party packages like 'latest-version' but they all fail to get the very latest version. 我尝试了“最新版本”之类的第三方软件包,但它们都未能获得最新版本。

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 . 例如,在撰写本文时, extract-text-webpack-plugin的最新版本是2.0.0-beta.4 However doing: 但是这样做:

npm i extract-text-webpack-plugin@latest

Will install '1.0.1' 将安装“ 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)

For lack of an actual tool I guess its going to be some grep work. 由于缺乏实际的工具,我想这将是一些grep的工作。

Version 1.0.1 is the 'latest' version of that package - published to the npm registry at least ( tagged as latest ) 版本1.0.1 该软件包的“最新”版本-至少发布到npm注册表( 标记latest

From the docs for cli/dist-tag . 来自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, eg, stable, beta, dev, canary. 例如,一个项目可能选择具有多个开发流,并为每个流使用不同的标签,例如稳定版,beta版,dev版,canary版。

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. 默认情况下,npm使用最新标签来标识软件包的当前版本,npm install(不带任何@或@指定符)将安装最新标签。 Typically, projects only use the latest tag for stable release versions, and use other tags for unstable versions such as prereleases . 通常,项目仅将最新标签用于稳定版本,而将其他标签用于不稳定版本,例如prereleases

By default, other than latest, no tag has any special significance to npm itself. 默认情况下,除了最新的标签外,没有标签对npm本身有特殊的意义。

If you want the beta releases , then install from GitHub, or use the tags explicitly. 如果需要beta版本 ,请从GitHub安装,或显式使用标记。

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

This is made pretty clear by reading the manual. 通过阅读手册可以很清楚地看出这一点

Even more clear: 更明确的是:

latest is an implicit tag, attached to any published version of a package that was not published with an explicit tag ( --tag ). latest隐式标签,它附加到使用显式标签( --tag )发布的任何发行版软件包中。

Installing xyz@latest simply looks up the release tagged as latest in the registry. 安装xyz@latest只是在注册表中查找标记latest的发行版。 In the case of this package, that's release 1.0.1 . 对于此软件包,版本为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不会将最新版本发布到npm

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. 显然,它们都没有被标记为latest ,因此尝试使用@latest来获取一个是毫无意义的。

From the registry: 从注册表中:

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

Again, use the GitHub releases for the bleeding edge, or use the versions/tags explicitly. 同样,使用GitHub发行版来实现最新功能,或显式使用版本/标记。

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

Here you go, made especially for you: 这是为您量身定制的:

Condense this into a shell script, and you're good to go: 将其压缩到一个shell脚本中,您就可以开始了:

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

只要已安装软件包,请使用npm update

npm update <package>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM