问题描述
我的 package.json 文件中有一个 npm 包
I have a npm package in my package.json file
"clean-webpack-plugin": "^0.1.18"
现在当我将鼠标悬停在包上时,我可以看到有一个更新的版本
Now when I hover over the package I can see that there is a newer version
"clean-webpack-plugin": "^0.1.19"
现在,据我所知,我可以例如执行 npm update
来更新所有遵守 semver 规则的包,或者只更新包 npm update clean-webpack-plugin
.
Now, as I understood, I could for example do npm update
to update all packages obeying the semver rules or just the package npm update clean-webpack-plugin
.
所以插入符号 ^
应该意味着,如果可用,您可以将包更新到版本 0.9.9
,对吗?
So the caret ^
symbol should mean, that you could possibly update the packge to version 0.9.9
if available, right?
npm update
没有效果,这就是我问的原因.
npm update
has no effect, that's why I ask.
推荐答案
我很确定 npm 会更新 clean-webpack-plugin
from version 0.1.18
to version 0.1.19
运行后:npm update clean-webpack-plugin
as在您的问题中描述.
I'm quite certain that npm will have updated the application files for clean-webpack-plugin
from version 0.1.18
to version 0.1.19
after you run: npm update clean-webpack-plugin
as described in your question.
但是,npm 不会更新您的 package.json
中的条目,因为理论上实际上没有必要这样做.为什么?...因为版本 "^0.1.18"
在 package.json
中指定.IE.版本用脱字符 ^
符号指定.
However, npm will not have updated the entry in your package.json
as theoretically it's not actually necessary to do so. Why?.. because version "^0.1.18"
is specified in package.json
. I.e. The version is specified with the caret ^
symbol.
假设您要使用 package.json
中指定的 ^0.1.18
发布您的项目,然后运行 npm install
的任何后续用户都将实际上获得版本 0.1.19
无论如何(警告:因为 clean-webpack-plugin
的版本历史记录在撰写本文时目前位于 npm 存储库中).
Let's say your were to publish your project with ^0.1.18
specified in package.json
then any subsequent user running npm install
will actually get version 0.1.19
anyway (caveat: as the version history for clean-webpack-plugin
currently stands in the npm repository at the time of writing this).
所以,简而言之,我很确定您的系统上已经安装了 0.1.19
版本,它只是没有更改 package.json
.实际上没有必要这样做,并且仍然遵守 semver 规则和插入符号的使用.
So, in short I'm quite sure that version 0.1.19
has been installed on your system, it simply hasn't changed the version specified in package.json
. It's not actually necessary to do so and the rules of semver and the use of the caret symbol are still being respected.
所以插入符号 ^
应该意味着,如果可用,您可以将包更新到版本 0.9.9
,对吗?
"^0.1.18"
中的插入符号对 npm 说我将接受对最新 次要 版本,但我不会接受主要更新.IE.^0.1.18
表示>=0.1.18 范围内的任何更新(该范围内的PATCH更新也是允许的).
The caret in "^0.1.18"
is saying to npm I WILL accept any updates to the most recent MINOR version but I WILL NOT accept a MAJOR update. I.e. ^0.1.18
means any updates in the range >=0.1.18 <1.0.0
(PATCH updates within that range are allowed too).
验证是否已更新:
要验证是否已实际安装0.1.19
版本,您可以cd
到您的项目目录并运行:
To verify whether version 0.1.19
has actually been installed you can cd
to your project directory and run:
npm ls clean-webpack-plugin
您应该会看到以下记录到您的控制台:
You should see the following logged to your console:
...
└── [email protected]
但我希望 package.json
在运行 npm update
后显示 "^0.1.19"
:
But I want package.json
to show "^0.1.19"
after running npm update
:
当您最初运行 npm update clean-webpack-plugin
时,您可以:
When you initially run npm update clean-webpack-plugin
you could have:
- 附加了
--save-dev
参数 (如果它列在package.json
的devDependencies
部分中,则适用). - 或者,附加
--save
参数 (如果它列在package.json
的dependencies
部分中,则适用).
- Appended the
--save-dev
argument (applicable if it was listed in yourdevDependencies
section ofpackage.json
). - Or, appended the
--save
argument (applicable if it was listed in yourdependencies
section ofpackage.json
).
根据情况将 --save-dev
或 --save
附加到 npm update clean-webpack-plugin
将更新条目在 package.json
中.这在 Recording Updates with --save 中有进一步解释
npm 文档的部分.
Appending either --save-dev
or --save
as appropriate to npm update clean-webpack-plugin
would have update the entry in package.json
. This is further explained in the Recording Updates with --save
section of the npm documentation.
通过这样做,您可以将其视为重新指定您将接受的更新范围的初始 >=
部分.
By doing this, you can think of it as re-specifying the initial >=
part of the range of updates you'll accept.
注意
使用附加的 --save
或 --save-dev
参数运行 npm update clean-webpack-plugin
不会有任何影响如果 npm ls clean-webpack-plugin
报告:
Running npm update clean-webpack-plugin
with the additional --save
or --save-dev
argument will not have any affect if npm ls clean-webpack-plugin
reports:
...
└── [email protected]
没有什么要更新的,所以我只是在 package.json
中手动指定 "^0.1.19"
.
There would be nothing to update, so I'd just manually specify "^0.1.19"
in package.json
.
这篇关于npm - Semver 版本控制 - 使用插入符号“^"更新包;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!