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

exports-cleanup

v0.1.0

Published

Find and remove unused exports - clean up dead code from your codebase

Readme

exports-cleanup

Find unused exports in your codebase - clean up dead code and reduce bundle size

npm version License: MIT

Problem

You export 100 functions. Only 20 are actually used. Dead code bloats your bundle.

Solution

exports-cleanup scans your codebase, tracks all imports, and finds exports that are never used anywhere.

Features

  • Fast scanning - Uses regex-based parsing for speed
  • Auto-fix - Remove unused exports with --fix
  • Bundle size estimation - Shows potential savings in KB
  • TypeScript + JavaScript - Works with .ts, .tsx, .js, .jsx, .mjs
  • Type-aware - Optionally include/exclude type exports
  • Safelist support - Keep intentional exports with // exports-cleanup-ignore
  • CI/CD ready - Exit code 1 when unused exports found, Markdown output for PRs
  • Zero config - Just run it

Installation

# Run directly with npx (recommended)
npx exports-cleanup

# Or install globally
npm install -g exports-cleanup

Usage

Basic Scan

# Scan current directory
npx exports-cleanup

# Scan specific directory
npx exports-cleanup ./src

# Compact output
npx exports-cleanup --compact

Include Types

# Also check type and interface exports
npx exports-cleanup --include-types

Show All Exports

# Show used exports too
npx exports-cleanup --show-used

Auto-Fix (Remove Unused Exports)

# Preview what would be removed
npx exports-cleanup --fix --dry-run

# Remove unused exports (creates backups)
npx exports-cleanup --fix --backup

# Remove without backups
npx exports-cleanup --fix

Safelist Exports

Keep intentional exports (public APIs, entry points) by adding a comment:

// exports-cleanup-ignore
export function publicApiMethod() {
  // This export will be ignored
}

/* exports-cleanup-ignore */
export const PUBLIC_CONSTANT = 'value';

Markdown Output (for CI/PRs)

# Output as Markdown
npx exports-cleanup --markdown

# Save to file
npx exports-cleanup --markdown -o report.md

Example Output

🔍 Unused Exports (47 found):

Summary:
  Total exports:  120
  Unused:        47
  Used:          73
  Potential savings: 23.4 KB

📁 src/utils/helpers.ts
  ❌ formatDate() [function]
     Line 12 - exported but never imported
  ❌ calculateTax() [function]
     Line 45 - exported but never imported
  ❌ DEPRECATED_CONSTANT [const]
     Line 78 - exported but never imported

📁 src/utils/validation.ts
  ❌ validateEmail() [function]
     Line 5 - exported but never imported
  ❌ validatePhone() [function]
     Line 23 - exported but never imported

──────────────────────────────────────────────────
Potential bundle reduction: 23.4 KB

💡 Tips:
  • Remove unused exports to reduce bundle size
  • Some exports may be used dynamically (check manually)
  • Entry points and public APIs may show as "unused"

──────────────────────────────────────────────────
Cleaned up dead code? Consider supporting:
☕ https://buymeacoffee.com/willzhangfly

Compact Output

🔍 Found 47 unused exports:

  src/utils/helpers.ts
    formatDate, calculateTax, DEPRECATED_CONSTANT
  src/utils/validation.ts
    validateEmail, validatePhone
  src/components/OldButton.tsx
    OldButton, OldButtonProps

Potential savings: 23.4 KB

Comparison with Alternatives

| Feature | exports-cleanup | TypeScript | ESLint | ts-prune | knip | |---------|---------------|------------|--------|----------|------| | Find unused exports | ✅ | ❌ | ❌ | ✅ | ✅ | | Bundle size estimate | ✅ | ❌ | ❌ | ❌ | ❌ | | Zero config | ✅ | ❌ | ❌ | ⚠️ | ❌ | | Fast | ✅ | ✅ | ✅ | ❌ | ⚠️ | | CI/CD exit codes | ✅ | ✅ | ✅ | ⚠️ | ✅ | | Actively maintained | ✅ | ✅ | ✅ | ❌ (2021) | ✅ |

CLI Options

Usage: exports-cleanup [options] [path]

Arguments:
  path                    Directory to scan (default: ".")

Options:
  --json                  Output results as JSON
  --markdown              Output as Markdown (for CI/PRs)
  --compact               Compact output format
  -o, --output <file>     Save report to file
  --include-types         Include type and interface exports
  --show-used             Also show used exports
  --ignore <patterns>     Additional patterns to ignore (comma-separated)
  --fix                   Auto-remove unused exports
  --dry-run               Preview fixes without modifying files
  --backup                Create .backup files before fixing
  -V, --version           Output version number
  -h, --help              Display help

CI/CD Integration

# GitHub Actions - Basic check
- name: Check for unused exports
  run: npx exports-cleanup
  # Exits with code 1 if unused exports found

# With Markdown comment on PR
- name: Check unused exports
  run: |
    npx exports-cleanup --markdown -o unused-exports.md
    if [ -s unused-exports.md ]; then
      echo "## Unused Exports Found" >> $GITHUB_STEP_SUMMARY
      cat unused-exports.md >> $GITHUB_STEP_SUMMARY
    fi

# With threshold (using jq)
- name: Check unused exports count
  run: |
    npx exports-cleanup --json > unused.json
    COUNT=$(cat unused.json | jq '.unusedExports')
    if [ "$COUNT" -gt 10 ]; then
      echo "Too many unused exports: $COUNT"
      exit 1
    fi

Programmatic Usage

import { analyzeExports } from 'exports-cleanup';

const result = await analyzeExports('./src', {
  includeTypes: false,
  exclude: ['**/*.test.ts'],
});

console.log(`Found ${result.unusedExports} unused exports`);
console.log(`Potential savings: ${result.estimatedSavings} bytes`);

// Get unused export names
for (const file of result.files) {
  for (const exp of file.exports) {
    if (exp.isUnused) {
      console.log(`${exp.export.name} in ${file.file}`);
    }
  }
}

False Positives

Some exports may appear unused but are actually used:

  1. Entry points - Main exports used by consumers of your package
  2. Dynamic imports - import() expressions aren't always detected
  3. Re-exports - export * from './module'
  4. Framework conventions - Next.js pages, React components loaded by name
  5. Public APIs - Exports meant for external use

Review results manually before removing exports.

Ignored by Default

  • node_modules/
  • dist/, build/
  • .next/
  • coverage/
  • *.d.ts (declaration files)
  • *.test.*, *.spec.*
  • __tests__/

Requirements

  • Node.js 18.0.0 or higher

Support

This project is maintained in my free time. If it helped clean up your codebase, I'd really appreciate your support:

Thank you to everyone who has contributed, shared feedback, or helped spread the word!

License

MIT


Made with ❤️ for cleaner codebases