如何将 package.json 中的每个依赖项更新到最新版本? [英] How to update each dependency in package.json to the latest version?

查看:136
本文介绍了如何将 package.json 中的每个依赖项更新到最新版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个项目中复制了 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 is to run npm info express version then update each dependency in package.json manually. 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"
  }
}


对于纱线的具体解决方案,请参考这个 StackOverflow 线程.


For Yarn specific solutions refer to this StackOverflow thread.

推荐答案

看起来像 npm-检查更新是现在实现这一目标的唯一方法.

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.(注意:在最近 (3.11) 版本的 npm 中损坏).

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.

要查看哪些模块已过时,只需运行 npm outdated.它将列出所有具有更新版本可用的已安装依赖项.

To see which modules are outdated, just run npm outdated. It will list any installed dependencies that have newer versions available.

对于 Yarn 特定解决方案,请参阅此 StackOverflow 答案.

For Yarn specific solution, refer to this StackOverflow answer.

这篇关于如何将 package.json 中的每个依赖项更新到最新版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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