npm install only if package missing or out-of-date compared to package.json

廉价感情. 提交于 2021-02-20 10:15:54

问题


I want to be able to compare my locally installed packages against my project package.json file without making a call against the npm online repo. If there is a package that is out of date based on the package.json file, then and only then will it go to the npm online repo and install the package.

The reason for this is that I want to be able to update the package.json file to require a newer version of a package, commit this change to the project repo and when other developers on the team get latest their npm package is updated. I do not want to slow down the process if everything is up-to-date or cause the build to fail if access to the npm repo or the internet is down.

I am wondering if this is an already solved use-case or do I need to parse the package.json file and compare it to a "npm ls" output myself?


回答1:


you will need to setup a local repository (by duplicating the NPM couchdb localy) ( see https://stackoverflow.com/a/7577265/406458)

then you could use npm-check-updates.

npm-check-updates will give you a list of packages that can be updated in your package.json file see https://www.npmjs.org/package/npm-check-updates

$ npm-check-updates

"connect" can be updated from 2.8.x to 2.11.x (Installed: 2.8.8, Latest: 2.11.0) "commander" can be updated from 1.3.x to 2.0.x (Installed: 1.3.2, Latest: 2.0.0)

Run 'npm-check-updates -u' to upgrade your package.json automatically Check global npm packages for updates:

$ npm-check-updates -u



来源:https://stackoverflow.com/questions/22056166/npm-install-only-if-package-missing-or-out-of-date-compared-to-package-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!