如何通过npm安装“latest”版本

huangapple go评论53阅读模式
英文:

How can I install "latest" via npm

问题

当我使用以下命令时(foo 仅为示例)

npm install foo@latest --save

并且 foo 的最新版本是 16.3.1 时,添加到 package.json 的行是

"foo": "~16.3.1",

如何使其实际添加字符串 "latest",就像这样

"foo": "latest",

注意:让我们避免讨论依赖管理,只是看看这是否在技术上可行。

英文:

When I use the following command (foo is example-only)

npm install foo@latest --save

and the latest version of foo is 16.3.1, then the line that is added to package.json is

"foo": "~16.3.1",

How can I make it actually add the string "latest", like this

"foo": "latest",

Note: Let’s avoid discussion about dependency management, just looking to see if this is technically possible.

答案1

得分: 1

"latest" 总是检索 NPM 中最新可用的版本。因此,在撰写本文时,最新版本为 16.3.1,但例如,每当包在以后的某个时刻更新为 16.3.2,"latest" 值将下载 16.3.2,以此类推。

如果您始终希望在执行 "npm i" 时获取最新版本,您应该使用 "latest" 值;如果您想要一个特定版本(我建议这样做,因为您可以测试当前可用版本,但无法测试将来可用版本),您应该使用静态版本(例如 16.3.1)。

英文:

Defining "latest" always retrieves the latest available version from NPM. So at this time of writing the latest version is 16.3.1 but for example whenever the package gets updated at a later point to 16.3.2 the "latest" value will download 16.3.2 and so on.

If you always want the latest version at the time of "npm i" you should use the "latest" value, if you want a specific version (which I recommend since you can test the current available version but not the future available version) you should use a static version (e.g. 16.3.1)

答案2

得分: 0

没有自动将其设置为最新版本的方法,但您可以手动将其设置为“latest”。
但将其设置为“latest”会被视为不良实践。通常情况下,您不会在依赖项中更改这些内容,因为这是自动完成的。
所以最好将其保持原样。

英文:

There is no way to set it to latest automatically, but you can set it to "latest" manually.
But setting it to "latest" would be considered bad practice. You usually dont change this stuff in the dependencies, because its done automatically.
So it's better to just keep it the way it is.

huangapple
  • 本文由 发表于 2023年7月12日 20:47:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定