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

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

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

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


当前回答

更新一个本地包: 首先通过以下方法找出过时的软件包: npm过时 然后手动更新你想要的包: 保存<package_name>

这样就不需要更新本地的package.json 手动文件。

注意,上面的命令将把包更新到最新版本。

如果您在软件包中编写了某个版本。Json文件,并执行: NPM更新<package_name> 在这种情况下,您将获得与您在包中编写的版本相关的下一个稳定版本。json文件。

使用npm list <package_name>你可以找到你的本地包的当前版本。

其他回答

只需执行此操作将所有内容更新到最新版本- NPX npm-check-updates -u

注意-系统会提示您安装npm-check-updates。按“y”并回车。

现在运行npm i,就可以开始了。

bash还有一个:

npm outdated -parseable|cut -d: -f5|xargs -L1 npm i

更新一个本地包: 首先通过以下方法找出过时的软件包: npm过时 然后手动更新你想要的包: 保存<package_name>

这样就不需要更新本地的package.json 手动文件。

注意,上面的命令将把包更新到最新版本。

如果您在软件包中编写了某个版本。Json文件,并执行: NPM更新<package_name> 在这种情况下,您将获得与您在包中编写的版本相关的下一个稳定版本。json文件。

使用npm list <package_name>你可以找到你的本地包的当前版本。

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升级

如果你想把一个包升级到最新版本(主要版本、次要版本和补丁版本),在包名后面加上@latest关键字,例如:

npm i express-mongo-sanitize@latest

这将把express-mongo-sanitize从1.2.1版本更新到2.2.0版本。

如果你想知道哪些包已经过期,哪些包可以更新,可以使用npm expired命令

ex:

$ npm outdated
Package             Current   Wanted  Latest  Location                         Depended by
express-rate-limit    3.5.3    3.5.3   6.4.0  node_modules/express-rate-limit  apiv2
helmet               3.23.3   3.23.3   5.1.0  node_modules/helmet              apiv2
request-ip            2.2.0    2.2.0   3.3.0  node_modules/request-ip          apiv2
validator           10.11.0  10.11.0  13.7.0  node_modules/validator           apiv2