问题
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