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

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

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

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


当前回答

一个简单的步骤:

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

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

编辑:

这里发生了什么?

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

其他回答

还有一个名为npm-check的“fresh”模块:

npm-check 检查过时的、不正确的和未使用的依赖项。

它还提供了一种方便的交互式方式来使用npm-check -u更新依赖关系。

另一种方法是首先升级一揽子计划。Json文件使用,

ncu -u

然后简单地运行,

npm install

将所有包更新到最新版本。 ps:它会将所有的包更新到最新版本,但是如果包已经是最新的,那么包将完全不受影响。

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 outdated

' expired '将检查package中定义的每个模块。查看NPM注册表中是否有更新的版本。

例如,xml2js 0.2.6(位于当前项目中的node_modules中)已经过时,因为存在一个更新的版本(0.2.7)。你会看到:

xml2js@0.2.7 node_modules/xml2js current=0.2.6

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

npm update

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

npm update xml2js

更新包。Json版本号,添加——save标志:

npm update --save

没有额外的包,只是检查过时的和更新那些是,这个命令将做:

npm install $(npm expired | cut -d' ' -f 1 | sed '1d' | xargs -I '$' echo '$@最新' | xargs echo)