是否可以仅在尚未安装npm软件包的情况下安装它? [英] Is it possible to install npm package only if it has not been already installed?
问题描述
仅当尚未安装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屋!