check if package.json contains dependencies not in node_modules

六眼飞鱼酱① 提交于 2021-01-29 15:49:19

问题


I'm looking for a way to check if there are packages that need to be installed that currently are not. For example, there is a package.json dependency that was not previously installed or a package.json dependency version that was not previously installed. To be clear, I'm not looking for outdated packages.

If this is not possible, I would be ok with knowing whether npm install installed or removed any packages.


回答1:


Try using the --dry-run flag. According to the docs man npm-install:

The --dry-run argument will report in the usual way what the 
install would have done without actually installing anything.

You can run this command, check the output. Unfortunately, it doesn't look like the return value changes depending on whether there are any changes, but you can parse the output.

If the last line of the output looks like:

up to date in 7.064s

Then you are good, but if it looks like:

added 1 package in 7.014s

or

updated 1 package in 6.019s

Then an npm i is required.



来源:https://stackoverflow.com/questions/61894812/check-if-package-json-contains-dependencies-not-in-node-modules

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