javascript - 如何读取具有 node_modules 平面依赖关系的 npm 项目的源代码?
问题描述
在 npm 将其依赖文件结构从 更改为 之前nested
,flat
我可以轻松地通过依赖树向下钻取项目依赖项的源代码和依赖项的依赖关系,从而对项目有深入的了解。
然而,现在项目flatly
的根目录node_modules
中有数千个依赖项,因此无法理解和浏览项目真正的依赖项结构。
如果您想深入了解开源项目,这些天您如何浏览项目依赖关系树?
解决方案
使用 NPM 命令行,您可以使用npm ls
它将输出依赖关系图树。
Yarn 命令行对这种调查有一个很好的功能:yarn why
请参阅此处的文档:https ://yarnpkg.com/lang/en/docs/cli/why/
这是一个示例输出:
yarn why doctrine
yarn why v1.7.0
[1/4] Why do we have the module "doctrine"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "doctrine@2.1.0"
info Has been hoisted to "doctrine"
info Reasons this module exists
- Hoisted from "eslint-plugin-react#doctrine"
- Hoisted from "eslint#doctrine"
- Hoisted from "@storybook#react#babel-plugin-react-docgen#react-docgen#doctrine"
=> Found "eslint-plugin-import#doctrine@1.5.0"
info This module exists because "eslint-plugin-import" depends on it.
Done in 0.91s.
推荐阅读
- javascript - 在加载组件之前等待 VueX 值加载
- c - 如何从我创建的文本文件中读取结构?
- javascript - 用于从 JSON 传递数据的数组映射方法
- ruby-on-rails - 无法在不支持编码的对象上设置编码
- scala - 是否可以等到 EMR 集群终止?
- android - Android Firebase 为什么我在更改电子邮件后会退出?
- javascript - componentWillUnmount 应该在传入组件的 componentDidMount 之前调用,不是吗?
- maven - 使用 Maven Appassembler 插件,如何在 BaseDir 中生成脚本?
- javascript - 如何阻止调用堆栈过载?
- tensorflow - Keras:关于 CPU 再现性的 MLP