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

orphix

v1.0.9

Published

Find unused files, exports, functions, components, and APIs in JS/TS projects

Readme

Orphix 🕵️‍♂️


Find unused files, exports, functions, components, APIs, and imports before they become technical debt.

Orphix uses static analysis and AST parsing via Babel to construct your project's dependency graph, identify orphaned files, discover unused module exports, locate dead local functions/React components, map dead API routes, identify unused npm package dependencies, and clean up the code automatically.


🚀 Features

  • 📂 Unused File Detection: Identifies files that are completely unreachable from your entry points.
  • 📤 Unused Export Detection: Flags module exports that are never imported anywhere in the project.
  • ⚡ Unused Function & Component Detection: Finds functions and React components declared but never invoked or rendered.
  • 📥 Unused Imports Detection: Identifies imported bindings that are never referenced in the declaring file.
  • 📦 Unused npm Dependencies: Flags third-party npm packages declared in package.json dependencies list that are never imported anywhere in the project.
  • 💼 Monorepo & Client/Server Support: Auto-groups workspaces containing separate sub-projects (e.g. client and server directories) and runs entrypoint auto-detection per-project root to prevent cross-deletions.
  • 🔍 Path Alias Resolution (@/): Automatically resolves @/ imports relative to the nearest project root's src directory.
  • ⚙️ CommonJS & ES Modules: Full compatibility parsing for both standard ESM (import/export) and CommonJS (require / module.exports).
  • 🔗 Template-Literal Dynamic Imports: Traces and resolves template-literal dynamic imports (e.g. import(\./pages/${page}`)`), automatically marking the target folders as reachable.
  • 🧠 Framework Awareness: Out-of-the-box entrypoint auto-detection for Next.js (pages, layouts, API routes) and Vite.
  • 🛢️ Barrel File / Re-export Propagation: Follows re-exports (e.g. export { x } from './module') to trace usage back to its origin file correctly.
  • 📡 Dead API Route Tracing: Extracts Next.js API endpoints and scans string/template literals across the project to flag unused endpoints.
  • 🧹 Automatic Code Cleanup (--clean): Rewrites files using Babel-traverse codemods to delete orphaned files, strip unused imports, and demote/remove unused exports.
  • 🕒 Git History Integration: Attaches the last modification date and author to unused items to help coordinate cleanups.
  • 🧪 CI/CD Integration: Supports pipeline failures via the --fail-on-dead-code exit flag.
  • 📦 Babel AST Support: Out-of-the-box support for modern JavaScript, JSX, TypeScript, and TSX.
  • 🛡️ Authoritative & Safe: Safe path validations prevent deletion of files outside the scan workspace boundary, and Code formatting preservation minimises Git diff lines.

📦 Installation

Run Orphix directly without installation using npx:

npx orphix

Or install it globally:

npm install -g orphix

Or install it locally in your project:

npm install --save-dev orphix

🛠️ CLI Options

Running npx orphix --help outputs:

Usage: orphix [options] [dir]

Find unused files, exports, functions, and components in your JS/TS codebase

Arguments:
  dir                       directory to scan (default: ".")

Options:
  -V, --version             output the version number
  --json                    output result in JSON format (default: false)
  --verbose                 detailed logs (default: false)
  --fail-on-dead-code       exit with code 1 if dead code is found (default: false)
  --git                     extract git history metadata (last edit date/author) (default: false)
  --ignore <patterns...>    glob patterns of files to ignore
  --entry <entryPoints...>  explicit entry point files
  --clean                   automatically delete unused files and clean up dead code (default: false)
  -h, --help                display help for command

⚙️ Configuration (orphix.config.json)

You can define a configuration file named orphix.config.json in the root of your target directory. It merges seamlessly with command-line options.

{
  "entryPoints": ["src/index.js", "src/admin.js"],
  "ignore": ["**/tests/**", "**/*.test.js"],
  "git": true,
  "failOnDeadCode": false,
  "verbose": false,
  "json": false
}

📁 Examples

Basic Scan

Scan the current directory (auto-detecting entry points):

npx orphix

Specify Target Directory

Scan a specific folder:

npx orphix src/

Specify Entry Point

Instruct Orphix to trace dependencies starting from custom entry points:

npx orphix src/ --entry src/main.tsx src/admin.tsx

Enable Git Integration

Retrieve information about when the files were last modified and by whom:

npx orphix --git

Ignore Directories

Specify custom patterns to ignore:

npx orphix --ignore "**/tests/**" "**/mock/**"

Fail Build in CI/CD

Exits with exit code 1 if any unused files, exports, or functions are detected:

npx orphix --fail-on-dead-code

JSON Format

Print results in raw JSON format (ideal for custom pipelines and automated tools):

npx orphix --json

Automatic Code Cleanup

Automatically delete unused files, strip unused imports, and clean up exports/functions:

npx orphix --clean

⚙️ How It Works

  1. Scanner: Scans the targeted folder using fast-glob. It respects default rules (ignores node_modules, .git, dist, etc.) and automatically parses .gitignore file patterns if present.
  2. Parser: Translates source code into Abstract Syntax Trees (AST) using @babel/parser supporting TypeScript and JSX.
  3. Graph Builder: Traces static imports, dynamic imports, and CommonJS require() calls to determine reachable code paths.
  4. Analyzer: Cross-references imported specifiers and internal references to detect dead exports, unused imports, dead API endpoints, and propagates barrel re-exports.
  5. Cleaner: Modifies the file ASTs using @babel/traverse and @babel/generator to prune unused code, strip export keywords, remove empty import statements, and delete orphaned files.
  6. Reporter: Displays detailed colorized summaries on stdout.

📄 License

MIT