如果需要 npm 检查和更新包 [英] npm check and update package if needed

查看:39
本文介绍了如果需要 npm 检查和更新包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要将 Karma 测试运行器集成到 TeamCity 中,为此我想给系统工程师提供一个小脚本(powershell 或其他):

We need to integrate Karma test runner into TeamCity and for that I'd like to give sys-engineers small script (powershell or whatever) that would:

  1. 从一些配置文件中获取所需的版本号(我想我可以把它作为注释放在 karma.conf.js 中)

检查定义的 karma runner 版本是否安装在 npm 的全局存储库中

check if the defined version of karma runner installed in npm's global repo

如果不是,或者安装的版本比预期的旧:选择并安装正确的版本

if it's not, or the installed version is older than desired: pick up and install right version

运行它:karma start .Scripts-Testskarma.conf.js --reporters teamcity --single-run

所以我真正的问题是:如果安装了所需版本的软件包,如何检查脚本?".你应该检查一下,还是每次都调用 npm -g install 是安全的?

So my real question is: "how can one check in a script, if desired version of package installed?". Should you do the check, or it's safe to just call npm -g install everytime?

我不想总是检查和安装最新的可用版本,因为其他配置值可能会变得不兼容

推荐答案

要检查项目中的任何模块是否旧":

To check if any module in a project is 'old':

npm outdated

'outdated' 将检查 package.json 并查看 NPM 注册表中是否有更新的版本.

'outdated' will check every module defined in package.json and see if there is a newer version in the NPM registry.

例如,假设 xml2js 0.2.6(位于当前项目的 node_modules 中)已过时,因为存在较新的版本 (0.2.7).你会看到:

For example, say xml2js 0.2.6 (located in node_modules in the current project) is outdated because a newer version exists (0.2.7). You would see:

xml2js@0.2.7 node_modules/xml2js current=0.2.6

更新所有依赖项,如果您确信这是可取的:

To update all dependencies, if you are confident this is desirable:

npm update

或者,更新单个依赖项,例如 xml2js:

Or, to update a single dependency such as xml2js:

npm update xml2js

这篇关于如果需要 npm 检查和更新包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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