如何获取未保存到 package.json 的包列表? [英] How to get a list of packages not saved to package.json?

查看:43
本文介绍了如何获取未保存到 package.json 的包列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在本地机器上安装了几个软件包,但我不知道我安装了哪些软件包.

I've installed a couple of packages here in my local machine, but I'm not able to know which ones I've installed.

是否有一些框架可以显示我的项目中安装了哪些包和版本(未保存、已保存和已保存)?

Is there some framework to show me which packages and version are installed in my project (not-saved, saved and dev saved)?

我尝试比较 node_modules 文件夹,但结果不是很精确.

I tried to compare the node_modules folders but the results are not very precise.

推荐答案

你想要的是 npm list(npm ls 是方便的别名).

What you want is npm list (npm ls is handy alias).

假设你跑了:

npm init
npm install -S postcss
npm install -D postcss-cli
npm install postcss-import

然后如果你运行 npm list --depth 0,npm 会打印:

Then if you run npm list --depth 0, npm will print:

my-package@1.0.0 /home/.../my-package
├── postcss@5.2.16
├── postcss-cli@3.0.0-beta
└── postcss-import@9.1.0 extraneous

npm ERR! extraneous: postcss-import@9.1.0 /home/.../my-package/node_modules/postcss-import

所有标有extraneous的包都已安装,但未添加到package.json.

All the packages marked with extraneous have been installed, but not added to package.json.

默认情况下,npm list 打印一个完整的依赖图.--depth 选项将图形限制为指定的层数.--depth 0 只打印直接依赖,而不是它们的依赖,所以这就是你想要的.

By default, npm list prints a full dependency graph. The --depth option limits the graph to the specified number of layers. --depth 0 only prints the direct dependencies, not their dependencies, so that's what you want in this case.

这篇关于如何获取未保存到 package.json 的包列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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