exports-cleanup
v0.1.0
Published
Find and remove unused exports - clean up dead code from your codebase
Maintainers
Readme
exports-cleanup
Find unused exports in your codebase - clean up dead code and reduce bundle size
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-cleanupUsage
Basic Scan
# Scan current directory
npx exports-cleanup
# Scan specific directory
npx exports-cleanup ./src
# Compact output
npx exports-cleanup --compactInclude Types
# Also check type and interface exports
npx exports-cleanup --include-typesShow All Exports
# Show used exports too
npx exports-cleanup --show-usedAuto-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 --fixSafelist 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.mdExample 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/willzhangflyCompact 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 KBComparison 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 helpCI/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
fiProgrammatic 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:
- Entry points - Main exports used by consumers of your package
- Dynamic imports -
import()expressions aren't always detected - Re-exports -
export * from './module' - Framework conventions - Next.js pages, React components loaded by name
- 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:
- ⭐ Star the repo—it helps others discover this tool
- 📢 Share with your team or on social media
- 🐛 Report bugs or suggest features
- ☕ Buy me a coffee if you'd like to support development
Thank you to everyone who has contributed, shared feedback, or helped spread the word!
License
MIT
Made with ❤️ for cleaner codebases
