npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

depsserch

v0.1.9

Published

文件依赖检索、可删除文件检索,可以检索文件夹所有文件的依赖情况和判断哪些文件可以删除

Readme

文件依赖检索,可以检索文件夹所有文件的依赖情况,并提供以下功能:

  • 分析出项目中那些文件没有被使用
  • 一个文件被那些文件使用了
  • 根据依赖情况和入口文件参数给出文件是否可删除的建议
  • 统计可删除文件的大小
  • 删除代码中无用的变量(慎用)

该工具适用于项目越做越大,不好管理,需要净化代码,净化项目文件的时候,或者其他场合。

注意:使用anu命令时需要项目中存在eslint配置文件,之所以没有给出默认的配置,我相信规范的项目代码是需要eslint的

使用

  • 安装依赖
npm i -g depsserch
  • 命令ds
coan ds

文件依赖检索

选项:
  --version        显示版本号                                           [布尔]
  -h, --help       显示帮助信息                                         [布尔]
  --path, -p       扫描路径                                            [字符串] [必需]
  --aliaspath, -a  alias配置文件路径                                    [字符串]
  --show, -s       信息显示类型, a: 显示所有;o: 是显示没有被依赖的文件       [字符串]
  --input, -i      项目入口文件文件夹路径                                 [字符串]
  --config, -c     配置文件路径                                         [字符串]

参数解释:
-p: 要扫描的文件夹路径
-a: alias配置文件路径(webpack.config.js路径)
-s: 信息显示类型, a: 显示所有;o: 是显示没有被依赖的文件
-i: 入口文件

当添加入口文件参数,会分析那些文件可以删除, 否则只分析文件依赖情况。config配置如下:

module.exports = {
    aliaspath: './webpack.dev.js',
    show: 'o',
    input: [
        './test/A.js',
        './test/B.js',
    ]
}

可以配置三个参数:aliaspath、show、input

  • 命令anu
选项:
  --version   显示版本号                                          [布尔]
  -h, --help  显示帮助信息                                        [布尔]
  --path, -p  扫描路径                                            [字符串] [必需]
  --func, -f  是否替换函数, 如果需要替换,建议函数注释中没有"{"或者"}"
                                                                 [布尔] [默认值: false]

该命令的作用是:分析出那些变量没有被使用,并自动删除变量(慎用)。这里的变量包括var、const、import或者定义的函数。默认不会检索函数变量,因为函数变量的定义不好获取(函数中可能包含注释,或者字符串),如果使用建议函数定义中不要在注释中或者字符串中存在 "{","}" 字符

  • 示例1 -- ds命令
baoxiangdongdeMacBook-Pro:depsSerch baoxiangdong$ coan ds -p . -a ./webpack.dev.js -s o -i ./test/
--------------------- 开始扫描 ---------------------
DIR: /Users/baoxiangdong/Documents/github/depsSerch
DIR: /Users/baoxiangdong/Documents/github/depsSerch/bin
FILE: /Users/baoxiangdong/Documents/github/depsSerch/bin/coan.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/bin/config.js
DIR: /Users/baoxiangdong/Documents/github/depsSerch/lib
FILE: /Users/baoxiangdong/Documents/github/depsSerch/lib/anu.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/lib/config.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/lib/ds.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/lib/parse.js
DIR: /Users/baoxiangdong/Documents/github/depsSerch/test
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/A.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/B.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/C.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/D.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/common.js
DIR: /Users/baoxiangdong/Documents/github/depsSerch/test/css
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/css/test.scss
DIR: /Users/baoxiangdong/Documents/github/depsSerch/test/imgs
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/imgs/demo.jpg
FILE: /Users/baoxiangdong/Documents/github/depsSerch/test/index.js
DIR: /Users/baoxiangdong/Documents/github/depsSerch/utils
FILE: /Users/baoxiangdong/Documents/github/depsSerch/utils/file.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/utils/utils.js
FILE: /Users/baoxiangdong/Documents/github/depsSerch/webpack.dev.js
--------------------- 扫描结束 ---------------------
--------------------- 依赖情况 ---------------------
没有被依赖的文件: 
  /Users/baoxiangdong/Documents/github/depsSerch/bin/coan.js
  /Users/baoxiangdong/Documents/github/depsSerch/test/A.js
  /Users/baoxiangdong/Documents/github/depsSerch/test/C.js
  /Users/baoxiangdong/Documents/github/depsSerch/test/common.js
  /Users/baoxiangdong/Documents/github/depsSerch/test/css/test.scss
  /Users/baoxiangdong/Documents/github/depsSerch/test/imgs/demo.jpg
  /Users/baoxiangdong/Documents/github/depsSerch/test/index.js
  /Users/baoxiangdong/Documents/github/depsSerch/webpack.dev.js
可删除的文件
  /Users/baoxiangdong/Documents/github/depsSerch/bin/coan.js
  /Users/baoxiangdong/Documents/github/depsSerch/bin/config.js
  /Users/baoxiangdong/Documents/github/depsSerch/lib/ds.js
  /Users/baoxiangdong/Documents/github/depsSerch/lib/anu.js
  /Users/baoxiangdong/Documents/github/depsSerch/utils/file.js
  /Users/baoxiangdong/Documents/github/depsSerch/lib/config.js
  /Users/baoxiangdong/Documents/github/depsSerch/utils/utils.js
  /Users/baoxiangdong/Documents/github/depsSerch/lib/parse.js
  /Users/baoxiangdong/Documents/github/depsSerch/webpack.dev.js
可删除文件数:9
可删除文件大小:26.4033203125KB
  • 示例2 -- anu命令
baoxiangdongdeMacBook-Pro:depsSerch baoxiangdong$ coan anu -p ./test/
/Users/baoxiangdong/Documents/github/depsSerch/test/B.js
删除的内容:
import D from './D';

./test/imgs/demo.jpg