问题描述
我从另一个项目中复制了package.json,现在想要将所有依赖项添加到他们的最新版本,因为这是一个新项目,如果它中断,我不介意修复它。
I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks.
最简单的方法是什么?
我现在知道的最好方法是运行 npm info express version
然后为每个人手动更新package.json。必须有更好的方法。
The best way I know of now is to run npm info express version
then update package.json manually for each one. There must be a better way.
{
"name": "myproject",
"description": "my node project",
"version": "1.0.0",
"engines": {
"node": "0.8.4",
"npm": "1.1.65"
},
"private": true,
"dependencies": {
"express": "~3.0.3", // how do I get these bumped to latest?
"mongodb": "~1.2.5",
"underscore": "~1.4.2",
"rjs": "~2.9.0",
"jade": "~0.27.2",
"async": "~0.1.22"
}
}
我现在是,这是解决这个问题的绝佳方法。
I am now a collaborator on npm-check-updates, which is a great solution to this problem.
推荐答案
看起来像是现在实现这一目标的唯一方法。
Looks like npm-check-updates is the only way to make this happen now.
npm i -g npm-check-updates
ncu -u
npm install
在npm< 3.11:
On npm <3.11:
只需将每个依赖项的版本更改为 *
,然后运行 npm update --save
。 (注意: )。
Simply change every dependency's version to *
, then run npm update --save
. (Note: broken in recent (3.11) versions of npm).
之前:
"dependencies": {
"express": "*",
"mongodb": "*",
"underscore": "*",
"rjs": "*",
"jade": "*",
"async": "*"
}
之后:
"dependencies": {
"express": "~3.2.0",
"mongodb": "~1.2.14",
"underscore": "~1.4.4",
"rjs": "~2.10.0",
"jade": "~0.29.0",
"async": "~0.2.7"
}
当然,这是更新依赖关系的直言不讳。如果—正如你所说的那样,那就没关系了......项目是空的,没有任何东西可以破坏。
Of course, this is the blunt hammer of updating dependencies. It's fine if—as you said—the project is empty and nothing can break.
另一方面,如果你在一个更成熟的项目中工作,你可能想要在升级之前验证依赖项中是否有重大更改。
On the other hand, if you're working in a more mature project, you probably want to verify that there are no breaking changes in your dependencies before upgrading.
要查看哪些模块已过时,只需运行。它将列出任何已安装的具有更新版本的依赖项。
To see which modules are outdated, just run npm outdated
. It will list any installed dependencies that have newer versions available.
这篇关于如何将package.json中的每个依赖项更新为最新版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!