是否可以仅在尚未安装npm软件包的情况下安装它? [英] Is it possible to install npm package only if it has not been already installed?

查看:131
本文介绍了是否可以仅在尚未安装npm软件包的情况下安装它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当尚未安装npm软件包时,才可以安装该软件包吗?

Is it possible to install npm package only if it has not been already installed?

我需要它来加速CircleCI上的测试,但是当我运行npm install protractor@2.1.0等时,它总是下载内容并从scracth安装它们,但是,在运行命令时,所有模块的node_modules文件夹已经存在(从以前的版本进行缓存)和protractor --version等显示了所需的软件包版本.

I need this to speed up test on CircleCI, but when I run npm install protractor@2.1.0 etc. it always downloads things and installs them from scracth, however, node_modules folder with all modules is already present at the moment of running commands (cached from previous build) and protractor --version etc. shows the needed version of the package.

最好有一些像这样的单行命令:

Its perfect to have some one-line command like this:

protractor --version || npm install -g protractor@2.1.0

但是也会检查软件包版本的人.

but the one that will also check version of the package.

推荐答案

使用bash即可完成

[ $(node -p "require('protractor/package.json').version") != "2.1.0" ] && npm install protractor@2.1.0

这篇关于是否可以仅在尚未安装npm软件包的情况下安装它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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