检查 package.json 是否包含不在 node_modules 中的依赖项 [英] check if package.json contains dependencies not in node_modules

查看:198
本文介绍了检查 package.json 是否包含不在 node_modules 中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检查是否有需要安装但当前尚未安装的软件包.例如,存在先前未安装的 package.json 依赖项或先前未安装的 package.json 依赖项版本.需要明确的是,我不是在寻找过时的软件包.

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.

如果这是不可能的,我会知道 npm install 是否安装或删除了任何软件包.

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

推荐答案

尝试使用 --dry-run 标志.根据文档 man npm-install:

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

updated 1 package in 6.019s

然后需要一个 npm i.

Then an npm i is required.

这篇关于检查 package.json 是否包含不在 node_modules 中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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