这是一个临时的叉子, 只需要到 受抚养人检查小组/受抚养人检查#127 或相当的合并
依赖性检查
请检查您在代码中使用过哪些模块, 然后确定它们被列为您的软件包中的依赖性
维修主要项目所需经费
依赖性检查 4.x 支持节点.js 10 及以后
依赖性检查 3.x 支持节点6及以后
依赖性检查 2.x 支持节点.js 0.10及以后( Dev Note: 使用 legacy 标签)
关于维护状况的更多信息,见 警卫。 。 。 .
如何运作
dependency-check 解析从默认条目文件(例如)开始的模块代码. index.js 或者说 main 和任何 bin 在 package.json 中定义的命令,或者如果已经定义了特定文件,那么这些命令)和穿过所有相对需要的JS文件,最终生成一个非相干模块列表
- 相对 - 比如说.
require('./a-relative-file.js'),如果遇到其中之一,则所需文件将由dependency-check算法 - 非相对 - 比如说.
require('a-module'),如果遇到其中之一,它将会被添加到依赖性列表中,但模块的子依赖性将不会得到递归解析
本模块的目标是,简单地检查所有非相对模块是否获得 require()'d'是在packet.json中,它阻止人们在安装你的模块时得到"模块找不到"出错,这些模块缺少了被意外发布给国家预防机制的道克(一直发生在我身上,因此是写这个模块的动力).
cli使用量
$ npm install dependency-check -g
$ dependency-check <path to module file(s), package.json or module folder>
# e.g.
$ dependency-check ./package.json --verbose
Success! All dependencies used in the code are listed in package.json
Success! All dependencies in package.json are used in the code
$ dependency-check ./package.json --missing --verbose
Success! All dependencies used in the code are listed in package.json
$ dependency-check ./package.json --unused --verbose
Success! All dependencies in package.json are used in the code
# or with file input instead:
$ dependency-check ./index.js
# even with globs and multiple inputs:
$ dependency-check ./test/**/*.js ./lib/*.js
dependency-check 如果存在差异, 则使用代码 1 退出, 除打印外
总是用代码0通过退出 --ignore
失踪
运行 dependency-check ./package.json --missing 将只检查是否确保您的代码中的所有模块都在您的软件包中列出。 json
未使用
运行 dependency-check ./package.json --unused 将只做丢失的检查的倒数, 并告诉你软件包中的哪个模块。 json 依赖性 未使用 在代码中
-- no-dev (无数据)
运行 dependency-check ./package.json --unused --no-dev 将不会告诉你您的软件包中是否有依赖性。 json 丢失或未使用
-没有
运行 dependency-check ./package.json --unused --no-peer 将不会告诉你您的软件包中是否有对等的依赖性
- 不透明模块, -i
忽略模块。 这对双方都有用 --unused 财务报告和审定财务报表 --missing。您可以指定许多单独的 --ignore-module 随想辩才. 例如运行 dependency-check ./package.json --unused --ignore-module foo 如果 foo 模块未在您的代码中使用。 通过使用 微比对所以说. --ignore-module "@types/*" is possible
-- 无违约企业
运行 eg. dependency-check package.json tests.js --no-default-entries 将不会添加任何默认条目, 尽管给出的主要路径是 one 到 package.json 或模块文件夹 。 所以,只有 tests.js 将检查文件
-- 扩展-e
运行 dependency-check ./package.json -e js,jsx:precinct 将解决所需路径 .js 财务报告和审定财务报表 .jsx 路径,并使用 precinct。 。 。 .
-- 检测
运行 dependency-check ./package.json --detective precinct 将 require() 当地 precinct 作为默认解析器。 使用 -e。默认解析 detective。 。 。 .
动词
运行中 --verbose 将启用关于成功与否的日志信息,否则只检查失败与否的日志.
-- 帮助
显示以上选项和所有其他可用的选项
每个 npm 发布前自动检查
将此添加到您的 .bash_profile编号 :.bashrc
# originally from https://gist.github.com/mafintosh/405048d304fbabb830b2
npm () {
([ "$1" != "publish" ] || dependency-check .) && command npm "$@"
}
现在,当你这样做 npm publish 而且你缺少依赖性 它不会公布,例如:
$ npm publish
Fail! Dependencies not listed in package.json: siblings
$ npm install --save siblings
$ npm publish # works this time
调用
见 调试依赖性。 。 。 .
笔记
- 侦探 用于解析
require()语句,这意味着它只是 需要静态这意味着你应该转换的东西像var foo = "bar"; require(foo)保持静态,例如.require("bar") - 使用 globbing 来有效添加您要检查的所有文件