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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tt-a1i/pkg-analyzer

v0.4.0

Published

Analyze node_modules dependencies - visualize sizes, find duplicates, detect unused packages, export reports for AI optimization

Readme

pkg-analyzer

npm version CI codecov Node.js License: MIT

English | 中文

一个强大的 CLI 工具,用于分析 node_modules 依赖 - 可视化包大小、查找重复包、检测未使用的依赖,并导出报告供 AI 优化建议。

特性

  • 大小分析 - 可视化包大小,带彩色进度条和图标
  • 重复检测 - 查找存在多个版本的包
  • 未使用检测 - 识别可能未使用的依赖
  • 依赖树 - 查看层级依赖关系
  • 过期检查 - 显示过期的依赖版本
  • 安全审计 - 运行 npm audit 安全检查
  • 项目对比 - 对比两个项目的依赖差异
  • 交互模式 - 菜单驱动的界面,方便探索
  • 导出报告 - 导出为 JSON/Markdown 供 AI 分析
  • 剪贴板复制 - 直接复制报告到剪贴板
  • 多包管理器 - 支持 npm、yarn 和 pnpm

安装

# npm
npm install -g @tt-a1i/pkg-analyzer

# pnpm
pnpm add -g @tt-a1i/pkg-analyzer

# yarn
yarn global add @tt-a1i/pkg-analyzer

# 或者直接使用 npx(无需安装)
npx @tt-a1i/pkg-analyzer

快速开始

# 分析当前项目
pkg-analyzer

# 交互模式
pkg-analyzer -i

# 导出报告供 AI 分析
pkg-analyzer --copy

使用方法

pkg-analyzer [路径] [选项]

选项

| 选项 | 简写 | 说明 | |------|------|------| | --top <n> | -n | 显示最大的 N 个包(默认:10) | | --type <类型> | -t | 按类型过滤:prod、dev、transitive、all | | --sort <字段> | -s | 排序:size、name、type | | --duplicates | -d | 显示重复的包 | | --unused | -u | 检测未使用的依赖 | | --outdated | -o | 显示过期的依赖 | | --security | | 运行安全审计 | | --compare <路径> | | 与另一个项目对比 | | --why <包名> | | 显示为什么安装了某个包 | | --tree [包名] | | 显示依赖树 | | --depth <n> | | 树视图最大深度(默认:3) | | --filter <关键词> | -f | 按名称过滤包 | | --interactive | -i | 交互模式 | | --export <文件> | -e | 导出到文件(.json 或 .md) | | --copy | -c | 复制报告到剪贴板 | | --json | | 输出为 JSON |

示例

基本分析

# 显示最大的 20 个包
pkg-analyzer --top 20

# 只显示生产依赖
pkg-analyzer --type prod

# 按名称排序
pkg-analyzer --sort name

查找问题

# 查找重复的包(多个版本)
pkg-analyzer --duplicates

# 查找未使用的依赖
pkg-analyzer --unused

# 搜索特定的包
pkg-analyzer --filter react

更新与安全

# 显示过期的依赖
pkg-analyzer --outdated

# 运行安全审计
pkg-analyzer --security

# 与另一个项目对比
pkg-analyzer --compare ../other-project

包安装原因

# 查找为什么安装了某个包
pkg-analyzer --why lodash

# 检查包是直接依赖还是传递依赖
pkg-analyzer --why ansi-styles

依赖树

# 显示完整依赖树
pkg-analyzer --tree

# 显示特定包的依赖树
pkg-analyzer --tree lodash

# 限制树的深度
pkg-analyzer --tree --depth 2

导出与分享

# 复制报告到剪贴板(粘贴给 AI 获取建议)
pkg-analyzer --copy

# 导出为 Markdown 文件
pkg-analyzer --export report.md

# 导出为 JSON 文件
pkg-analyzer --export report.json

交互模式

pkg-analyzer -i

交互模式提供菜单驱动的界面:

  • 按大小分析顶级包
  • 按依赖类型过滤
  • 按名称搜索包
  • 查找重复项
  • 检测未使用的依赖
  • 查看依赖树

AI 辅助优化

导出报告并粘贴给你喜欢的 AI 助手获取优化建议:

pkg-analyzer --copy

导出的 Markdown 包含:

  • 完整的依赖分析
  • 重复的包和浪费的空间
  • 可能未使用的依赖
  • 现成的 AI 提示词,请求优化建议

包管理器支持

| 包管理器 | 锁文件 | 支持 | |----------|--------|------| | npm | package-lock.json | ✅ | | yarn | yarn.lock | ✅ | | pnpm | pnpm-lock.yaml | ✅ |

系统要求

  • Node.js >= 20

贡献

欢迎贡献!请随时提交 Pull Request。

许可证

MIT © tt-a1i