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

从一些配置文件中获取所需的版本号(我想我可以把它作为一个注释放在karma.conf.js中) 检查karma runner的定义版本是否安装在npm的全局repo中 如果不是,或者安装的版本比期望的旧:选择并安装正确的版本 \Scripts-Tests\karma.conf.js——reporteteamcity——单次运行

所以我真正的问题是:“如果安装了所需版本的包,如何检入脚本?”你应该做检查,还是每次都调用npm -g install更安全?

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


当前回答

3个简单的步骤,您可以使用更新所有过期的包

首先,检查过期的包

Sudo NPM I -g NPM check-updates

第二,把它们都准备好

NCU -u

终端中的结果如下所示:

第三,更新所有这些。

npm安装

就是这样。

其他回答

NPM命令更新或修复某些依赖清单文件中的漏洞

Use below command to check outdated or vulnerabilities in your node modules. npm audit If any vulnerabilities found, use below command to fix all issues. npm audit fix If it doesn't work for you then try npm audit fix -f, this command will almost fix all vulnerabilities. Some dependencies or devDependencies are locked in package-lock.json file, so we use -f flag to force update them. If you don't want to use force audit fix then you can manually fix your dependencies versions by changing them in package-lock.json and package.json file. Then run

NPM更新&& NPM升级

在npm@5.0.0+上,你可以简单地做:

npm update <package name>

这将自动更新包。json文件。我们不需要手动更新最新版本,然后使用npm update <包名>

您仍然可以使用旧的行为

npm update --no-save

(参考)

NPM expired将识别应该更新的包,NPM update <包名>可以用来更新每个包。但是在npm@5.0.0之前,npm update <包名>将不会更新包中的版本。Json是一个问题。

最佳的工作流程是:

用npm obsolete标识过期的包 更新package.json中的版本 运行npm update来安装每个包的最新版本

查看npm-check-updates来帮助完成这个工作流。

使用npm i npm-check-updates -g安装npm-check-updates 运行npm-check-updates来列出过期的包(基本上和运行npm outdated是一样的) 运行npm-check-updates -u更新包中的所有版本。Json(这是神奇的酱汁) 像往常一样运行npm update,根据更新后的package.json安装新版本的包

一个简单的步骤:

$ NPM I -g NPM -check-updates && ncu -u && NPM I

仅此而已。所有的包版本在包。Json将是最新的主要版本。

编辑:

这里发生了什么?

正在安装为您检查更新的包。 使用此包更新包中的所有包版本。json (-u是——updateAll的缩写)。 安装所有新版本的包。

要真正更新一个包,请安装NCU,然后仅为该包运行它。这将是最新的。

npm install -g npm-check-updates

ncu -f your-intended-package-name -u